Hey guys and welcome back. So in the previous nugget we had discussed the virtual file system
and at the very end of this nugget, or the end of that nugget should I say, what we did
was we added a new disk, we partitioned that disk and we actually formatted it with a particular
file system. Like I say within this nugget right here we're going to be able to use this newly
created partition and begin practicing how we can manually mount and unmount that file system.
So the process that I want to walk you through is going to be related to these commands. Now the
first command I will discuss will be that very first one, the mount command and you can guess
what this one is going to do. What it's going to do is going to mount a file system but it's also
going to show you if you just type the command on its own what file systems are currently mounted.
So it's not just used to make changes i.e. to mount a new file system, this command can also show you
what is already mounted on the system as well as the corresponding mount options. So let me actually
just run this command right now, I'll just say the command mount because on its own it's going to
just simply list the mounted devices. We can see we have a whole bunch of information here. Now let
me just grep for sd, okay in fact let me just grep for sda so I will clear the screen and do sda
just so we get a little smaller output so it's easier to focus in on. Now here is the format
of this output here, we see right here the device in this case here dev sda1 the first partition
disk one or the one at the top sda5. So that is the first piece of the syntax we're going to see,
we're going to see the device and then we're going to see the keywords on okay so it doesn't matter
what we're going to be looking at. The device might change sda1 sda5 but this one here on is going to
remain the same and I just completely obscured that with my bad drawing on okay. Then what we're
going to see is the mount point, this is whereabouts in the virtual file system that this device happens
to be mounted. So if you look at the very top line here and let me just make my pen a little bit
narrower just so I'm not smudging things up so much notice the first value here you see this
it just happens to be that forward slash. Now this might be a little bit obscure to you right now
but it actually just means here this is mounted at this directory here we know that happens to be
the root directory you know if I happen to go onto my command line and I say cd forward slash and I
do an ls this is at the root of the tree so let me just go back and I'll reissue my command and then
we're going to see the keyword type again this is always going to be present so we see it right here
and we also see it right here in the one below and what the type is going to show us it's going to
show us the file system type. Now we did talk about some of the file systems that we can actually see
you mentioned things like ext2 ext3 the top one right here the file system type is ext4 and then
after this what we're going to see within the brackets we can see right here these are known
as the mounts options I happen to mention so in this case here we have these different mount options
what it's saying here is that this is read write meaning that when the system is mounted the disk
is going to be readable and writable i.e. you can read from the disk and you can maybe create new
files on this disk because it is writable if there happens to be an error though what is going to
happen is we're going to try to remount this file system but in read only mode now there are a whole
bunch of different mount options it's going to be or rather should I say it's going to take
far too long to cover all of them and you don't have to know all of them in any great depth but
just understand the basic format of what we're seeing here so if we look at the bottom one here
we see the device we see the keyword on we see the mount point so in this case here it's in the
boot directory and within the boot directory it's bootefi to be exact actually so it's not just
boot it's actually in this directory here if we go into this directory we would be accessing sda1
now the type of file system mounted here is one called vfat we didn't actually mention this one
quite just yet again we'll talk about more file systems in a little bit more detail later on
within this course and then just like we saw before within the brackets we have a whole bunch
of different mount options that really is the type of format so even if I actually remove the grip
filter here and just show you the mount look at the format what you see here just take any old one
here we see the device we see the keywords on we see where it is mounted we see the type and in
the brackets we see the mount options this is the same for every piece of output we can see here if
you scroll on up exact same everywhere so that really is the format you can expect when you just
issue the mount command on its own now here is a very important topic that we really must talk
about here so when we actually issue the mount command as we know it's showing us what happens to
be mounted now here is a question how on earth is the mount command getting this information
does it just know it inherently or is it pulling this information from a particular file well the
answer is it is indeed pulling that information because all of that information we're talking about
is stored in a particular location and this is a location we definitely want to be remembering this
is in the etsy directory and the file is called m tab I like to remember this as the table where
everything is mounted m tab now whenever a file system is mounted this file right here is updated
and whenever a file system likewise is unmounted once again this is updated so when we issue this
mount command and we get this output we're really just pulling information from this file which is
very frequently updated or I really shouldn't say frequently updated which is updated as soon as
something is mounted or unmounted so it really just depends how much things have been unmounted
and mounted now let's actually have a look at this particular file so if we go into the etsy
directory and I happen to do an ls you can actually see we have m tab right here let me just do an ls
dash l and scroll on up now you may notice if you have a keen eye the color here is a little bit
different and we actually have an l at the very end here this means that m tab right here is a sim
link it's actually pointing to this particular file right here so if I happen to just say cat m tab
notice this is very close just a slight formatting difference to the output we get with respect to
the mount command okay again if we happen to look at say for example this one right here we see the
device we see the mount point we see the type and we also see the mount options again formatted a
little bit differently we're not going to see the keyword on the keyword type or the brackets around
the mount point but it really is the same information now if we happen to go into the proc
directory and I do an ls dash l we're also going to see this other sim link mounts that also points
to self mounts you see that so we can cat mounts or in fact let me just give it the full name so it's
a little bit more clear so we cat this file we can see our mount information once again so really
for the purposes of the examination we want to be remembering that within it say m tab we can get
mount information as well as from proc forward slash mounts these two locations and we can also get
mount information directly via the mount command now one thing to just be aware of here because
this might be a little bit of a gotcha when you happen to use the mount command you can actually
specify a particular option it's dash n in fact let me just show you here in the man page I say
man mounts figure down to the n flag we can see here we can use dash n or dash dash no m tab what
this means is that we can actually mount something without actually updating it say m tab so just be
aware of this when we happen to use the mount command it is actually possible if someone explicitly
instructs the mount command to do so to not actually update this particular file so just be aware
what we see within this file that is a possibility for it to be outdated and again this might be
when the etsy is a read-only file system that means you actually cannot write within the etsy
directory therefore you cannot update this particular file if you still want to be able to mount
something even though you can't write within this directory you could use this particular flag so
just be aware that that is a possibility now let's get back to the unmounting of a particular file
now one thing I just want to say directly off the bat because this is a point of confusion very often
is that the temptation absolutely is to think to use this command here now when I say this command
I am kind of talking rubbish because this is not a command there is no unmount command the command
is called you mounts and like I say this can so easily trip people up in the examination you might
be presented with the syntax of unmounts just drill this into your head that this is not a command
we want to be using the you mount command the you mount command will unmount something it's just not
called unmount okay now let's briefly talk about the you mount command now with respect to the you
mount command it is quite easy to use but you do actually have two different ways you can use this
command what you can do is once you have a particular file system mounted you can unmount it by saying
you mount of course and the first option would just be to specify the device you want to unmount
so let's maybe say forward slash dev forward slash sdb one if that happened to be mounted which right
now it is not so we could do this specifying the device or depending on where that device was mounted
let's say it was mounted in a directory called backups within the home ipv0 directory I could
just see you mount and then the directory home ipv0 and then backups the two different ways to
unmount either the device we're trying to unmount or the location of where it is currently mounted
either or will work no problem at all so let's actually see some of this in action then shall we
now how do we actually see what is mounted and where about the mount point is well we actually do have
this very useful command this is one you would want to be remembering this is the lsblk command
this is going to allow it to list our block devices okay now if I happen to use the dash f flag or dash
dash fs this is also going to give us information about the file system so I can press q and what
I can do is I can say lsblk dash f check this out right here this is the output we have so we can see
at the very top we have our first disk sda and we have three different partitions right here on this
we have sda1 the file type or the file system type should I say is vfat we see the unique or rather
the universally unique identifier we can see the size how much is in use as well as very crucially
the mount point like I say if I happen to go into cd boot efi that means transparently we're going
to be accessing the first partition on this disk now we also have sda5 which would be our first
logical partition the file system type is ext4 we can see the uuid right here as well as the
available size how much is in use and notice like I say this is the mount point right here
in fact let me just redraw that with my squinty line this one right here so the roots file system
if we go there we are accessing this partition but notice we have sdb this is the disk I created
and partitioned and happened to format with the as we can see here ext4 file system whereabouts
is this mounted well in fact as we can see here it is not mounted this command right here can give
us that information where something is mounted or not mounted now like I say we could if we want we
could use the mount command and we could grip for sd and try to fish out sdb we can see sda sda1
sda5 but no sdb me myself I happen to find this output a little bit cleaner so now what I want to
do is to actually mount this particular file system so some things we have to actually specify here
so if I just clear the screen and if I go into the mount command I would tell if I could type this
correctly so have a scroll on down and keep on scrolling there's a lot on this page this is an
important flag we want to use the t flag or the dash dash types and then we specify the file system
type so we know from the lsblk command the file system type for this particular device is ext4
we want to be using that information with the t flag so what I will do here and we want to be using
super user privileges by the way is you want to say subtle mounts and then the dash t flag and then
say ext4 that is the file system type now what we want to do is to specify what device do we want
to mount I will say dev and it's going to be sdb1 and now what I want to do is to give it a mount
point whereabouts do I want to mount this particular device so what I'm going to do right now just
by before I issue this command as I will go in to say for example in fact let me just check where
I am I'm in the home directory here home ipv0 I will make a directory called backups since I've been
using that in all of my examples I'll go into this and we can see this is an empty directory so I see
the go back out I will say subtle mounts dash t ext4 the device is dev sdb1 and the location where
I want to mount this is going to be in home ipv0 and then the backups directory that I've just
created if I hit enter now I'm going to have to type in my super user password and it seems
everything is a okay nothing really major has happened but if I do my ls blk command dash f notice
we have some different outputs here we have information relating to sdb1 we can see the size
which is available which is one gig how much has been used nothing has been used but more importantly
whereabouts this is mounted we are in or rather mounted in home ipv0 backups like I say right now
I am currently on sda5 because I'm working within the root directory if I go in to home ipv0 and then
into the backups directory and I happen to create a file called file dot txt I do an ls what I've
actually done is I have ultimately written a file on a different disk on disk 2 partition 1
you see that and if I go back out I'm now no longer on that disk transparent it doesn't affect our
experience as the system administrator and like I say if we happen to use the mount command now
we can see at the very bottom here that indeed mounted we have sdb1 we see the mount points
we see the type and in brackets we see the mount options similarly if we happen to go into xam tab
within this one right here same information this is also being updated so like I say if we want to
unmount this so there is no longer an action we can say sudo you mount in fact let me just show you
this output one more time remember we have two options we can unmount this by giving the name
of the device which would be sdb1 or we can specify the location of where it is mounted
the mount point so I can say sudo you mount dev sdb1 hit enter and notice if I do an lsblk-f
this is suddenly unmounted and again if I happen to just arrow up I will remount this one more time
do an lsblk-f we have mounted it once again alternatively as opposed to specifying the actual
device I can just say sudo you mount and give the mount points to home ipv0 and backups if I
hit enter same type of deal I can do an lsblk suddenly we have unmounted that file system
so one thing you'll notice is that what I did is I specified the name of the device as well as where
I want to mount it what I can also do is just specify the uuid so if I actually just copy this
value right here as opposed to saying dev sdb1 so I just copy this what I will do is I'll mount it
using its uuid so I'll say sudo mounts and now I won't have to specify the file system type using
that dash t flag I can just say dash uppercase u paste in the uuid and then specify whereabouts I
want to mount this so I can say home ipv0 and then once again in the backups directory if I hit
enter that should now be mounted I'll do an lsblk dash f and we can see successfully just by using
the uuid I did not have to specify the file system type or the device the uuid will pull that information
in automatically now one thing I just want to demonstrate I'll just unmount this device no
longer mounted if I happen to create a new directory let's just call this new dir and I cd into here
and what I'll do is I'll create some files in here I'll just say nano my importance file dot
dxd and just say this is some super important and vital information guess I'll save you okay so
within this directory right here we have this very important file now what would happen if I try to
mount a file system into this directory so if I try to mounts I'll say dash t ext4 and I'll mount
sdb1 and the location is going to be in home ipv0 and into this directory which is not empty notice
if I do an lsblk dash f it does mount successfully but watch what happens if I go into this directory
I do an ls where is this important file it's actually gone if I go into my super user and I go
into lost and found nothing in here either so that important file with that really really important
information is no longer accessible to me now really the crucial point I want to show you
is going to lead us into our next video notice we have our file system mounted in this mount
point right here what would happen if I reboot the system so now I've lost my connection my virtual
machine is rebooting just give it a moment okay so I've logged back in I'm now going to check my
mount points once again do an lsblk dash f and look at this you'll notice if you're following along
you should have the exact same issue suddenly just by rebooting the system the changes we made
i.e the mounting of this particular partition right here it is no longer mounted that means
that the changes are not persistent and this is one of the gotchas that you have to be aware of
when just using the mount command on its own so how on earth are we going to solve this problem
so that we can make these changes persistent well that's what we're going to be talking about in the
very next nuggets I hope this has been informative for you and I'd like to thank you for viewing