Disk Partitioning Lab - Part I
Disk Partitioning Lab - Part I
Alexandru Calcatinge
Dec 1, 2018 • 27 min read
In this laboratory, you will exercise using disk devices, partitions, RAID, LVM, swap and cryptsetup.
Contents:
Solution:
For the purpose of this exercise, you will need unpartitioned disk space available on your disk. If you don't, and
you are using your own system, you will need to shrink a partition and the filesystem on it first, and then make
it available to the system. If you don't use partitions on your system, only one large partition for the entire
operating system, the you can use the loop device mechanism with or without the parted program. In the first
exercises we will use the loop mechanism.
We are going to create a file that will be used as a container for a full hard disk partition image, and thus it can
be used as a real partitioned hard disk.
For this, I created a test directory in my home directory, and the output is:
2. Put a file system on the file you just created. For convenience, I created a ext4 file system, but you can
user another one, such as ext3, vfat, xfs or btrfs.
3. Next, mount the file you created. For this, I created a new directory called mount point inside my
backup_test directory, where the image file was created
Laboratory objective 2: Partitioning a disk image file
Commands used: fdisk, umount
Solution:
In the previous exercise, you created an image file that was formatted as a disk drive. Now, the next level of
complication is to divide the container file into multiple partitions, in order to hold a file system or a swap area.
We will reuse the imagefile that we created earlier.
When finished with the above Lab, please make sure to unmount the imagefile using the unmount command.
Note: In Linux Mint, the unmount command did not work. I unmounted the drive using the GUI.
Solution:
In this exercise, you are going to experiment with loop devices, losetup and parted to partition at the command
line. You can use the previous file, or you can create a new one. For the purpose of this exercise, better create a
new one.
7. mount all three filesystems and show that they are available
8. after using the filesystems to your needs, you can unmount it all
Solution:
Now we will exercise partitioning and formatting with a real memory stick or external hard drive. Depending on
what you have available, you can use either of those.
I have a 32GB memory stick that I will use for this exercise.
1. Insert your memory stick into your computer's USB port and use fdisk to see details about it.
In the example above, the memory stick is not recognized by the VM.
You should choose your filesystem based on your requirements and needs. Most used filesystem type is ext4,
supported by most distributions, but there also are XFS or btrfs that are also used by enterprise grade Linux
such as SUSE. For convenience I will use ext4, even though I use XFS and btrfs on my SUSE systems. I will
label the three partitions: "gbcc1", "gbcc2", "gbcc3", thus I will use the -L option for mkfs command:
5. Now lets mount the device partitions. I will use the same directory as in the previous exercise, but I will
create two other directories, for each partition.
6.
Solution:
2. We will now add more swap space to the system by adding a new swap file. You can add more space
with a new partition, if you have one unused.
3. Now format the file as a swap partition. First I will move the swapfile into the /backup_test directory for
more convenience.
4.
You notice that the distribution is warning us that the new swap is insecure, so we will need to take extra
measures and fix this:
6. If you are not using the file, you can then remove it from use and delete it from your system with the
commands:
We did an ls to make sure that the file was removed.