Now it really doesn't matter whether we're using physical disks or
virtual disk such as the disk files that we have created.
We always have the option to partition the disk or break it up into smaller,
more usable chunks.
Now the tools that we can use to do this include fdisk, a
traditional command that has been available for many years in
many different operating systems, including Linux.
It is interactive and interactive only,
which means it cannot be scripted. Whereas the newer tool, parted, does allow
us to use it interactively if we want, but it also can be used directly at
the command line, and as such, can be scripted.
This is one of the reasons why it's becoming the new favorite.
Once we've created our partitions,
these partitions are stored in the disk label or what is
commonly known as the partition table.
We have two main partition tables that we can use. Again,
starting with the traditional, we've got the msdos partition table.
So this allows for up to a maximum of 4 primary partitions with a maximum
partition size of 2 TB, and that's the real limitation.
We have four primary partitions, but we can also create an extended partition.
So if we only use a maximum of three primary partitions,
we can create an extended partition, and we can create logical
partitions within that extended partition. However,
we are still going to be limited by that 2 TB size. When we look at
the newer GUID or gpt partition table, we allow for a maximum of 128
partitions per disk. Although to be honest,
you're likely to hit other limitations before you get there.
The driver is likely only to support a certain amount of
partitions per disk. But the big benefit is its partition size.
And look at this, an absolutely massive 32 EB.
When we're looking at using the parted command, so this is the
one that can be issued directly at the command line and
scripted, we need to elevate our privileges, put in our correct
device. Here, we're using loop1.
We can create the label and the partition at the same time. So
mklabel will go through and create our partition table, mkpart
will go through and create a partition.
We can also specify the size. Here, we're using a percentage of the disk.
So we're starting at the beginning of the disk and
moving through to a quarter of the disk.
We can obviously, then continue with the next partition,
and we can go through and specify, then 25%, moving
through to 50%, if we wanted to.
The partition table is written to the operating system immediately.
We're able to print it from the parted command. But more
importantly, using the lsblk command,
we're going to be able to see that new device files have been created
for each one of these partitions. Working on our disk dynamically
where that disk is not in use, the operating system is going to know
about the partitions straightaway.
We've kind of seen that with the lsblk command before.
However,
if there are partitions that are already in use from that disk and we
create new and additional partitions, then they won't show in the operating
system straight away. During boot of the system, any hardware is going to
be detected and the partitions on it.
But if we add a new disk file with partitions, we
won't know about those partitions.
So we're going to have to use partprobe to inform our operating system.
It's quite simple to use.
So again,
with elevated privileges, we can go through, in this case,
we're reading in our /dev.sda device.
Now its silence won't display anything; however, we have the option to
run a dry run. Again, the dry run won't do anything, it won't print
anything, and it won't actually do anything.
So it doesn't make much sense running a dry run
without the option ‑s for summary.
This, then prints the partitions that have been found. This
could be a great option to run before we actually probe our
partition table and read it into the operating system to check
it is what we expected it to be.
So ‑ds is our dry run and printing the summary.
Now I don't know about you, but I think it's about time we put this theory into practice and we find ourselves a command line.