How To Mount and Unmount Drives on Linux

Mount and Unmount Drives on Linux
(Image credit: Tom's Hardware)

In a Linux GUI, we usually take it for granted that when we insert a USB flash drive, best hard drive, or even a DVD disk, they just appear ready for use. But under the hood there is a process where the device is mounted (made ready for use) and assigned a mountpoint. When using a server or a remote connection, it is not certain that a device will automatically be made available, so how can we mount our own devices?

In this how-to we’ll look at various ways of mounting and unmounting disks and disk images. We will use a variety of approaches and tools including both terminal emulator commands and GUI tools.

All the commands in this how-to will work on most Linux machines. We’ve used a Ubuntu 20.04 install but you could run this how-to on a Raspberry Pi. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t. 

Unmounting and Mounting Drives using GUI tools

(Image credit: Tom's Hardware)

Most of the time when you attach a drive, for example a pen drive, the system will recognize it and automatically mount the drive. Occasionally this may not happen and knowing how to manually mount and unmount a drive can be a useful skill.

1. Plug in a USB Flash drive and allow it to automatically mount. You should see an icon appear as a shortcut to the drive, or opening a file explorer you will find the pen drive mounted.

(Image credit: Tom's Hardware)

2. Press the Windows / Super key and search for “disk.” Select the Disks utility.

(Image credit: Tom's Hardware)

3. Selecting the USB Flash drive correctly. Click the square stop button icon to unmount the disk. You will see your main system disk drive(s) and also the pen drive you just inserted, so double check before taking the action.

(Image credit: Tom's Hardware)

4. Click the mount button to re-mount the drive. With the pen drive unmounted the mount button icon changes to a triangular “play” icon. Clicking this will remount the pen drive.

(Image credit: Tom's Hardware)

5. Unmount the drive to get ready for the next part of the tutorial. It’s useful to have the pen drive attached but not mounted for the next part of the tutorial so unmount it by once again clicking the unmount button in the disk utility.

Identifying and Mounting a Drive using the Linux Terminal

Using the command line interface (CLI) in the terminal emulator allows us to have more control over when drives are mounted and the position in the filesystem that they are mounted to.

(Image credit: Tom's Hardware)

1. Identify the USB drive using the lsblk command. In the results you may well see lots of entries labeled “loop.” However you are looking for results that are listed as sda or sdb to identify physical disks attached to your system. Comparing the listed capacity of the attached drives can often help you discover the name of your target drive. In our case we can identify our USB drive as sdb1.

lsblk

(Image credit: Tom's Hardware)

2. Create a directory to mount the USB drive into. When an external drive is automatically mounted it is often mounted inside the media directory. However using the CLI we can create and specify a directory into which we will mount our pendrive. Note that we need to evoke root privileges using sudo to create a directory inside the media directory.

sudo mkdir /media/pendrive

3. Mount the USB drive to the /media/pendrive directory using the mount command. The mount command has the following syntax; sudo mount /path/to/drive /path/to/mountpoint.

sudo mount /dev/sdb1 /media/pendrive

4. Check the drive has been mounted by re-running lsblk. Notice that the final column in the lsblk output lists the mount point of the listed device, if there is a mount point listed then the device is confirmed as mounted.

(Image credit: Tom's Hardware)

Unmounting a drive in Linux using the umount command

(Image credit: Tom's Hardware)

Unmounting a drive is handled via the umount command and when invoked it safely removes the drive from the system, enabling us to pull the drive and use it in another machine.

1. Unmount the drive using umount command. Note the spelling of umount as a common error is people type “unmount”. Using the umount command we only need to specify the mount point location and name of the drive we wish to unmount.

sudo umount /media/pendrive

2. Check the drive is unmounted using lsblk. Notice that in the lsblk output the final column lists the mount point of detected devices, if there is no mount point listed then the device is unmounted.

lsblk

Mounting a Disk Image to view contents in Linux

(Image credit: Tom's Hardware)

It is possible to mount a disk image to appear as a read only drive. This is a useful technique if you want to copy some content out of a disk image or if you simply want to inspect a disk image’s contents. In the following example, we have used a downloaded disk image of the Puppy Linux distribution but this technique would work with any disk image including images made of disks for backup purposes.

1. Create a directory called iso in the media directory to mount the disk image into. Again this could be anywhere in the file system but we have created a directory called iso within the media directory.

sudo mkdir /media/iso

2. Mount an ISO disk image using the mount command and the loop argument. We need to run this command with root privileges so therefore we use sudo. The usage of the mount command is similar to previous uses and includes the path to the image and the path to the mount point we created in the previous step. We also add the -o loop argument to create the loop device which tricks the operating system into believing this is a real disk and not an image.

sudo mount -o loop Downloads/fossapup64-9.5.iso /media/iso

(Image credit: Tom's Hardware)

3. Unmount the ISO using umount. Once again when using the umount command we need only specify the mount point of the drive or disk image we wish to unmount.

sudo umount /media/iso

With these techniques you now have greater control over mounting and unmounting disks in Linux and have some skills that may help next time a connected drive doesn’t automatically mount correctly. Being able to mount a disk image using a loop device is very useful when exploring old backup images of previously used systems or when you want to have a look around a Linux distributions image contents for exploration or learning.

Jo Hinchliffe

Jo Hinchliffe is a UK-based freelance writer for Tom's Hardware US. His writing is focused on tutorials for the Linux command line.  

  • lsatenstein
    Hi Jo,
    I very good presentation.
    I have an approach that I follow for my external backup drive.
    I usually keep it plugged into the system, but with the entry within the /etc/fstab having ... noauto,user
    #as I am a single user on the system. Were multiple users need access to that backup, I would have ... noauto,users

    I often mount other temporary stuff with /mnt. It allows me to not worry about system reboots keeping information that should not be there.
    Reply