How to Mount a Drive on Ubuntu/Linux?


In Ubuntu/Linux, sometimes the Drive you want to access is not mounted and thus is inaccessible. Have you worked on what it is and how to get out of it?

Well, mounting refers to the technique of making the specific Drive accessible (read/write or read-only). A drive is mounted at a specific location known as a mount point. The mount point acts as a root directory for that drive.

Today’s post will list the possible ways to mount a drive on Ubuntu. We are using Ubuntu 22.04 for practical demonstration. However, the commands apply to all Linux distributions

Prerequisites: Create the Partition of the Drive

You must create the Drive’s partition that you want to mount. You won’t be able to mount the whole physical drive. Here’s the process of creating a partition of a drive in Ubuntu/Linux:

For instance, we are using the drive “/dev/sdc”, which has only one system-reserved partition at the moment, as seen in the following command’s output:

fdisk -l /dev/sdb

To enter the edit mode, use the “fdisk” alongside the “Drive”:

sudo fdisk /dev/sdb

Type “m” to enter the edit/guide mode:

Type “n” to initiate the partition creation process:

Up next, you can set the partition number, first sector, and the last sector (max space)

Type “w” to save the changes and exit:

Verify:

sudo fdisk -l /dev/sdb

Important: Do not confuse yourself between the Drive, Device, and Partition in Ubuntu/Linux. Device and Drive refers to the physical storage attached to the system whereas the partition is the logical division under the drive. The partition is accessible and is mounted to make the drive/device accessible/read-to-use.

How to Mount a Drive on Ubuntu/Linux?

Ubuntu offers competitive CLI support (like all other distros) and the Disks utility (a GNOME-based GUI utility). First, we will talk about the command line utilities, i.e., the mount command and the “/etc/fstab file. The mount command allows you to mount a drive on Ubuntu/Linux with the following syntax:

sudo mount [Options] [Drive] [Mount-Point]

It is necessary to use the sudo or login as a root user to use the mount command.

From the syntax, it is clear that we need the name of the drive [Drive] and the point where it would be mounted [Mount-Point].

The mount command offers various options that can be listed as:

Mount a Drive on Ubuntu/Linux Temporarily

When a drive is mounted temporarily, the drive will be unmounted at the next reboot and thus remain inaccessible after that. You need to use the mount command to mount the drive temporarily.

When we look at the syntax of the mount command, we require the “Drive/Device Name”, and the “Mount Point”. Let’s fulfill this prerequisite:

 

Step 1: Check/Find the Drive to be Mounted

List the available drives/devices using the “sudo fdisk -l” command and get the exact device name:

sudo fdisk -l

Check that the chosen device is mounted already. Use the “lsblk” command:

lsblk

The “/dev/sdc1” is not mounted yet.

 

Step 2: Create a Mount Point

Use the “mkdir” command to do so:

sudo mkdir /mnt/main

Important: You can create the mount point at any of the locations. However, it is recommended to use “/mnt” for the filesystem and “/media” for the removable drives (Pen/Optical drives).

Step 3: Mount the Drive Using the Drive/Device Name

Now, use the “mount” command to mount the drive “/dev/sdc1” at “/mnt/main”:

sudo mount /dev/sdc1 /mnt/main

Verify it using the “df -h”:

df -h

You can also verify using the “lsblk” command:

Alternative to Step 3: Mount the Drive/Device Using its UUID

Just like we used the “Device Name” to mount it. You can use the UUID of the drive instead of the name. First, get the UUID using the command:

sudo blkid | grep <device-name>

And use the “mount” command with the “-U” flag, as:

sudo mount -U <UUID> <mountpoint>

Alternative Method to Mount a Drive/Device Temporarily

Apart from the mount command, you can also mount the drive temporarily by editing the “/etc/fstab” file. It is not recommended to mount the drive temporarily using this method, yet it exists and is possible.

To do so, open the “/etc/fstab” file and put the entries as per the syntax (Go to This Section For Details). The “noauto” option is the actual parameter that halts the system to auto mount the drive/device at the startup:

Now, you have to use the “mount” command specifically on that drive “/dev/sdc1”, as:

sudo mount /dev/sdc1

