So friends, now that we know how to format a file system on our devices using
Ansible,
what we now want to do is to be able to access that data on those file systems.
The key point here to do this is to ensure that we actually mount that file
system.
So with that said, let's talk about some of the key concepts behind file
mounting.
So one of the cool things about Linux is as you happen to traverse across
different directories,
you can actually be transparently moving across different devices on the system WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you can actually be transparently moving across different devices on the system
.
What do I mean when I say that? I'll say for example, we have a disk right here
.
And let's maybe add a second disk right here. I know I know my artistic skills
are not quite so
good, but nevertheless, let's imagine these are two hard disks. Okay. So let's
imagine that we go
into the home directory, you know, just by typing the command cdhome. And let's
say for example,
we're actually accessing data on this disk right here. Now we don't have to
worry about how this
disk is actually partitioned, whatever it may be. Let's just look at this at a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
disk is actually partitioned, whatever it may be. Let's just look at this at a
high level. We're
accessing this particular disk. Now, what if we then type the command, well, I
don't know,
let's go with cd/bin. Now it is completely plausible that we will still be
accessing information on
the same disk depending on how the device is configured. However, what might
actually happen
is well, you just see a change on the command line. You know, you're no longer
in the home directory
or in the bin directory. You could potentially be accessing an entirely WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
different disk completely.
Now the way this is actually made possible, it's all down to how these
partitions happen to be
mounted. Pretty much when you have a partition that has been formatted, you can
specify a particular
mount point where you want that particular file system to be accessible from.
Now realistically,
this is what I want to talk about in this particular video. So one of my
favorite commands in order
to determine whether or not a device happens to be mounted is to use the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to determine whether or not a device happens to be mounted is to use the
command lsblk-f.
So what we actually see here is we see the name of the device as well as the
file system type.
We get information relating to its label as your ID as well as how much of the
file system is
available and how much of it is actually in use. Now more crucially though,
relevant to what we
are talking about is on the very right hand side, we have this option here,
mount points. This tells
us where that particular partition happened to be mounted, i.e. where it
happens to be accessible.
Check this out right here. Take for example, my XFS file system right here, my WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Check this out right here. Take for example, my XFS file system right here, my
main file system.
This happened to be mounted in the root directory. Whereas we also happen to
have a separate partition,
which is again, XFS base, but this is going to be my boot partition and it's
actually on a separate
partition, you see that. Now this is not the only command we can use to see
such information.
We can also type the command mount and that is going to give us all the
information
about these mounted devices. And if I wanted to perhaps be great for a
particular piece of
information, I could say grep nvm e. Check this out right here, we have two WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
information, I could say grep nvm e. Check this out right here, we have two
entries. Here is the
first one and we can see the device is disc number one. This is partition
number two and this is
mounted on the boot directory. We can see the type is XFS and then we also have
some information
about the disk itself. It happens to be read rateable as well as a whole bunch
of other information.
Similarly, we also have this partition right here, n1p1, this is disc1
partition 1,
this is mounted on boot efi and it is formatted with a type vfat. Now this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this is mounted on boot efi and it is formatted with a type vfat. Now this
command doesn't just
show me what type of mounts we have configured. We can also use this command to
actually mount
a particular file system. So let me go to one of my devices right here. Let's
go into the yellow
box right now. If I do an ls blk - if we can see here, we actually have this
new disk which I have
created the n2 disk. It has been formatted with the ext4 file system, but look
at the right hand
side, we do not have a mount point. That means we cannot access any data that WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
side, we do not have a mount point. That means we cannot access any data that
might be potentially
written on this particular partition, nor can we actually write any new data to
it. So let's say
I wanted to actually create a mount point. What I actually want to do is I want
to make sure that I
have an existing directory that says very, very important. And ideally, we
really want that directory
to be empty. Now there is a reason for this. Let me show you why. Let's say for
example, I happen
to create this directory here called, I don't know, let's call this test there.
Okay. Now inside of WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Okay. Now inside of
tester, if I happen to create a file, let's just call this important dot txt
and I just go into
insert mode and say this is some really important file. Okay, so let's imagine
this is some really
important data inside this file. Check this out. If I happen to try to mount a
particular file system,
so I say pseudo mount, I will say dash t to specify the type of the file system
. And in fact,
let me just double check if I don't LSB okay dash f we can see we have an ext4
based file
system for this particular device right here, the n2. If I say pseudo mount WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
system for this particular device right here, the n2. If I say pseudo mount
dash t ext4, and then I
target the actual device which is nvme 0n2. And I specify that I want to mount
it in the test
directory. If I enter, I type in my super user password. And now if I do an LS,
if I go into the
tester directory and list it, what do you notice? Do you see that the important
text file is
suddenly inaccessible? So pretty much when we mount into a directory that WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
suddenly inaccessible? So pretty much when we mount into a directory that
already has a file in it,
the existing contents within that directory are going to be inaccessible. But
if I do an LSBLK
dash, if we do see indeed that this particular file system has been mounted in
this particular
directory structure. Now if I want to unmount that, I can say pseudo you mount
and then specify the
name of the mount point of ISO wish, which is in my case here tester. So I'll
just hit enter. Now
we are unmounted if I list the information once again, now we are no longer
mounted. Now notice if WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
mounted. Now notice if
I try to mount and a directory which is not already created, let's just see a
targeted device nvme 0n2
once again. And let's maybe say I wanted to mount it and in all the directory,
let's call this
test.dirtu, which doesn't actually exist. If I hit enter, it just says here
that the mount
point does not exist. So make sure that it does exist. And ideally, like I say,
if I just create
it and I make sure it's empty, if I now try to remount to an LSBLK dash, if I
have mounted in
this particular directory and if I so wish now what I can do, I can go into t WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this particular directory and if I so wish now what I can do, I can go into t
ester to the vim
file 1.txt, going to insert mode and just say now I can write data to this. So
if I just write
and quit, if I can't file check this out right here, we have successfully
written to the partition
which has been formatted with the ext4 file system because the data is now
accessible via
its mount point right here. So this is the process that we want to be able to
automate using Ansible.
So how about we check out one of the modules that we can use in order to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So how about we check out one of the modules that we can use in order to
perform this particular task.