File System Mounting - Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the key differences between Linux and other operating systems like Windows is the fact that you need to mount a filesystem on Linux before you can use it now this is one of those things that really confuses new Linux system administrators understand that on Linux you have to mount hard disk partitions DVDs USB drives etc before you can actually use them now the good news is the process of mounting a filesystem on Linux is really pretty easy it's done using the mount command the mount utility mounts the filesystem that's already been created on a partition or on an optical disk or on a flash drive into an existing directory within the Linux file system that way when you switch into that directory what you're actually doing is switching to the filesystem on that storage device to use the mount command you enter mount and then use the Dashti option to specify which filesystem you want to use then you point to the partition that you want to mount and remember that this has to match what is configured on this you can't just use whatever filesystem you want if I've created an ext4 filesystem on SD b1 then that's the type of file system I have to specify with the mount command then after the device file that we're mounting we specify where in the filesystem we want to mount it at in this case I'm mounting it in a directory called slash mount slash shared you can see that in my /mnt directory I already have a directory named shared that way when I switch to the shared directory what I'm really doing is switching to this partition the first partition on the second hard disk in the system now here's a little tip there may be times when you need to mount a storage device say a flash drive and because it's a flash drive you're not the one that actually partitioned and formatted it and so you may not know what filesystem it uses in these situations you can use the - a option instead of the - T option and if you use - a you don't have to specify a file system type you still specify the device file name and the you want to mount it in using the - a option will cause the mount command to try to mount whatever partition you've specified using all supported filesystem types until one actually works and as soon as that's done it goes ahead and completes the mounting operation now be aware that on most distributions the /mnt directory is the default directory that's used for mounting both local and remote file systems when I say local I'm talking about locally connected devices such as the USB Drive or an optical disk while a remote filesystem is one that's being accessed on another computer over a network connection now you don't have to use /mnt to mount a filesystem if you don't want to you can mount a partition into any directory in the Linux file system that you want however by convention /mnt is used by default for this purpose now on most distributions /mnt is used to mount not only partitions on a hard drive but also external flash storage devices like a USB Drive it's also used for mounting optical devices such as a DVD however be aware that some distributions will kind of split things up and they will use /mnt for mounting partitions on hard drives and they will use the slash media directory for mounting removable media like an optical disk or a USB flash drive now be aware that there are other options you can use with the mount command that we haven't covered here go ahead and look at the man page for mount you can see a complete listing of all the available options for example you can use the - o option to specify mounting options that are used as that device is mounted in the file system a good example would be - o ro which mounts whatever device you specify into the directory you specify but mounts it read-only so you can read information from it but you can't write information to it now after mounting the partition you can then use the mount command with no options and no parameters to simply view all of the mounted file systems this is a very useful command that you should remember you can then look through the output to verify that the device you specified is actually mounted in the directory you specified in this case we mounted /dev / SD b1 in the /mnt / shared directory using the ext4 filesystem now you need to be familiar with this file right here / Etsy / M tab this is an important file understand that whenever you mount or unmount a device in the Linux file system this file gets updated therefore it always contains the most current list of currently mounted file systems and it is just a text file therefore you can view it using a standard text viewing utility like cat or less or more and by doing so you can see a list of mounted file systems and here you can see that we have stb-1 mounted in the directory we've specified with the file system we specified in addition to the /xe / M tab file you can also view the contents of this file to view information about mounted file systems /proc / mounts and again it's just a text file so you can use cat less or more whatever it is you want to use to view it and again we see the partition that we mounted in the this directory using the ext4 file system now in addition to mounting a file system you can also unmount a file system if you need to this is done using the you mail command now as soon as I say this in every single class a student pipes up and says you spelled that wrong it's not you mount its unmount no actually it is not unmount it is truly you mount to unmount a filesystem you enter the you mount command followed by one of two different things either the device that you want to unmount such as slash day of /s s db1 or you can also specify the directory where that device is currently mounted in this case slash mount slash shared either one of these commands would accomplish the exact same thing now it's important that you remember that when you're trying to unmount a filesystem the device that you're trying to unmount cannot be busy if it's busy then it's not going to unmount for example in this case I have used the CD command to change into the shared directory which is where this device is mounted and then I try to use the u mount command to unmount this device and it says I can't I'm busy somebody's using it the same thing would hold true if I had mounted say an optical disk or USB Drive somewhere in my filesystem and I were using the filesystem on that device when if I try to unmount it with the u mount command it'll give me a similar error saying hey somebody's using it I can't unmount it right now now this brings up another issue when you're working with Linux file systems understand that just because you mount a file system with the mount command does not mean it's going to stay mounted as long as the system stays running yeah it'll stay mounted but if you reboot the system the device that you specified with the mount command will not be remounted by default when the system starts back up but you can fix this what you do is go into your /sc /fs tab file and then add the mounting information for that device to this file that way when the system boots up that you can be sure that that device will be mounted in the directory you specify and I did that right here I've added the / - slash SDB one device to the FS tab file I specified where I want it mount it at what file system I want to use and then I specified my mount options here we'll go into that in a little more detail here the important thing for you to remember is the fact that each line in the FS tab file contains six different fields that you need to fill out for each file system to be mounted whenever the system boots the first field specifies the device to be mounted this in this case last day of /s DB 1 the second field specifies the mount point where you want that device to be mounted in this case we want it mounted in slash mount slash shared the next field specifies the filesystem that's been created on that device and remember that does have to match you can't just use whatever file system you want the file system you specify must be the file system that has been already been made on that particular device next we have our mount options which we'll talk more about in just a second I put defaults in here which we'll just use the default mounting options you customize this entry to make this device be mounted into the filesystem using a wide variety of different options the next field specifies whether or not this file system should be dumped zero means don't dump it 1 means go ahead and dump it and then the last number specifies the order in which the filesystem check utility should check the file system when the system starts up basically there are only two different values that are used in this field the filesystem that contains the root partition should always be checked first so on that one line in FS 2 up file this field to be set to one everything else will be set to a value of two meaning it really doesn't matter basically we want the root filesystem always checked first and then after that it can be checked in whatever order we want now in that fourth field we talked about the fact that you could use a variety of different mount options and I just use defaults just to make it easy but there are many different mount options you could include in this field you can use the mount options shown here and you can use many of them all at the same time if you want to all you have to do is put a comma between the different mount options that you want to use our W specifies that we mount the filesystem readwrite so we can read data from it and write data to it where as ro only allows us to read information that does not allow us to write information the sync option enables synchronous input and output which basically means that any changes you make to a file on that filesystem need to be written immediately and this is commonly used for devices that are removable in nature such as a USB Drive because there's a potential lag between the time a write operation happens and the time when somebody pulls the drive out of the USB port you probably want your USB Drive information to be written right away and not held the opposite is the async option which enables asynchronous input/output this option is used typically on devices that will not be disconnected from the system at all like a hard disk drive by enabling a sync all the changes that are being made to the files in the file system may be cached and then they'll be written later on when the hard disk isn't busy and by doing this we increase performance but the gotcha here is that drives got to be in the system all the time otherwise you could potentially miss a write operation the a time option specifies that whenever a file is accessed the time when it's accessed will be updated in the files inode the no wait time does just the opposite it does not record the last access time in the files inode and sometimes that is used because it does provide a better overall file system performance because we're not constantly updating the I nodes of files with their last access time no dev prevents the device files and /dev from being interpreted as special block devices whereas dev just does the opposite it causes the kernel to interpret device files in /dev as special block devices we also have the no exact options which prevents binaries on that file system from being executed this can be useful from a security standpoint and the exec does just the opposite it allows any executables on the file system to be executed the no Sui D option blocks the use of Sui D and s GID permissions where Sui D does just the opposite it enables the use of su ID and SG ID permissions Auto specifies that the file system be automatically mounted whenever the system boots no Auto does just the opposite it prevents the file system from being automatically mounted on system boot the user option allows users to mount the filesystem while no user specifies that only root is allowed to mount the filesystem and as we said earlier you can just use default if you want to which if you specify will cause the kernel to mount the filesystem using the read write option the su ID option the dev option the exec option the auto option the no user option and the async option now before we end there's one more thing I want to show you and that's how to mount an image file an ISO file in other words into the Linux file system by doing this we essentially mount the ISO image into a directory and when we switch to that directory we're actually able to access the contents of the ISO file the syntax are doing that is shown here first we run mount and then we use the - Oh option to specify our mount options and we specify the loop option with - oh this specifies that we're mounting a loopback device and then we specify the file name of the image file whatever that happens to be and then the mount point where we're mounting it into the file system example is shown here mount o - loop my files the ISO in - /mnt /i so this can be really useful because it allows you to take an ISO file in your filesystem mount it into a directory somewhere and then access the contents of the ISO file basically is if it were an optical disc in an optical drive such as a DVD in your optical drive that's it for this lesson in this lesson we discussed how you mount Linux file systems first we looked at the mount command along with au mount command then we looked at the syntax of the slash Oetzi /fs tab file and then we ended this lesson by talking about how you can mount an ISO image in the Linux file system
Info
Channel: The Linux Man
Views: 131,724
Rating: 4.9570093 out of 5
Keywords: Linux, Tutorials, Learning, Testout, Coding, File System, Unmounting a File System, unmount, Code
Id: A8ITr5ZpzvA
Channel Id: undefined
Length: 13min 54sec (834 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.