How to Mount and Unmount Drives in Linux

In a Linux GUI, we usually take for granted that when we insert a USB flash drive, hard drive, or even a DVD disc, they just appear ready to go. But under the hood there is a process where the device is mounted (out of the box) and assigned to a mount point. When using a server or a remote connection, it is not certain that a device is automatically provisioned, so how do we mount our own devices?

In this tutorial, we’ll look at different ways to mount and unmount disks and disk images. We will use a variety of approaches and tools, including terminal emulator commands and GUI tools.

All commands in this tutorial will work on most Linux machines. We used an Ubuntu 20.04 install, but you can run this guide on a Raspberry pie. All procedures are performed through the terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t.

(Image credit: Tom’s Hardware)

Most of the time, when you connect a drive, for example, a USB flash drive, the system recognizes it and automatically mounts the drive. Sometimes this may not happen and knowing how to manually mount and unmount a drive can be a useful skill.

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

(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. Correct selection of the USB key. Click the square stop button icon to unmount the disk. You will see your primary system disk drive(s) as well as the USB drive you just inserted. So check well before you act.

(Image credit: Tom’s Hardware)

4. Click the mount button to remount the drive. When the USB drive is unmounted, the mount button icon changes to a triangular “play” icon. Click on it to remount the USB key.

(Image credit: Tom’s Hardware)

5. Unmount the player to prepare you for the next part of the tutorial. It’s helpful to have the USB key attached but not mounted for the next part of the tutorial, so unmount it by clicking the unmount button again in 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 what position in the filesystem they are mounted on.

(Image credit: Tom’s Hardware)

1. Identify the USB drive using the lsblk command. In the results, you may see many entries labeled “loop”. However, you are looking for results listed as nda Where bathroom to identify the physical disks attached to your system. Comparing the listed capacity of attached disks can often help you discover the name of your target disk. In our case, we can identify our USB drive as sdb1.


(Image credit: Tom’s Hardware)

2. Create a directory in which to mount the USB drive. When an external drive is automounted, it is often mounted inside the media phone book. However, using the CLI we can create and specify a directory where we will mount our USB drive. Note that we need to invoke root privileges using sudo to create a directory inside the media phone book.

sudo mkdir /media/pendrive

3. Mount the USB key on the /media/USB drive directory using ascend ordered. The ascend The command has the following syntax; sudo mount /path/to/drive /path/to/mount point.

sudo mount /dev/sdb1 /media/pendrive

4. Verify that the drive was mounted by re-running lsblk. Note that the last column of the lsblk The output lists the mount point of the device listed, if there is a mount point listed, the device is confirmed as mounted.

(Image credit: Tom’s Hardware)

Unmount a drive in Linux using the umount command

(Image credit: Tom’s Hardware)

Unmounting a disk is managed via the to disassemble command and when invoked, it safely removes the drive from the system, allowing us to remove the drive and use it on another machine.

1. Unmount the drive using to disassemble ordered. Pay attention to the spelling of to disassemble because a common mistake is that people type “unmount”. By using the to disassemble command, we only need to specify the location of the mount point and the name of the drive we want to unmount.

sudo umount /media/pendrive

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


Mount a disk image to view content 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 content from a disk image or just want to inspect the contents of a disk image. In the following example, we used a disk image downloaded from Linux distribution for puppies but this technique would work with any disk image, including images consisting of disks for backup purposes.

1. Create a directory called iso in the media directory in which to mount the disk image. Again, this could be anywhere in the filesystem, but we created a directory called iso within the media phone book.

sudo mkdir /media/iso

2. Mount an ISO disk image using ascend command and the loop argument. We need to run this command with root privileges, so we use sudo. The use of the ascend The command is similar to the previous uses and includes the path to the image and the path to the mount point that we created in the previous step. We also add the loop -o argument to create the loop device that tricks the OS into thinking it’s 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 to disassemble. Again when using the to disassemble command, we only have to specify the mount point of the drive or disk image that we want to unmount.

sudo umount /media/iso

With these techniques, you now have better control over mounting and unmounting disks in Linux, and you have certain skills that can help you the next time a connected drive fails to automount properly. Being able to mount a disk image using a loopback device is very useful when exploring old backup images of previously used systems or when you want to view the contents of an image of Linux distributions for exploring or learning.

Comments are closed.