And yes,
we need to go out and have a look at our command line so we
can start partitioning our new disk files.
In the demonstration,
we're going to be taking looking at the fdisk and the parted command, as well
as going through and investigating the partprobe command and seeing how we
can inform the operating system of partitions.
Come on, let's find that command line. And here we are, then on the
command line of my Alma Linux 8 system. And I say, I really like it when
you guys can follow through. We can begin by elevating our privileges.
Most commands that I'm going to be running will need root access, so I'm
just being a little bit lazy here, so I don't need to put sudo in front
of every command.
Now one of the wisest things that we can do to begin with is printing out our
block devices to verify what we have on our system so far.
So we've got loop0, our ISO file, then loop1 and loop2.
We can see they're not currently mounted, and they don't have partitions. And
honestly, these are partitioning exercises, so we're going to be going
through and partitioning out both loop1 and loop2.
These are our new disk files. But it's always worthwhile
double‑checking anything, especially when we're working as root. So
we know what we want to do, and we're going to begin using the
fdisk command and partitioning up loop1.
So as we go through /dev/loop1, the first thing is it detects that there is no
partition table, so it creates the default disk label or partition table of DOS
or MS‑DOS. We can see that we've got m for help or our menu. As we print it out,
the new fdisk command does quite a lot.
It can work with GUID partition tables.
It can work with our MS‑DOS partition tables,
but it also incorporates some functionalities from the
sfdisk command that can be used to dump and load text files
that have partition definitions.
So to a degree,
this now is scriptable. We're going to be using it though
directly through its interactive menu, and p allows us to print
the partition table that we just created.
We want to go through and start creating new
partitions, and that's the subcommand, n for new.
As we go through, we can then specify whether or not
to create primary or extended.
The default is p for primary, so we can either hit Enter or
p to continue. As we then go through, we can specify that
we want partition number 1.
It automatically puts the starting sector.
The ending sector is the end of the disk, but we want to add it into
500 MB or thereabouts, so it will adjust to the nearest sector,
+500M, and we've created that partition.
We can run the process against, so new, enter in our partition type,
enter in our partition number. We can enter on the starting
point, so it's going to start at that 500 MB sector, and we can
go through to the end of the disk now.
So again, I'm just entering on the default. P will print our partition
table, and we can see there that we've got our partitions.
They're only in fdisk at the moment, though.
So w will write to the operating system and will write to the disk, but we
can see that we fail to read that partition table into the operating
system, and its advising me to either use partprobe or kpartx. So let's
give these a go. When I use lsblk, we see what we mean by not having read
into the operating system.
We don't see the devices, so partprobe. We're going to put the dry run, so
it won't do anything with the summary, so it will print to the screen, and
then read in the partition table from loop1.
And we can see, then that we've got an MS‑DOS
partition table with two partitions.
We can go ahead, then and read this into our operating system. And
now as we go through and list the block devices,
the operating system now is aware and has created the
associated device files So all of this is now good.
But we're going to see, as we work with a parted command, it both can be
run directly from the command line without having to go into a menu, and
it writes to the operating system directly.
So again, using lsblk, we can verify what we have.
It's always a good idea, especially when we're working with
parted, as it's writing directly to the operating system, that
we know the device name we want to use.
So when we're certain we've got the right device,
we're going to be working with loop2, so /dev/loop2.
We need to create the partition table, so that's mklabel msdos.
Now I could hear Enter at this stage, and it would create the partition
table, and then I can go and create my partitions, but I can also chain
my commands together. So I'm going to add in my first primary
partition, so mkpart primary. No percentage the starting bit at the
beginning of the disk; however,
the beginning of the disk is reserved space, so this will automatically
adjust to the first space that's available, and we can use 50% of the
disk. That's created, then my first partition.
Make sure that we remove the label command because we don't want to create the
partition table again, and we can then adjust, so we start in the middle of the
disk, 50%, and move to 100% at the end of the disk.
It's really an easy command to use, this parted.
Now if we clear the screen and move this back up to the top,
and then we can go through and print out the partition table
on loop2, so that looks good.
Now with that done,
lsblk will actually show me that we've written to the operating system
directly, and we don't need to worry about anything else. So there you go, fdisk, partprobe, and parted, all for your delectation.