How to Mount a File System on Linux

in linux •  5 months ago 

Mounting or unmounting a file system on Linux is usually straightforward, except when it isn’t. This article teaches you how to mount and unmount file systems, as well as list available and currently mounted file systems. It also explains how to handle the case where file systems won’t unmount because they are in use.

A filesystem is a way that an operating system organizes files on a disk. These filesystems come in many different flavors depending on your specific needs. For Windows, you have the NTFS, FAT, FAT16, or FAT32 filesystems. For Macintosh, you have the HFS filesystem and for Linux you have more filesystems than we can list in this tutorial. One of the great things about Linux is that you have the ability to access data stored on many different file systems, even if these filesystems are from other operating systems.

Screenshot from 2024-09-03 11-08-29.png

In order to access a filesystem in Linux you first need to mount it. Mounting a filesystem simply means making the particular filesystem accessible at a certain point in the Linux directory tree. When mounting a filesystem it does not matter if the filesystem is a hard disk partition, CD-ROM, floppy, or USB storage device. You simply need to know the device name associated with the particular storage device and a directory you would like to mount it to. Having the ability to mount a new storage device at any point in the directory is very advantageous. For example, lets say that you have a web site stored in /usr/local/website. The web site has become very popular and you are running out of space on your 36 GB hard drive. You can simply go out and purchase a new 73 GB hard drive, install it in the computer, and then mount that entire drive as /usr/local/. Now your /usr/local mount point has a total hard drive space of 73 GB, and you can free up the old hard drive by copying everything from the old /usr/local to the new one. As you can see, adding more hard drive space to a computer, while still keeping the same exact directory structure, is now very easy.

Seeing a list of mounted filesystems

In order to determine what filesystems are currently being used type the command:

$ mount

When you type this at a command prompt, this command will display all the mounted devices, the filesystem type it is mounted as, and the mount point. The mount point being local directory that is assigned to a filesystem during the process of mounting.

How to mount filesystems

Before you can mount a filesystem to a directory, you must be logged in as root (some filesystems can be mountable by a standard user) and the directory you want to mount the filesystem to must first exist. Also in some situations, you must be logged in as the root user in order to make the particular mount directory. If the directory exists, and any user can mount that particular device, then it is not necessary to be logged in as root. When mounting a particular filesystem or device you need to know the special device file associated with it. A device file is a special file in Unix/Linux operating systems that are used to allow programs and the user to communicate directly with the various partitions and devices on your computer. These device files are found in the /dev folder.

As our first example, lets use a real world example of accessing your Windows files from a floppy in Linux.

In order to mount a device to a particular folder, that folder must exist. Many Linux distributions will contain a /mnt folder, or even a /mnt/floppy folder, that is used to mount various devices. If the folder that you would like to mount the device to exists, then you are all set. If not you need to create it like this:

$ mkdir /mnt/floppy

This command will have now created a directory called /mnt/floppy. The next step would be to mount the filesystem to that folder or mount point.

$ mount -t msdos /dev/fd0 /mnt/floppy

You have now mounted an msdos filesystem, which is indicated by the -t (type) option. The device is recognized by the /mnt/floppy point. Now you can access MS-DOS formatted disks as you would any other directory.

To mount a CD-ROM:

$ mount -t iso9660 /dev/cdrom /mnt/cdrom

Again this is a similar method as above to mount the CD-ROM.

Different filesystems can also be mounted in a similar manner:

$ mount -t vfat /dev/hda1 /win

Any filesystems that are not mounted can be seen via the df command. So using that command you know what you got to work with.

Note: The -t option should be used so that the operating system knows the specific filesystem type that you would like to mount the device as. If you leave the -t option out of the command, mount it will attempt to determine the correct filesystem type it should mount the device with.

How to unmount a filesystem

When you are done using a particular filesystem, you should unmount. The command to unmount a filesystem is the umount command.

When unmounting a filesystem you simply type umount followed by the mount point. For example:

$ umount /mnt/floppy

$ umount /mnt/cdrom

Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command. File system mounting and unmounting requires you to be logged in as root, or use the sudo prefix to temporarily take on root privileges.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

"Wow, this article is super helpful! 🤩 Thank you for sharing your knowledge on how to mount and unmount file systems in Linux. I'm definitely bookmarking it for future reference. 😊 It's great to see such a detailed explanation of how to handle different scenarios, like accessing Windows files from a floppy disk in Linux.

I'd love to hear more about your experience with mounting and unmounting file systems! Have you had any tricky situations or successes with this process? Let's discuss it in the comments below!

And don't forget to vote for @xpilar.witness by going to https://steemitwallet.com/~witnesses. With your support, we can continue to contribute to the growth and success of the Steem community. 💕"