How to Use mount Command in Linux

The mount command in Linux integrates a different filesystem into the primary OS filesystem. It is one of the most confusing things for a Windows user who just migrated to a Linux environment. We will discuss the concept of mount, as well as it’s default syntax and usage.

The Purpose of mount Command in Linux

Windows users who are migrating to Linux are usually baffled when they plug their devices, and nothing shows up at first. It can be really frustrating and inconvenient, especially if you’re used to the plug-and-play approach applied on Windows systems.

But how come Linux users need to use the mount command to access files? It all boils down to the fundamental differences in how Windows and Linux work.

How Linux Filesystem Works

Linux and other UNIX-based operating systems run in a single file hierarchy or also known as a tree.  Root or / is called as it is because it is the top directory in a Linux filesystem (ironically). The problem with storage devices is that they have their own separate filesystems.

You need to connect the device to the main Linux filesystem to make its own filesystem accessible.  mount is a way to attach your drive’s filesystem within the Linux tree. Once connected, you would be able to access and retrieve files stored inside the drive.

A fun way to demonstrate this method is thinking of Linux as Dora (from the “Dora The Explorer” show). She can see the object in front of her (the device), but you need to point to it and say what it is so she can recognize it (mount).  

Note: A filesystem refers to methods on how OSes organize files. It references the physical location of a file within the drive. So if you want to access a photo stored somewhere on your device, you just need to fire up your photo viewer, and the filesystem retrieves the bits and pieces of the picture.

How Windows Filesystem Works

On the other hand, Windows use different directory trees for each device, making it unnecessary to mount devices separately. When you plug a device, Windows will automatically recognize a new directory tree and mount it for you.

New drives and partitions are assigned with unique letter identifiers so the OS can access them. However, the user would need to manually unmount their drives by using the eject button.

Not all distros require the user to mount their devices manually. For instance, Ubuntu and Linux Mint automount removable devices. Luckily, users can configure automounting to save time and streamline processes. You still need to format and mount new disks so users can have device access.

Syntax of mount Command in Linux

The syntax to use mount is quite simple. Just write the device name, and follow it with the directory you want to mount it to. You need to have elevated access to run this command.

$ sudo mount <directoryname> <mountpoint>

mount Options

Here are the options that you can use for the mount command. Check the manpages to see how these options are placed within an argument.

l: Enables users to add labels on mount output

-h: Displays all other options for the mount command

-V: Shows the current mount version

-a: Automatically mounts all filesystems indicated in /etc/fstab

-t: Sets the filesystem type of the mounted device

-T: Gets info on alternative fstab if available

-O: Used to limit the set of filesystems  

-r: Read-only

Listing all Mounted Filesystems using Mount Command in Linux

Showing all the mounted filesystems is very straightforward, type mount in your terminal to show all the filesystems mounted in your computer.

$ mount
mount command in linux

Mounting and Unmounting a Filesystem

The easiest way to mount a filesystem is the method utilized below. Here, the example the partition /dev/sda6 is mounted to a directory called sample. All devices mounted with this method will not remain mounted after a reboot.

$ sudo mount /dev/sda6 /home/grumbot/sample

Note: You need to create the mount point directory if it is not available yet. You can use mkdir to do this or through your favorite file explorer.

Use umount to unmount your device. Unmounted devices are greyed out when you see them on your desktop. Linux cannot identify unmounted devices, physically connected or not.

$ sudo umount /dev/sda6 /home/grumbot/sample
umount command in Linux

Using the /etc/fstab Method to Mount

The /etc/fstab is a file that allows users to automatically mount devices after a system reboot without using mount Command in Linux. You need to use gedit (or other text editors that you prefer) to view and modify the contents. It will look just like the screenshot shown below.

mount command in Linux using fstab

Each line after the <file system> represents each device entry that automounts even after a reboot. The first step is to mount the device that you want to add to your fstab file. Then run sudo blkid command.

$ sudo blkid
getting your disk UUID

Choose the partition you want to automount and save the information somewhere. Go to this fstab line generator to configure your prompt. The device address is your entry created by blkid. In my case, it is the /dev/sda6 drive. I’ll just plug this again into the /home/grumbot/sample folder.

$ /dev/sda6: UUID="e057108f-4141-43c0-937a-3b238c9a6141" TYPE="ext3" PARTUUID="4a6626af-06"

You can choose ext3 on the drop-down option if you want to use the ext3 filesystem. Don’t forget to check the auto-mount option. Executable makes your drive capable of running scripts automatically. All other options are up to you to check or skip.

Here is my final output to automount /dev/sda6 into the system. Add your customized line into your fstab file and reboot. Your drive should be mounted already.

$ /dev/sda6: UUID="e057108f-4141-43c0-937a-3b238c9a6141" TYPE="ext3" PARTUUID="4a6626af-06" /home/grumbot/sample ext3 auto,nouser,exec,rw,async,atime 0 0

And that’s it for the mount tutorial, I hope you learn something about Linux and overall the Unix system and how mount operates. If you need more help in navigating other Linux commands, you can check out other articles on the site. Thanks for reading, and happy learning!

If this guide helped you, please share it. ?

Leave a Reply
Related Posts