Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.
If you’re looking to use the Linux terminal more, learning how to manually mount and unmount your hard disks is a simple place to start. Besides, if you ever find yourself in a situation that leaves you away from the traditional desktop, learning how to do so might save a lot of time and Googling.
Fortunately, modern Linux distributions make this process much easier and intuitive than before.
What Is Mounting?
In most cases, mounting refers to a process which enables your computer to access files on different devices, such as USBs or hard disk drives. This is because they originate from separate file systems. Mounting also occurs in most Linux distributions due to how they themselves use multiple file systems in the form of “partitions”.
Usually, modern Linux desktops handle this automatically. However, it’s good to know how to do it manually if all else fails, or if you happen to be stuck with only a terminal and need to back up some data.
Checking Your Available Partitions
To see your devices and their separate file-systems, simply use this command:
As seen above, separate devices are split into differently named letters, namely sda, sdb, and sdc. Further hard drives follow this convention, continuing to sdd, sde, and so on. Modern hard disks and USBs all start named with sd(x), short for “serial device”. On older computers, you might see them labelled like hda instead.
These devices are further split into different partitions. Put simply, they represent how your hard disk is divided up. It’s these specific partitions which we’re going to mount, rather than the devices themselves — they are where data is actually stored.
As a thumb rule, your Linux box is the device with more than one partition. This is usually done to split important and unimportant system files from one another, among other things. Another way to tell is to look under the “Mountpoint” entry. The entries which are part of your Linux box will be already mounted.
Mounting With Udisks
Udisks is an important piece of software used in many Linux distributions. It is responsible for managing storage devices such as USB flash storage, and hard disk drives. With it comes a command line tool called udisksctl. Under this tool, all of your partitioning commands follow this pattern:
Simple isn’t it? To mount your desired partition, use this command, substituting the last bit with the right partition:
udisksctl mount -b /dev/sd[b1, b2, etc.]
The -b simply denotes that what you’re mounting is from a device.
You can also mount disk images with Udisks, but it takes an extra step:
udisksctl loop-setup -r -f Example.iso
udisksctl mount -b /dev/loop[0, 1, 2, etc.]
The first command allows us to recognize our disk image as a virtual (or loop) device. The -r is optional, but makes doubly sure the files you’re mounting won’t be accidentally overwritten — it’s read only. After that, we can proceed as usual, and mount the now available disk image. Since we’re not mounting a hard disk drive, it’s labelled as loop rather than sd(x).
If you check your mounted partitions with the lsblk command again, you’ll notice a few changes.
Notice how the devices other than your Linux box now also have specific mount points. This means you can now access the files on them by going to their specified locations.
Unmounting With Udisks
Once you’re done with your USB, or any other miscellaneous device, you need to safely remove it from your Linux box to prevent data loss. This is done by unmounting the foreign file-system, decoupling it from your own.
Doing this is as simple as substituting mount with unmount:
udisksctl unmount -b /dev/sd[b1, b2, etc.]
Keep in mind that your virtual devices such as disk images are named differently to hard disk drives and USBs!
If you check your devices using lsblk, you’ll notice that your USB/hard disk drive is still present, even after unmounting it. To remove it completely and safely remove your device, you need to enter in another command which switches it off:
udisksctl power-off -b /dev/sd[b, c, etc.]
Note that this does not apply to your own partitions, as they’re part of your system. The same goes for disk images, as they’re not powered in the first place — instead, you’ll need a different command to remove them from your list of devices:
udisksctl loop-delete -b /dev/loop[0, 1, 2, etc.]
Mounting the Old-School Way
For the most part, Udisks should be able to cover most of your bases. However, it’s good to know how to do it another way. The main difference here is that you need to specify where you’d like to mount your partitions, and you won’t be able to turn off your devices using these commands after you’ve finished with them.
You will also need administrator privileges (hence the “sudo” at the beginning of the following commands), so suffice to say, using Udisks is recommended in most cases to prevent your system from breaking accidentally!
To mount a partition:
sudo mount /dev/sd[b1, b2, etc.] /mnt
The last part indicates where you’d like to place the foreign file-system in your Linux box. Traditionally, this is the /mnt directory. For multiple devices, you can mount them in sub-folders under /mnt. Just be sure to create these folders first with the mkdir command!
Like Udisks, the mount tool also supports disk images. However, memorizing how it works can be a little more cumbersome. On the bright side, you only need to enter a single command compared to the Udisks method:
sudo mount Example.iso /mnt -t (iso9660|udf) -o loop
If the contents of your disk image isn’t showing properly, you may have to alternate between “iso9660” and “udf” (excluding the brackets!) — this indicates the format of the disk image.
Unmounting the Old-School Way
Strangely enough, the command to unmount a partition is not unmount, but umount. Keep that in mind. Unlike mounting, you don’t need to specify the location of your mount point — just the device will do:
sudo umount /dev/sd[b1, b2, etc.]
You can now remove your device without data being potentially lost.
For disk images, the command is a little different:
sudo umount /dev/loop[0, 1, 2, etc.]
If ever you need to remember the specific steps to mount or unmount your devices with the command line, all you need is to do is to enter this:
As seen in the above image, you can also ask for help pertaining to the different udisksctl commands.
So there you have it. With these commands at your side, you’re one step closer to using Linux without the aid of the desktop. If you’re up to it, feel free to navigate through your freshly mounted files through the terminal too.
Looking for more helpful commands? Check out our Linux commands reference cheat sheet.