Linux Exercise: Disk Partitions
Disk Partitions
- If you have not done so, stop your virtual machine and use your virtualization interface to add a second hard disk of about 8 GB. Restart your system.
Verify you have an extra hard disk, which is currently not partitioned at all.
- # lsblk
You should see a disk called hdb, sdb, vdb or xvdb, but there should not be any partitions on this disk.
- # fdisk -l /dev/sdb
Again, verify that there are no partitions.
Create two partitions of about 4 GB each. The first partition should have type 82 (Linux swap), while the second partition should have type 83 (Linux).
- # fdisk /dev/sdb
Use the "n" command to create new partitions. Use the "t" command to change the type. Use the "p" command to list your current partition table. Use the "w" command to write the partition table to disk.
Run the lsblk and fdisk -l command again to verify you have now created two partitions.
- # lsblk
- # fdisk -l /dev/sdb
As far as partitioning is concerned, the exercise is now finished. However, in order to do something useful with the partitions, you can format the partitions with, respectively, a swap space and a filesystem, and activate these.
- # free
- # mkswap /dev/sdb1
- # swapon /dev/sdb1
- # free
- # df
- # mkfs -t xfs /dev/sdb2
- # mkdir /mnt/extra
- # mount /dev/sdb2 /mnt/extra
- # df
Deactivate and delete the partitions in anticipation of the next exercise.
- # swapoff /dev/sdb1
- # umount /dev/sdb2
- # fdisk /dev/sdb
Use the "d" command to delete the partitions. Write the (now empty) partition table to disk with "w".
- # lsblk
End of exercise