Free Domain Sign up for PayPal and start accepting credit card payments instantly.

Thursday, October 21, 2010

Swap Partitions & Files

Features:
1. Extra, virtual RAM for the OS


Steps:
1. Identify current swap space
a. swapon -s - enumerates partitions and/or files, which constitute swap storage

b. free -m

2. Select target drive and provision swap partition
a. fdisk /dev/sdb
b. n
c. 2
d. 500
e. +512 (cylinder 562) - 63 cylinders are required for 512MB
f. t - change type
g. 82 - Linux Swap/Solaris
h. w - committ changes to disk

3. Create the swap file system on the raw partition: /dev/sdb2
a. mkswap /dev/sdb2

4. Enable swapping - publish the swap space to the kernel
a. swapon /dev/sdb2 - this enables swapping on /dev/sdb2

5. update /etc/fstab
a. /dev/sdb2 swap swap defaults 0 0

swapoff /dev/sdb2 - disables swapping on /dev/sdb2

Task:
1. Improve system performance by distributing swapping to /dev/sdb2
a. swapon /dev/sdb2
b. swapoff /dev/sda6
c. disable /dev/sda6 via /etc/fstab

Basic Provisioning of Partitions and File Systems

Features:
1. Ability to provision extra storage on-the-fly

Steps:
1. Identify available storage
a. 'fdisk -l' - returns connected storage

2. Create partitions on desired hard drive:
a. 'fdisk /dev/sdb' - interacts with /dev/sdb drive
b. 'n' - to add a new partition
c. 'p' - primary
d. '1' - start cylinder
e. '+4096M' - to indicate 4 Gigabytes
f. 'w' - to write the changes to the disk

Note: use 'partprobe partition (/dev/sdb1)' to force a write to a hard drive's partition table on a running system

Note: 'fdisk' creates raw partitions

3. Overlay (format) the raw partition with a file system
a. mke2fs -j /dev/sdb1 - this will write inodes to partition

4. Mount the file system in the Linux file system hierarchy:
a. mkdir /home1 && mount /dev/sdb1 /home1
b. mount OR df -h - either will reveal that /dev/sdb1 is mounted

Note: lost+found directory is created for each distinct file system

5. Configure '/home1' to auto-mount when the system boots
a. nano /etc/fstab and copy and modify the '/home' entry

Quotas

Features:
1. Limits disk usage (blocks or inodes)
2. Tied to file systems (set on a per file system basis)
3. Can be configured for users and groups

Steps to enable quota support:
1. Enable quota support per file system in: /etc/fstab
a. defaults,usrquota,grpquota
2. Remount the file system(s)
a. mount -o remount /
b. use 'mount' to confirm that 'usrquota,grpquota' support are enabled
3. Create quota database files and generate disk usage table
a. quotacheck -mcug / - this creates /aquota.user & /aquota.group
b. quotacheck -mavug
4. Assign quota policies
a. edquota username - set blocks/inodes soft_limits hard_limit
edquota student1 - sets quotas for user 'student1'
export EDITOR=nano - to have edquota default to 'nano' editor
5. Check quotas
a. quota username
quota student1

Note: place 'quotacheck -avug' in /etc/cron.*(hourly,daily)

6. Report on usage
a. repquota -a - this reports on usage

Note: The blocks are measured in 1K increments. i.e. 20000 blocks is roughly 20MB

Symlinks

Features:
1. Provides shortcuts to files (including directories)
2. Provides hard links to inode (file system) locations

Soft Links:
1. ln -s source_file target
a. ln -s ./regextest.pl lastscript.pl

Note: Soft links may span multiple file systems/hard drives
Note: Symlink count is NOT increased when using soft links

2. ln -s /home/Linuxtutorial/testRH5/regextest.pl . - this will symlink (soft) to the /boot file system

Note: With soft links, if you change the name or location of the source file, you will break ALL of the symlinks (soft)


Hard Links:
Features:
1. The ability to reference the same inode/hard drive location from multiple places within the same file system
a. ln source target
ln regextest.pl ./testhardregextest.pl - creates a hard link