Before you can access and use any kind of storage device, it must first be mounted on the operating system. This is what is referred to as mounting. The storage medium has to be mounted for the OS to recognize its filesystem and interpret the data written on it. In this guide, you will learn how to mount a drive on Linux. The commands herein are global and are distribution-agnostic.
Listing mounted file systems
The mount/umount commands are used for attaching or detaching storage devices in Linux / UNIX systems. To list the currently attached or mounted devices, run the mount command as follows:
The output includes all filesystems including virtual filesystems such as sysfs, proc, and cgroup. Every line consists of the device’s name, directory on which the device is mounted, filesystem type, and the mount options.
To narrow down to specific file systems, pass the -t option followed by the filesystem type. The command below displays all mounted ext4 filesystems on the system.
$ mount -t ext4
How to mount a drive
Mounting a filesystem is quite a straightforward process. You must first create a mount directory on which the device will be mounted and thereafter mount the device using the mount command.
Usually, USB drives are automounted when plugged in. However, sometimes, they are be accidentally unmounted and in such cases, you might need to mount them manually.
In this example, I have a drive plugged in labeled as /dev/sdb1. You can get a list of attached devices or volumes using the lsblk command.
To mount the device I will first, create a directory or mountpoint to mount the drive. In this example, I have created the /media/winnie mount point as shown.
$ sudo mkdir -p /media/winnie/
To mount the USB drive on the mount point, the command will be:
$ sudo mount /dev/sdb1 /media/winnie/
To confirm that the drive has been mounted, run the df command and grep utility to search for the volume.
$ df -Th | grep -i sdb
We’ve successfully managed to mount a USB drive. Let’s now see how you can mount an ISO image
How to mount an ISO file
Mounting an ISO file, such as an ISO image allows you to access its contents, the same way we did with the USB drive. It’s the equivalent of the files being written on a physical medium which is then plugged in.
The procedure of mounting an ISO file is similar to what we did when mounting a drive.
First, create a mount point.
$ sudo mkdir -p /media/winnie/iso
Then mount the ISO using the syntax shown. This mounts the ISO file in read-only mode.
$ sudo mount /path/to/iso/image/ /mount/directory -o loop
How to unmount a drive
To detach a drive, simply run the command
$ sudo umount device
Mounting and unmounting a drive or an ISO image is just as simple as that. Hopefully, you are now comfortable mounting and unmounting your drives.