00:00:00 - Welcome to nugget 104.3, where we learn about mounting
00:00:04 - and unmounting file systems. Now, we need to learn a few different
00:00:07 - things. We need to learn how to manually mount and unmount
00:00:10 - file systems. We need to learn how to do that automatically
00:00:14 - on bootup, using the /etc/fstab file. Then we need to learn
00:00:19 - how to do user mountable file systems. So a regular user can
00:00:22 - mount and unmount things. And then, this is actually not one of
00:00:26 - the exam requirements. But I just want to briefly explain what
00:00:29 - automount is, and why it might throw you for a loop if you're trying to
00:00:32 - do some of these things up here. Alright, so let's get to the
00:00:35 - command line, so I can show you how to mount and unmount.
00:00:39 - Okay, first things first. I'm going to show you how to use two commands,
00:00:43 - mount and umount, alright. Now if you remember from the past
00:00:46 - nuggets that we've done on working with hard drives. We have a
00:00:49 - formatted partition. It's right here. /dev/sdb1 okay.
00:00:55 - So we know that this is a partition, and if you don't know just
00:00:59 - trust me because this is a formatted partition, it has an ext3
00:01:03 - file system on it, which we learned how to make in previous
00:01:06 - nuggets. And now we're going to mount that. What you need to mount
00:01:10 - something, basically is an empty folder. So I've created inside,
00:01:16 - this folder mnt, I've created a folder called hard_drive, alright.
00:01:20 - Now it's owned by root, but it's readable and executable
00:01:25 - by everybody.
00:01:26 - So it's -- again, it's called hard_drive inside the mnt folder.
00:01:30 - So the way that you mount something, you type mount-t
00:01:35 - and the type of file system you're mounting, which in our
00:01:38 - case is ext3, not two,
00:01:42 - and then you say what device, for us it's /dev/sdb1,
00:01:47 - and then where you want it to mount it; /mnt/hard_drive/.
00:01:50 - So that's the command, you press enter,
00:01:55 - and you'll learn that you can only do that as root. Now there
00:01:58 - are some exceptions we're going to learn later, but in the
00:02:01 - meantime you need to know that in order to mount devices you
00:02:05 - need to be root. So again, we'll do S-U-D-O, for sudo.
00:02:10 - And now if you look in -- now, I guess I should have shown you that it was
00:02:13 - an empty directory, but I'll show you that in a second. Go to /mnt/hard_drive
00:02:18 - and see inside here,
00:02:22 - see, a bunch of stuff here. A lost and found folder, folder one, file one,
00:02:26 - file two, file three. So these are things inside this hard_drive folder now.
00:02:30 - So it acts just like a folder inside our drive, alright. If you want
00:02:35 - to see what devices are mounted, you can actually type the mount
00:02:39 - command with no flags at all. And it will show you the things that
00:02:42 - are mounted. Now, it shows you a whole bunch of things. Like the
00:02:45 - the proc file system, which we learnt early on, really isn't --
00:02:47 - it's like a virtual file system talking about the
00:02:51 - different states of the system. But, if you look down here, this
00:02:54 - is the last one, this is what we just did, we mounted /dev/sdb1
00:02:58 - on the /mnt/hard_drive folder, okay. So that's right in
00:03:03 - there. Now what if we want to unmount it. Now watch really, really
00:03:06 - close. First we're going to be root, so sudo. It's not --
00:03:10 - the command is not unmount its umount.
00:03:13 - And then you say either the folder that it's in,
00:03:19 - or the device.
00:03:25 - Either one of those.
00:03:27 - Oh, and -- hah, I'm glad I made this mistake. It says it's already in
00:03:31 - use, it's busy. Well, why is it busy? Well, because we're in that folder
00:03:35 - right now. So let's type cd, to get back to our home directory.
00:03:40 - Type that same command, and it's no longer busy, meaning, we're
00:03:43 - no longer in there. And now if we -- ls /mnt/hard_drive/.
00:03:49 - Remember, this is just a folder. We've unmounted it, so now
00:03:53 - it's just an empty folder, alright.
00:03:55 - So again, the folder has to be empty if you're to mount a
00:03:57 - hard drive or mount a block device on there. But right now it's just
00:04:01 - an empty folder. But if we were to mount it again,
00:04:05 - back to here, mount the device again,
00:04:10 - and we'll see, ls shows files in there, because it's mounted, alright.
00:04:15 - And again, sudo umount, will unmount it.
00:04:18 - So that's how you use mount and unmount.
00:04:24 - There are some things that you can do so that things mount automatically,
00:04:27 - because it's not like we have to do this every time the hard
00:04:30 - drive mounts. We don't have to mount, like for example, if you look
00:04:33 - in the mount, you know we don't have to mount the root partition
00:04:39 - every single time the computer boots up, it does it automatically.
00:04:42 - And what we're going to learn next is how to automatically mount
00:04:45 - things on boot.
00:04:47 - To do that, we're going to edit the file, sudo as root,
00:04:52 - vi, in the /etc/ folder, or /etc/ folder, as it's
00:04:56 - sometimes called, /fstab
00:05:01 - And this is what we're going to see. Now, just like with a lot
00:05:03 - of other configuration files, if it starts with this hash mark,
00:05:06 - or this number sign, it's a comment. So things here aren't parsed
00:05:10 - by the mounting programmer, by the kernel as it mounts different
00:05:13 - file systems. But what does happen, on a line with actual commands,
00:05:18 - there's basically six different fields that are read through. The first
00:05:23 - field is what file system we want to mount, and this can be referenced
00:05:27 - in three different ways. Now, here you'll see it's being referenced
00:05:31 - as a Universal Unique Identifier. And it's talking
00:05:35 - about the root partition of the drive. Now again, this is really
00:05:39 - /dev/sda1. However, every device has this Universal
00:05:45 - Unique Identifier and it's being referenced that way. So if
00:05:48 - you put in a new hard drive in its spot, it's not going to
00:05:51 - mount it on the root partition, because it's going to have a
00:05:53 - different UUID. So the second way you can do that is
00:05:57 - with a label. Now, you can label a partition, and then you can just
00:06:01 - reference this first one as label= and, let's say you named
00:06:05 - it bob, whatever you name the partition, you can label it
00:06:09 - something, and then reference the file system as whatever you
00:06:14 - name it if this said label. And the third way, which is what we're
00:06:17 - actually going to do, is like we see down here, the actual block
00:06:21 - device, /dev/scd1, or in our case, /dev/sdb1.
00:06:29 - The second field is where we want it to be mounted.
00:06:33 - The third field is what type of file system that is.
00:06:37 - The fourth one is options, now if there's more than one option, it's separated
00:06:41 - by commas, as you can see here. These different options are separated
00:06:44 - by commas. Now the last two are a little more confusing, dump
00:06:49 - is a booming thing, it's either a zero or a one. If it's a one it will save
00:06:54 - files automatically when the system is shut down. If it's a
00:06:58 - zero it won't. And then pass is talking about the order in
00:07:03 - which file systems are scanned, okay. So for example, usually
00:07:08 - the root file system, right here, will have a scan number
00:07:12 - of one. Other file systems that are local on the computer, like
00:07:17 - if you have, we learned about having like a separate user partition
00:07:21 - sometimes. That would have a number of two, and then removable
00:07:26 - devices, like CD roms and floppies, they generally all have a
00:07:30 - zero in for the pass number, okay. So that's just what
00:07:35 - that field means. So again, it's just important to remember,
00:07:38 - the root partition generally has a one, other local file systems
00:07:42 - mounting points usually have a two, and then removable media,
00:07:46 - removal file systems, generally have a zero for the pass, which
00:07:51 - is for the order in which the're scanned, alright. So basically, anything
00:07:55 - in here is going to be auto mounted. Unless it's specifically
00:07:59 - flagged noauto. But we're going to talk about that in a minute. Let's add
00:08:03 - our trusty little directory that we have. We are
00:08:08 - going to add /dev/sdb1, which is the same partition
00:08:13 - we've been working on for many nuggets.
00:08:15 - And where did we mount that? We mounted it on mnt/hard_drive.
00:08:19 - Now here's something -- let me just
00:08:23 - segway for a second here. You'll notice that the floppy drive
00:08:26 - and CD drives are mounted inside this folder called media.
00:08:30 - Now this is specifically listed on the lpic exam, and media
00:08:34 - is the place that generally removable media is mounted, okay.
00:08:39 - So, now I'm using the old school mnt folder for mounting another
00:08:43 - hard drive, right. As far as a program is concerned, it doesn't
00:08:46 - matter where you mount it. It just has to be an empty folder.
00:08:49 - But the tradition, or what's generally used, I don't want to say standard, because
00:08:54 - it's not necessarily a standard that you have to mount it
00:08:57 - in this media folder, but it's generally now in modern distribution,
00:09:01 - where removable devices are mounted. As in a folder inside the media
00:09:05 - folder, okay. Now, we just used a folder inside the mnt folder,
00:09:09 - and this is an empty folder called hard drive, which we saw
00:09:12 - a little bit ago when we were mounting it manually, alright.
00:09:16 - So, the next field is going to be what file type it is. Now you
00:09:20 - can type auto, like this, and it will probably detect it. But
00:09:23 - we actually know what the file system is. So we'll type ext3.
00:09:27 - And this next field here is options. Now, you can do this. You
00:09:32 - can say defaults, and it will give you a good set of defaults.
00:09:36 - It will auto mount the file system. It will be read-write. Let's
00:09:40 - put a couple of specific ones in here though. Let's say we
00:09:43 - want it to be read-write, the other option will be read only, which
00:09:47 - means that nobody could write to it, not even root. Because the
00:09:50 - file system itself would be a read only. User, now user is
00:09:56 - a really neat flag, and this actually is one of the ways that,
00:10:00 - or one of the objectives, to learn to do this, but if you add the
00:10:04 - user option, that means that any user, not just root, will
00:10:08 - be able to mount and unmount. If you remember, when we first tried
00:10:10 - to mount a file system, it said you had to be root. Well if
00:10:13 - you actually use this user flag, you don't have to be root in
00:10:17 - order to mount it. Now, the next one that we're going to add is auto. Now, the difference
00:10:23 - here, you see the cd, or this floppy drive, is noauto. What
00:10:27 - this means, it's different than the auto that detects the file system.
00:10:31 - This means that we'll automatically mount on bootup, okay. It's
00:10:35 - going to automatically mount this file system listed on bootup.
00:10:39 - Now, if you don't put auto in here, it's not going to auto mount it, unless
00:10:43 - you write that, remember I said defaults will give you a good
00:10:47 - group of default listings, of default options. Well,
00:10:51 - one of those options is auto. But we're going to specifically type
00:10:55 - that in, auto, and then we'll say, noexec, because executable
00:11:01 - or no executable. This means that anybody -- or that nobody
00:11:05 - will be able to run a binary program running in this field. A lot
00:11:10 - of times people will do this if they mount a home directory, they'll
00:11:13 - mount it with a noexec flag. So that people can't compile and
00:11:18 - run binary programs in their home directory. That could be
00:11:21 - a security risk, okay. So this is a pretty simple
00:11:24 - list of options. If you want to see all the options available,
00:11:28 - it's kind outside of the scope of this nugget, but go ahead
00:11:31 - and look at the man page. So type man mount, the manual
00:11:35 - page for the mount command, and it will show you a list of all
00:11:37 - the other options. If in doubt, just put defaults. Because just
00:11:41 - the word defaults as the only option, is a good set of defaults
00:11:45 - for mounting a standard file system, okay. Now, the next field
00:11:49 - is going to be that dump. Now, we're going to say zero. So it doesn't
00:11:53 - automatically write and shut down. That's generally what you
00:11:56 - want there, and then for pass. Now again, what order they're scanned in
00:12:00 - system startup. Now, let's see if we can figure this out. If you remember,
00:12:04 - I said the root
00:12:06 - partition, the root file system, generally has a one.
00:12:11 - Removable devices, generally have a zero. And I said, any other
00:12:16 - hard drive or any other partition mounted, like a user partition,
00:12:20 - or in our case the mount hard drive partition, will generally
00:12:24 - have a two, alright. So we quickly save this file.
00:12:29 - Okay, so let's see. We have, let's type mount, and see what's mounted,
00:12:34 - see. So we have nothing mounted here right now, okay. So --
00:12:38 - well, we have lots of stuff mounted, but -- alright. The partition
00:12:41 - we've been playing with has not been mounted. Now since we added that user
00:12:46 - option, I should be able to mount this without being root first, okay.
00:12:49 - And now, the other cool thing. We don't have to specify
00:12:54 - the device and the partition and the file type.
00:12:57 - Because that's all in there. All we have to do is reference
00:13:00 - one of them. So, let's say -- we either have to reference a device or the
00:13:04 - folder to mount it on. So let's say /mnt/hard_drive, okay.
00:13:08 - I didn't tell it what device to mount there, I just did
00:13:12 - that, and let's see if it worked.
00:13:16 - Sure enough, it mounted our file system. And the reason is, when
00:13:20 - you type mount in a file, it parses that at fstab file
00:13:23 - that we edited, and it says oh, okay. I know what's supposed to go on
00:13:27 - that folder that you specified, it's supposed to be /dev/sdb1
00:13:31 - So the same thing with umount.
00:13:34 - Now again, since we have that user option, we can do this without being
00:13:38 - root. So we can do it just as a regular user. Now, let's
00:13:42 - address it this way, /dev/sdb1
00:13:46 - And now the same thing. I didn't call it the same thing. I
00:13:49 - referenced a folder here, and I referenced the device here. But
00:13:52 - since it's in the fstab file, it knew what I was talking
00:13:55 - about, and it unmounted, it. So now if we type ls that folder, you see,
00:13:59 - it's just an empty folder again. Because I unmounted it with the umount command, alright.
00:14:03 - Now, this will, if I reboot the system, it will be mounted
00:14:07 - automatically, because remember, that's the default, and that's
00:14:13 - all there is to mounting and unmounting. Now remember, you have
00:14:16 - to be root, unless you specify, specify that user option
00:14:21 - in the fstab file.
00:14:25 - We started out this nugget, learning how to manually mount and unmount
00:14:29 - file systems with mount and umount. Now notice it's not unmount, the command
00:14:34 - is umount, alright. So we learned how to do that, and then we
00:14:38 - learnt how to edit the etc, or the /etc/fstab file and
00:14:42 - learnt how to mount things automatically on boot up using that
00:14:46 - auto option, right. If you write that auto option, or if you just
00:14:49 - use defaults. You know, type in defaults as the
00:14:53 - option, then it will automatically mount on boot up. Then we
00:14:57 - also learned about the user option, or the user flag, inside the
00:15:00 - /etc/fstab file, and that will allow a regular old
00:15:04 - user to mount and unmount file systems, right. Because we learned
00:15:09 - early on, that if you don't specify user, and you just try
00:15:12 - to mount and unmount, or umount a file system. It's says, well, only
00:15:17 - root can do that. But if you add that U-S-E-R option in the
00:15:21 - /etc/fstab, anybody a non root user, or a root user will be
00:15:26 - able to edit that, or to mount and unmount that.
00:15:30 - Now the one other thing I wanted to talk about, is automounting. Now,
00:15:34 - for the lpic exam and for this specific nugget, basically
00:15:38 - it's talking about a system that doesn't have a desktop manager,
00:15:41 - like GNOME, KDE. Because, if you are running, like for example, Ubuntu,
00:15:46 - and you put a USB drive in, it's going to automatically mount
00:15:50 - that on your desktop. And that is way beyond the scope of
00:15:54 - what we're trying to teach here. We're trying to teach the basic
00:15:57 - mount and unmount thing, and how to edit fstab for
00:16:01 - this objective number, okay. However, on your system, if you
00:16:05 - notice that weird things are going on, it's probably because
00:16:07 - you're running a gooey (GUI) operating area, a gooey environment, and
00:16:11 - the automount built into GNOME, or KDE, or whatever your
00:16:15 - desktop manager is, is probably taking over, and doing some stuff
00:16:19 - behind the scenes, that's beyond what we're learning here, okay.
00:16:22 - So don't worry if this is a little bit confusing, just know
00:16:25 - how to do the mount, the umount, and how to configure an /fstab file,
00:16:29 - and that will get you through this nugget, okay. I hope
00:16:33 - that this has been informative for you and I'd like to thank you
00:16:35 - for viewing.