-
Hey everybody. I'm Shawn Powers. And in
-
this video, we're continuing our Linux
-
plus certification prep. We're talking
-
about mounting file systems and this is
-
one of those videos where I could go
-
super deep into so many different
-
aspects of mounting file systems but
-
what I'm going to do is I'm going to
-
cover enough that you will understand
-
what you need to know for the exam. And
-
if there are areas that I think might be
-
interesting for you to dive deeper into
-
I'll try to mention it along the way
-
we're currently in objective 1.3 on the
-
Linux plus objectives. I'm calling this
-
1.3.3. This is our third video as we
-
explore this objective and like I said
-
specifically, we're going to look at
-
mounting local and remote file systems
-
or devices and remote devices is
-
important here because we're not talking
-
about remote file systems like over the
-
network. We're going to talk about that
-
over here specifically remote devices
-
are like externally attached like a USB
-
drive that sort of a thing. So we're
-
going to cover the things in here
-
including encryption very briefly, you
-
and that should give us a good feel for
-
what's going on and I don't want to
-
start this video without thanking
-
everybody over here. You might notice
-
it's actually scrolling now because
-
we've had even another person who has
-
decided to be a Patreon supporter of
-
mine. I am so grateful and humbled and it
-
makes me so excited to continue to make
-
more and more content whether it's
-
videos or whatever it is that you might
-
be supporting me for. So anyway, thank you
-
to my Patreon supporters. If that's
-
something you're interested in, link
-
will be down below. But let's get into
-
how we can actually mount file systems
-
on Linux. So just a quick rundown of what
-
I have set up in the folder MNT. I've
-
created just three empty folders or
-
directories called drive one, drive two
-
and drive three. We're going to use those
-
as places to mount our drives or devices.
-
So I have those things created and if we
-
look at LS,
-
BLK. I'm going to do Dash E7 which will
-
filter out all of those Loop devices. It
-
will show us that we have, of course, SDA
-
is our system hard drive. I'm not really
-
going to touch that. That's the, that's
-
what our, our system is installed on,
-
but I have some other devices here too. I
-
have sdb, SDC and sdd. SDR is actually our
-
CD-ROM but I've created a partition on
-
each of these drives. Just one partition
-
that takes up the entire 10 gigabytes,
-
okay. Now if we actually do another
-
command here, Dash f. It will show us what
-
file systems are formatted on there. If
-
there are any so here, you'll see sdb1
-
has an ext4 file system already put on
-
it SDC one has Butter FS BTR FS, the file
-
system is formatted on it and sdd1
-
doesn't have any file system at all. It's
-
just a raw partition. We're going to use
-
that later for encryption. So anyway,
-
these two have things have a file system
-
already installed on it which means we
-
should be able to mount it into our
-
Linux file system. So let's do that for
-
first of all with sdb1, and this is just
-
how we go about doing it manually. So we
-
would say sudo because we need root
-
privilege now I say that it is possible
-
to have something set up so that a user
-
can mount it without root access. That's
-
kind of Beyond where we're going to go
-
today. That's like user mounting options,
-
which has to be set up for individual
-
mounts. We're going to use root access to
-
mount all of these drives onto our
-
system. Because at the end of the day, it
-
requires root access but you can set it
-
up so that a user can initiate the mount
-
anyway we're going to be, we're going to
-
have root access to do this. So sudo
-
Mount and then the device that we want
-
to mount in our case, let's do Dev sdb1
-
and then where we want to mount it.
-
MNT will say drive one. Now, I could add
-
another flag before I do this. I could
-
say Dash t for what type is it and we
-
know that it's ext4, but that is almost
-
always Auto detected. We very rarely have
-
to specify what type of file system it
-
is. And in fact, if it doesn't work if it
-
doesn't Auto detect the file system,
-
chances are there's something wrong and
-
it's not going to mount anyway. So I'm
-
not going to put that on there but if
-
you see somebody specify Dash T and then
-
the file system type. That's why it's a
-
way to tell Mount what kind of file
-
system to expect,
-
but you can see it usually Auto detects
-
it, just fine, if we do it, if we do a DF
-
minus H. We're going to see that now we
-
have this device mounted on MNT drive
-
one, and it's able to be used now on our
-
system. It's part of our file system now
-
mounting things manually is great but
-
it's really not that practical,
-
especially if it's hard drives that you
-
want to have automatically mount when
-
the system boots up. And so generally,
-
what we do is create entries in the ETC
-
FS tab file, which file system tab. So
-
that's what I'm going to show you how to
-
do right now is how you would make
-
amount permanent on the system. So let's
-
unmount this drive and to do that, sudo U
-
Mount it's not on. It's not unmount. It's
-
U mount for unmount, which is a little
-
confusing sometimes but you mount and
-
then MNT drive one . So then it will
-
unmount, if we look it's no longer
-
mounted on our system. So let's look at
-
Etc FS tab, here is where we can make an
-
entry and there is a little cheat sheet
-
up top here. That will explain how you
-
can specify what you wanted to mount
-
when the system starts up. So the first
-
field is what file system and that can
-
be specified in a number of ways. In fact,
-
it's specified a couple ways right here.
-
You can see uuid equals and then this
-
euid that can be how we specify it, we
-
could just use a device like Dev sda2, we
-
could use a label that we have formatted
-
on the partition. So there's a lot of
-
different things that we can specify as
-
what file system is that we want so in
-
this case. Let's actually, I just did the
-
device on the command line. So let's get
-
out of here really quickly and if we do
-
sudo
-
blkid, and I'm going to get rid of all
-
the loopback devices. This will show us
-
all the partitions on our system and the
-
one that we were just looking at is Dev
-
sdb1. And so this has a uuid of this
-
right here. Now, point out right here
-
since we're since we're looking at this
-
block ID information. This is the uuid,
-
this is the unique Universal unique
-
identifier for the file system that is
-
installed. However, there's also the
-
partition uuid which is pointing to the
-
actual partition on the hard drive that
-
the file system is written to. So if you
-
and that if that seems confusing
-
hopefully this will help if we look down
-
here at Dev sdd1, you may remember this
-
is a a partition that does not have a
-
file system put on it yet. And this still
-
has a part uu idea partition uuid but it
-
does not have a uuid because there's no
-
file system formatted on this partition
-
yet, okay. Now the cool thing is we can
-
actually specify in file
-
Etc fstab using either uuid or part uuid.
-
Generally, you'll see this done either by
-
the device which in our case is going to
-
be Dev sdb 1 or the uuid. So let's, let's
-
do this uuid. This is going to be that
-
device copy and now if we do sudo VI Etc
-
FS Tab and now I'm going to paste that.
-
So that's the file system. This is the
-
device this is that first field and then
-
where we want it to Mount. That's just
-
going to be MNT drive 1. The next field
-
is the type. So here we do actually have
-
to put the file type which is or the
-
file system type which is ext4 and then
-
the next one is what options. I'm just
-
going to say defaults. We don't need any
-
specific options in there and then the
-
next two are a little bit confusing dump
-
is very rarely used at all anymore. So
-
we're going to put a zero here. What dump
-
is talking about is you could do like a
-
file system backup, it would like dump
-
the contents of a partition or a mounted
-
device. It's just not done anymore it was
-
dump FS. It's just not done anymore. So
-
zero means like no, we're not going to do
-
that and then pass talks about how often
-
you want to do a file system check.
-
We're going to look at file system check
-
in probably the next video, but there's
-
three options. Let's see there's zero one
-
or two zero means don't do any file
-
system checks one means I want you to do
-
file system checks and this is the root
-
partition. Well this is not the root
-
partition and so two would be I want you
-
to do file system checks, but this is not
-
a root partition all right. So I guess,
-
this would be the way to go either a 2
-
or a zero. I'm just going to leave it at
-
zero then we save this,
-
and now when the system boots up, it will
-
automatically mount that onto mount
-
Drive one. But if you look right now, it's
-
not mounted. So we can say sudo Mount
-
Dash a, which will re-read that FS tab
-
file and mount all the things that are
-
in there. So if we do that and now we
-
look now it's mounted and it will Mount
-
every time the system is rebooted. Now,
-
the Linux plus objective specifically
-
says external devices, which is a little
-
bit of a weird thing. It's not something
-
we do very often and this makes me think
-
of a USB drive. Now if it's like a USB
-
stick most distributions. Especially if
-
they have a GUI installed will just
-
automatically mount it, when you put it
-
in and then you take it out. It's, you
-
know, unmounted however let's say you
-
have a like a really large
-
USB drive it's like an external, you know,
-
USB like I don't know 20 terabytes or
-
something and you want to have it
-
treated like a regular hard drive on
-
your system, but it connects via USB. Well,
-
it is possible to actually have those
-
treated it like a regular drive. So
-
that's what we're going to do. We're
-
going to set up a USB drive so that it
-
doesn't automatically Mount and unmount,
-
when we plug it into the USB connector
-
but treat it more like an internal hard
-
drive on our system, and here's the thing
-
normally when you plug in a USB drive.
-
And I have one just out of camera here.
-
It will do what it just did here. It will
-
automatically Mount that USB stick, and
-
if we look down here DF minus H. It
-
mounts it somewhere like in the media
-
folder, and this is the auto mounter that
-
looks for USB drives and it will do that
-
automatically, but let's say like, like I
-
just discussed that we want this to be
-
treated like a regular hard drive. Well,
-
let's do let's unmount it first. So
-
umount media s Powers USB stick. Now,
-
let's do a sudo BLK ID corrupt Dash V
-
Loop. And let's see if we can find that
-
device, yes. It's right here so Dev SD E1
-
is that partition. I unmounted it but
-
it's still inserted into the system and
-
so we can create an entry in ETC FS tab
-
for this and now remember I said we can
-
specify these based on a lot of things
-
like a device, the problem is with a USB
-
device specifically, let's say we plugged
-
in another USB stick before this one and
-
so the other one was sde and then this
-
one was SD F so using a device name
-
particularly with something. That might
-
change is not a great idea. So in this
-
case, we would either want to use the
-
uuid which you know we have uuid or you
-
could use a label and for something like
-
this. I would probably use a label. My
-
rationale here is that you can actually
-
label different USB disks the same thing.
-
And so, if you always want your USB drive
-
to mount in the same spot. You could just
-
label them the same whichever one's
-
plugged in is going to be there, but
-
nonetheless label is one more way we can
-
specify it. Let's take this label USB
-
underscore stick,
-
Etc fstab.
-
And the same thing as before we're just
-
going to make another entry. This time
-
though we're going to say label equals
-
USB underscore stick.
-
And then I want this one mounted in MNT
-
Drive 2, and this is going to be well
-
what was the file system on there. Let's
-
look. I'm going to go back and look it
-
looks like a v-fat. So this is a, it's a
-
Dos based thing basically. So the type is
-
v-fat it's right here. So we'll go back
-
in and V fat is our type defaults. I'm
-
going to say 0 0. Again.
-
save this and now again it's not mounted
-
because we you mounted it. However, if we
-
were to say sudo Mount Dash a now all of
-
a sudden that drive is going to be
-
mounted in Mount Drive Two. And now when
-
we reboot the system as long as that USB
-
drive is in even. If it's not recognized
-
in the same order. It should mount on
-
that location instead of us having to
-
like put it in and have it Auto Mount
-
detected by the GUI operating system,
-
that sort of thing. It should be treated
-
just like a regular hard drive on the
-
system and mount app boot, but you want
-
to know a little secret system D
-
actually does all of the mounting the
-
ETC fstab file used to be where
-
everything was read from and mounted
-
right from there but not anymore now
-
systemd looks at our FS tab file and
-
creates on the Fly individual
-
system. D Mount files and that is what
-
it uses to mount them. Let me show you if
-
we go to our system here and we go into
-
run system d e generator, and we look at
-
all the files in here. We're going to see
-
a couple specifically this is the the
-
one that is generated on boot. So the
-
dash here is just referring to the root
-
partition, but here is the deal. Let's
-
look at it. This is auto generated by
-
reading the fstab file, and it creates
-
this file on the Fly, and this is
-
actually how it mounts on the system now
-
we can create our own dot Mount files in
-
Mount devices into directories using
-
this method. However, this is not what is
-
generally recommended. It's still
-
recommended to use the ETC fstab file to
-
spell out all of the mounts that you
-
want. Even though they're converted to
-
system D Mount files. However, it is
-
possible to use a systemdmount file. If
-
you have a reason to do that and you
-
want to specify in a file like this
-
but to do that I'm not going to dive too
-
deep into system D, but if you have
-
custom things that you create for
-
systemd. They're going to be put into
-
Etc system D system. This is where the
-
user generated files are put and there's
-
probably already a bunch of stuff in
-
here, but we're going to create a simple
-
Mount file and we're going to put it in
-
here. So I'm going to do sudo VI and this
-
is it has to be in a very specific
-
format. Okay, it has to represent
-
by name where the end result is going to
-
be. So we have to do something like v i m
-
n t Dash Drive 3 dot Mount, because if
-
you remember, I created that directory in
-
Mount Drive 3 and so we have to name the
-
mount file, exactly this or it won't work
-
so we're creating this file. I'm just
-
going to make it very very simple
-
Mount Drive three, and then a little
-
Mount section what equals and then this
-
is the device that we actually want to
-
use. So this is device the device that
-
we're going to mount. So let's get the
-
uuid from a device pseudo okay ID crop
-
Dash V looped. So the loops don't show up
-
and the device that I want to mount in
-
here is this one Dev SDC one, and it has
-
this uuid for the file system. So I'm
-
going to copy this,
-
go back into here and this is a little
-
bit goofy. This is kind of how you
-
specify it Dev disc by uuid. And then
-
actual uuid> So I'm going to get rid of
-
this stuff
-
so we specify that is what device and
-
then where is the next option here and
-
where is going to be Mount Drive three
-
and it has to be here because remember,
-
that's what we named the file type
-
equals
-
btrfs which is what it said it was
-
options equal defaults, and I don't know
-
if this part is required but generally
-
multi user dot Target and that just
-
means that it will call this when we
-
start multi-user mode on boot, all right.
-
So I'll save that,
-
and now we have to do sudo system CTL
-
Daemon reload so that it sees that mount
-
file that we've created. This is just
-
more systemd stuff and then we treat it
-
just like we would a service. So we can
-
say pseudo system CTL start MNT Drive 3
-
mount,
-
and now if we do DF minus H. It's mounted
-
it right here. Now this will not
-
automatically start on boot because just
-
like a systemd service, we would have to
-
do sudo system CTL enable
-
Mount Drive three dot mount.
-
So we do that and now it will actually
-
Mount that on boot. Even though, it's not
-
in our FS tab file. So again it's
-
possible to do that and if you put it in
-
ETC systemd system and name it properly
-
it will mount on system boot, but it's
-
still not generally the way that we go
-
about doing it normally. We still use the
-
ETC fstab file because it's one place
-
that we can put all of our file systems.
-
And that's will be converted.
-
Automatically, so we don't have to worry
-
about the system D side of it and then,
-
you only have one place to remember to
-
store all of your system mounts that
-
said the one last thing. We have to cover
-
is an encrypted file system using Luke's
-
so back here on Ubuntu. I'm going to
-
create one more directory. I'm going to
-
make directory Mount secret. We're going
-
to use this directory for an encrypted
-
file system. Now if you remember lsblk, we
-
have these devices down here. So the one
-
that we haven't messed with at all is
-
sdd1 this is a partition. There's is no
-
file system on it at all. So we're going
-
to create an encrypted partition and to
-
do that we use the Crypt setup tool. So
-
Crypt actually I'm going to do sudo
-
Crypt setup Luke's format Dev
-
sdd1. So it's going to overwrite it
-
completely because it's creating uh this
-
encrypted partition. So I'm going to it
-
says are you sure. Type yes in capital
-
letters. So yes in capital letters. Now, I
-
have to enter a passphrase okay. This is
-
how it's going to decrypt if you don't
-
remember this passphrase. Your data is
-
lost right. There's, there's not a
-
recovery function if you can't remember
-
your passphrase. So it's generally
-
something long. Mine is not going to be
-
really long and now it is an encrypted
-
partition, but it's not open in order to
-
access the partition itself. So that we
-
can write data to it. We have to decrypt
-
it and open it in a decrypted state. So
-
in order to do that, we use the same tool
-
sudo Crypt setup but we say open and
-
then what the device is so Dev sdd1 and
-
then what we want it to be named in its
-
unencrypted state. Okay, does that make
-
sense? Hopefully it does. Hopefully, it
-
does. We're going to call it secret disc.
-
I have to enter the passphrase okay and
-
now I think it shows up with a LS block
-
sort of I mean it is called secret disc
-
but it's going to live in Dev mapper,
-
okay. In Dev mapper, secret disc is that
-
currently decrypted file system. So what
-
we would do is write a file system on
-
there because right now. It's just a
-
an encrypted partition that's currently
-
open and decrypted, and that's how we
-
access it. So we're just going to do sudo
-
mkfs.ext4. I'm just going to make an ext4
-
file system on it Dev mapper secret disk,
-
okay it's all done. And now let's
-
mount it. So we're gonna say sudo Mount
-
Dev mapper secret disc on Mount Secret,
-
and now sure enough, it is there and we
-
should be able to access it so let's
-
go into I'm just going to become root
-
Out secret, okay. There's lost in file
-
touch file.txt, all right. Sure, enough.
-
It's there, so let's get out of there and
-
now to unmount it. We would do the same
-
thing backwards, right. We would just say
-
you mount mount secret okay. It's no
-
longer mounted and then, it's still
-
available in an unencrypted form though.
-
So what we would have to do is say Crypt
-
setup close Dev sdd one, just actually
-
the name of it which for us is secret
-
disc,
-
okay. And now we can no longer access it
-
without retyping in our password. I know
-
that was a lot. There's one more thing
-
that I, it isn't really specified but I
-
do want to show you. You can actually
-
automatically have it mount on boot and
-
it will prompt you during boot up for
-
the passphrase. In order to continue and
-
actually Mount the file system on boot.
-
There's also ways. You can create keys,
-
and have them stored in special places
-
like on a USB drive that you plug in but
-
let's quickly set up an automatic that
-
an automatic Mount that will prompt us
-
on boot to unencrypt the drive and then
-
we'll be done. So let's do the okay ID. So
-
this is our device. Let's get the uuid of
-
this device this is our crypto Lux
-
device itself. So I'm going to copy the
-
uuid and what we need to do is when the
-
system boots up, it will look in a file
-
called
-
Etc Crypt tab. So we have to create this
-
file and in here we actually specify,
-
what it is we want it to decrypt. And so
-
the first field is what we want it to be
-
called. In our case, I want it to be
-
called secret drive.
-
And then the next field is going to be
-
that uuid of the actual Luke's partition
-
itself and then the Third Field is just,
-
I'm just going to put a dash. This is
-
where we could tell it like to have a
-
key that we would automatically decrypt
-
it, but if we just put a dash here. It's
-
going to prompt us for that passphrase
-
as it tries to create secret Drive, okay.
-
So that it should be all we need to do
-
and then if we look in FS tab,
-
then we can assume that we've entered
-
our passphrase Dev mapper.
-
Secret Drive is going to be in Mount
-
secret and this is just ext4
-
defaults, zero zero that should be all. It
-
takes to get it to automatically Mount
-
after it prompts us for the passphrase
-
on boot. So let's reboot the system and
-
see what happens,
-
okay. It's asking us right here for the
-
passphrase. So let's put that in
-
all right we've booted up. Let's have a
-
quick look
-
TF minus H and we have drive one is
-
mounted drive, two is mounted drive three
-
is mounted and Drive Mount secret is
-
mounted so all of the things that we set
-
up survived the reboot including that
-
one that we did with system D and
-
automatically mounting this by prompting
-
us for that passphrase on boot. I know
-
that was a lot to cover and I encourage
-
you to look deeper into things like Auto
-
Mount because that's really fun, but it's
-
not part of the Linux plus objectives.
-
But anyway hopefully, all this made sense
-
maybe you have to go back through and
-
watch it I encourage you to try it on
-
your own system to make sure that you
-
can replicate what's going on as we went
-
along doing it and this is another
-
example of how important it is to learn
-
everything do what you love, and most
-
importantly be kind, I know this is a
-
long one. But I'll see in the next video.