When you reboot, the drive will be unmounted. Thus, you have to run the sudo mount <drive-name> command every time you need to mount it.

With this temporary method, the drive is mounted for the current session only. After the reboot, it will again be inaccessible. Let’s see how you can mount a drive permanently.

Mount a Drive on Ubuntu/Linux Permanently

FSTAB (File System Table) is the file inside the “/etc” directory which contains the permanent mounts of various drives/devices. So, if you want to mount the drive permanently, you have to update that file with the specific syntax.

Syntax of the “/etc/fstab” File

First, understand the syntax. Open the file “/etc/fstab” in the terminal and you will get the syntax in that file:

sudo cat /etc/fstab

The entries are explained below:

  • <file system>: The Drive name or the UUID.
  • <mount point>: The point where the drive will be mounted.
  • <type>: The file system type of that drive, i.e., ext4 usually.
  • <options>: Additional instructions to mount. It is recommended to use defaults, which contain rw, suid, dev, exec, nouser, and async.
  • <dump>: Create a dump for backup or not. The value could be 0 for not, and 1,2 refers to the priority.
  • <pass>: Whether to check the filesystem at boot or not. 0 for not checking, and 1,2,3 to set the priority that which filesystem will be 1st, 2nd, etc checked at the boot.

Step 1: Check the Drive Name and Create a Mount Point

Like the first method, you also need to Check The Drive Name. Here, the device name is the same as used in the Temporary Method, i.e., “/dev/sdc1”:

Step 2: Create/Identify a Mount Point

Create it Using mkdir if it does not exist:

sudo mkdir /mnt/genie

Step 3: Mount the Drive Inside the “/etc/fstab” File

Open the “fstab” file in the nano editor and put the information as per the syntax. Here, you can also use the “UUID” of the disk in place of its name, i.e., replace “/dev/sdc1” with “UUID=<UUID-No.>”:

Important: The defaults option does not allow non-root users to mount. You can add an option “user” to make it mountable for all the users (not recommended). Similarly, you can use “noauto” to not mount the drive automatically, until the changes.

Apply the changes of the “/etc/fstab” file using the “mount -a” command and also verify the changes:

sudo mount -a

Mount a Drive Using Disks (GUI Utility) | Temporarily

Linux is known for its CLI. However, GNOME-based distributions offer a GUI utility named “Disks”, which allows you to perform mounting/unmounting. This also mounts the drive temporarily.

The Disks utility is by default available on most of the GNOME-based distributions. However, here are the commands to install them if not available

sudo apt install gnome-disk-utility #Debian/Ubuntu-Based
sudo dnf/yum install gnome-disk-utility #RHEL/Fedora/CentOS

Open the “Disks” application, select the disk to be mounted, and click on the “play” icon to mount it:

It’s mounted now. By default, this method mounts the partition/drive in the “/media” directory.

You can click back on the “stop” icon to unmount it.

Can we Use Any Other File Instead of “/etc/fstab”?

Yes, we can use any file other than “/etc/fstab”. However, the format must be the same. Let’s create a secondary file and mount the drive “/dev/sdc1”:

sudo nano ~/fstable

At the time of applying changes, you have to use the “-T” option and the path of the newly created file, as follows:

sudo mount -a -T ~/fstable

How to Unmount a Drive on Ubuntu/Linux?

If you have mounted the drive temporarily, then it is easy to unmount it via the “umount” utility as follows:

sudo umount /dev/sdc1

However, if you have mounted it permanently through the “/etc/fstab”, then you have to comment or delete the partition-specific lines in the “/etc/fstab” file:

Lastly, reboot your system to apply the changes.

Bottom Line

By default, any additional storage or removable pen drive device added to the system storage cannot be accessed on Ubuntu/Linux. That’s where we need to mount the drive. First, create the partition of the drive, if not created already. Then, go for mounting.

If you have attached any media or removable pen drive, then it is recommended to mount it temporarily which will be un-mounted automatically at the next reboot. Else, do it permanently by modifying the “/etc/fstab” for permanent mount.

So, all in all, you have learned the methods/techniques to mount a drive on Ubuntu/Linux.

Print Friendly, PDF & Email
Categories