Until Windows 8, a PC had no native support for ISO files. A little piece of software could help you cope with that very easily, but you still had to install it by yourself. On Linux, you can mount any ISO or file systems immediately with a simple command. However, it can be a little tricky to manipulate devices, especially if you were used to Windows before. You have to think using Linux’ philosophy: everything is a file. Therefore, a device can be considered as a folder, which is a file in itself. And mounting a device consists in giving some space and a path to that file.
First of all, you will need the super-user rights in order to mount anything on your computer. The general syntax is something like:
sudo mount [-t type] [-o options] [unmounted device] [path to the mounted device]
After the parameter “t”, you should provide the type of the file system that you are trying to mount. If you do not write anything, the program will try to find by itself the type. The most common ones are vfat, iso9660, reiserfs, nfs, ramfs, smbfs, ext2, ext3, and ext4. On the other hand, “o” stands for the options that you can precise, such as:
- auto/noauto for automatic mounting or not
- exec/noexec to specify if the binaries on the file system can be executed or not
- user/nouser to determine if any user or just the root can mount the device
- ro/rw which stands for “read-only” and “read and write”
In general, you would want to use the option “defaults” which sums up the most used parameters: async, auto, dev, exec, nouser, rw, suid. And you can put more than one option of course, as long as you separate them with a comma. For more options and types, you can read the manual page of mount with
As an example, you can now mount any ISO file simply with
sudo mount -t iso9660 -o loop [image.iso] /mnt/
Notice that the directory /mnt is specially intended for mounting devices. You do not have to use it but it is good to know that it is there. You should also keep in mind that if you mount a device on a non-empty directory, the content will be hidden but not destroyed (you can make it re-appear by removing the mounted device). And if you want to become more familiar with the options and types in general, using the command mount without any argument will display the list of currently mounted devices (the same list can be found at /etc/mtab, which stands for Mounted file systems TABle).
Now that you know how to mount stuff, the next logical step is removing them: umounting as we’ll call it since we use the command umount to do so. Umounting is also very important since it is the moment when the data will be physically written on the device. Therefore, you cannot eject the device if it is still in use. As a side tip, the command fuser will help you find the processes and the users depending on a specific device:
fuser -v [mounting point]
With the option “v” standing for verbose mode. Back to device ejection, the syntax for umounting is very simple:
sudo umount [mounting point]
Another cool stuff about the mount command, you do not have to umount a device and then mount it again in order to change its mounting options. Instead use the parameter “remount” following the syntax:
sudo mount -o remount,[new options] [mounting point]
For those who want to go further and use the mount command very frequently, you can configure the file /etc/fstab to simplify the mounting of devices, and even make it automatic on boot. For example, I use fstab to mount my LVM devices before the daemons.
The syntax is as follow:
- the device to mount or its UUID
- the mounting point
- the type of file system
- the mounting options
- the dump frequency (if you have no clue leave it 0)
- the verification frequency (0 to ignore it, 1 to check it first, 2 to check it second, etc.)
If you indicate “noauto” in the options, the device will not be mounted automatically but the mount command will be simplified:
sudo mount [name of device recorded in fstab]
You should now be able to use the mount command like a pro. At least be able to mount your ISO files easily. We even covered a bit more with fstab but I refused to name this article “Everything You Need To Know About Mounting” because of the unintended pun. If you want to go further, I invite you to check out labels which simplify the mounting of devices (start with e2label and mlabel). And as always, the manual page are pretty good too. As a bonus, you can try using a GUI like pysdm for all the mounting, but again the command line is a must-know.
Do feel confident about the mount command? Do you use it frequently? Do you have any other examples to propose? Please let us know in the comments.
Our latest tutorials delivered straight to your inbox