To enumerate a list of connected hard disks and partitions:
fdisk -l
Linux hard disks typically begins with hd[a-z] or sd[a-z]. hd stands for IDE drives, while SD represents SCSI or SATA drives. Partitions begin with numeric values after sd/hd, like /dev/sda1, /dev/sda2, /dev/hda1, /dev/hda2.
Hard disks must be formatted to be used. There are three steps to provision storage:
1) Create partitions
2) Create file systems
3) Mount file systems at a location in the tree (beneath '/').
Gnome Partition Editor is a GUI interface that does what fdisk does. The Gnome Partition Editor is called GParted.
We will now use fdisk to create 3 partitions, create 3 file systems, and then mount them automatically. To create the file systems, we need to use mk2fs to overlay the file system over the partitions.
To remove partitions using fdisk, use:
fdisk /dev/sdb
d 1
w
fdisk /dev/sdb will bring up an interactive prompt. d will delete the specified partition, and w will write changes.
To create a partition:
fdisk /dev/sdb
n
p
1
[enter]
[enter]
w
Enter the interactive prompt, create a new partition, choose primary, create partition 1, and start from first and last cylinder.
Now you would have an empty partition. We will now make the file system a journaling e2fs (e3fs). Use the following syntax:
mke2fs -j /dev/sdb1
To mount the file system, use:
mount /dev/sdb1 /var2
To automatically mount during boot, use:
nano /etc/fstab
Simply copy any existing entries and rename accordingly.
We will now focus on creating swap space for kernel and user applications. There are two forms of swap: Dedicated Partition, Dedicated File. It can be created within Primary or Extended partitions. Paging too much, however, will negatively affect system performance.
To create a swap partition:
1) Identify possible storage
fdisk -l
parted print
df -h
mount
2) Calculate desired swap space based on physical RAM.
Swap Space =~ 1.5 * RAM
3) Create Partitions
4) Overlay partition with swap file system
mkswap /dev/sdb1
5) Turn on swapping
swapon /dev/sdb1
To see the current swap configuration:
swapon -s
To enable swapping on all partitions:
swapon -a
To disable swapping:
swapoff /dev/sdb1
To create a swap FILE on an existing partition, we first write zeroes to a file using the zero device:
dd if=/dev/zero of=/home/swapfile bs=1024 count=524288
Note that 524288 is 512*1024. This will create a 512MB file. Next, we use mkswap to make the file a swap file:
mkswap /home/swapfile
We then turn on the swap file:
swapon /home/swapfile
We then make sure that the file cannot be modified by anyone else except root:
chmod 0600 /home/swapfile
Update the fstab with new swap locations:
/home/swapfile swap swap default 0 0
No comments :
Post a Comment