Lab Objective:
Learn how to design a disk partitioning scheme.
Lab Purpose:
In this lab, you will learn about disk partitioning, partition types, and how to set up partitioning using tools such as fdisk.
WARNING: In this lab, you will begin partitioning your main disk with fdisk. As long as you do not use the write command, these changes will stay in memory only, and your data will be safe. As an extra precaution, you may wish to run fdisk on a secondary drive or create another VM just for this purpose.
Lab Tool:
Ubuntu 18.04 (or another distro of your choice).
Lab Topology:
A single Linux machine, or virtual machine.
Lab Walkthrough:
Task 1:
Open the Terminal and run sudo fdisk /dev/sda – substitute your hard disk for /dev/sda if sda is not the right device; you can check with the command ls /dev/sd*.
Enter p to see the current partition layout. If you selected your main disk, you should see at least one partition, along with its size, type, and whether it is a boot partition. For example, in the output below:
/dev/sda1 * 2048 41940991 41938944 20G 83 Linux
The disk contains a single 20GB partition, of type 83 – a Linux filesystem (enter l to list all of the types).
Task 2:
Now, let’s delete (again, from memory only) any pre-existing partitions. Type d and answer the prompts until none remain.
Then:
Enter n to add a new partition. This should be a primary partition, number 1, in the first sector, press Enter key, and enter +100M in size. It would be mounted at /boot.
Repeat this for the swap partition. Make it 4G in size or double the system RAM. Enter t to change this partition type to 82 (Linux swap). Swap space is “backup RAM,” which uses disk as secondary memory if your system runs out of RAM.
Repeat this for the /var filesystem. Make it 4G in size, or whatever feels right to you based on the disk size.
Create an extended partition that fills up the rest of the disk. Within this extended partition, you will create partitions for /home and /.
Create a partition for the /home filesystem. Make it 4G in size, or whatever feels right to you based on the disk size.
Repeat this for the / filesystem. It will fill up the rest of the disk.
Enter a to toggle the bootable flag on partition 1.
Enter p again to see your results.
IMPORTANT: Enter q to quit without writing the partition table.
In most situations, you probably wouldn’t need this many partitions; if you did, you would use Logical Volume Manager (LVM) instead. LVM provides a more flexible way to manage logical volumes than partitions. In LVM, you would create a volume group consisting of one or more physical volumes (disks), and then create logical volumes on top of that in lieu of partitions.
Notes:
Some systems contain an EFI System Partition. This would show up in fdisk as a GPT partition and, in general, should not be deleted, especially if you have a dual-booting machine.