So yeah, we're going to dive out to the command line of our AlmaLinux 8.5 system,
and we're going to create systemd service units.
So of course,
we're going to need our block device files and our partitions on those files,
but then the service unit is going to do the hard work for us on the reboot.
Let's go through and take a look at this.
And welcome, ladies and gentlemen, boys and girls,
to the AlmaLinux command line,
where you're about to experience the service units doing the
hard work for us on relinking our disk file.
I can create my disk file with fallocate,
and this is going to persist my 1 GB disk file,
along with anything that is written through to the disk file.
What isn't going to persist is linking it through to
a loop device so it can be used.
So we're here then going through creating our loop device,
but on a reboot this wouldn't happen, nor would reading of the partition table.
We can go through and create our partition table using parted.
And we can set up then our label, so we're using an msdos partition table.
We can create our partitions, and we can see something slightly different here.
I'm actually going to create both partitions
together, so we can create our label, our partitions,
so we're creating a primary partition that takes up half of the disk and then
another primary partition. I can just run mkpart again.
So this is where the parted command can be really useful.
I only need to run it once and then run multiple
subcommands within that one command.
So here we're taking up then the rest of the disk
space so we've got our two partitions.
I can see this with the lsblk command.
But parted wrote to the memory and to the partition table at the same time,
so we can see these partitions.
If I go through now and reboot, I haven't created a service unit,
so my disk file is going to be there,
but I'm not going to be able to see any of my disk devices.
As I connect back into my AlmaLinux system,
if I then go through and gain administrative privileges and run the lsblk,
we're back to just having the sda disk.
Whereas if I run ls, I've got my disk 1 file,
but I don't have my loop device or the partition tables showing.
Now I can go through and create, then, the disk device with losetup.
So we're just looking at the commands that we have
to run within our service unit.
So we need to link loop1 to my disk file.
Running lsblk, though, I see my disk file but not its partitions.
So I need to then run partprobe.
Partprobe can read the partition table into the running kernel configuration.
So as I go through then and read the partition table on loop1,
we can see then that I've got the two partitions. So this is my
desired state, if you'd like, but I need to be able to put my system
into that. And that's where systemctl and this wonderful subcommand
called edit. Edit allows us to edit; cat allows us to see the
contents of a service unit.
Now this service unit won't exist at the moment. When we create it, we want
to create a full service unit, rather than just an override file, and
because it doesn't exist, we're going to have to force it to create;
otherwise, it will tell me it doesn't exist.
So we're creating it in etc, systemd, and system, and it's going to be the
losetup service, just a temporary file that is being used at the moment. Now
for ease, I'm just pasting in the unit file.
This is the same unit file that was in the slides, but you
can see the service element of it is running then that same
losetup and partprobe command.
You're able to download this as part of our exercise files.
It should be available to you through your Pluralsight subscription.
When I go through then and save this, we need to allow
systemd to know about the new unit file.
So to double‑check that it has read it into its system, I'm going to use
the systemctl and daemon‑reload, and that's d‑a‑e, reload. And with that
done, I can go through and enable my service.
I only need to enable the service; I don't need to go through
and execute it now, because I've already manually created my
loop devices, so I don't want to cause any problems with it
saying they're already in use.
But enabling the service means that now when I go through and reboot my system,
it is going to go through and automatically create our loop devices on the
system boot. So we should be able to then connect back into our system, run
lsblk, and see both the loop device and the partitions.
So as I go back into the system now, waiting for the system to come up,
it's here. Hello,
AlmaLinux. As I then go through and run lsblk, we can see that from the
get‑go, I've got my block device and my partitions.
So we've really got what we need by creating that service unit.
The service unit is really just going through, scripting the creation of
the loop device, and reading in our partition table. If we want to
remind ourselves of what we wrote into our unit file, we've also got the
subcommand cat. And taking a look then at our losetup.service unit, we
can see where it lives underneath the etc systemd structure and the
elements that we added in. But there you go, another big thumbs‑up for systemd.