Mount Command in Linux

November 01, 2005
This article explains the use of mount command in Linux.

What is meant by mounting a drive ?


Mounting is the process of attaching a device to the native file system tree so that you can access the data on the device locally. A device can be any removable unit that is capable of carrying data. This can be a hard disk, floppy, CDROM drive, USB pen drive, Zip drive, cell phone and so on.

In Linux and other Posix compliant operating systems like Unix, you need to specifically mount the storage device, prior to start using it.

Linux distributions now a days are capable of automatically mounting a device when you attach it to your computer.


There are special cases though, where you may want to mount the device manually.

Use the command line tools mount to attach a device and umount to detach the device.

Mount command examples


The following are a couple of mount command examples.

Check which filesystems are mounted


$ mount

Re-mount a drive as read-only


To mount a drive as read-only, use the -o remount,ro mount option as follows.

# mount -o remount,ro /dev/hda2 /mnt/C/

The above example remounts an already mounted partition /dev/hda2 as read-only.

This is useful if you want to take a backup of a filesystem in a production server. Mounting a partition as read-only ensures no one can write to the partition while the backup is going on.

Once the backup is finished, you can remount the filesystem as read-write using the -o remount,rw option as follows.

# mount -o remount,rw /dev/hda2 /mnt/C/

ro - Read only
rw - Read write.


Another use of remounting is in a situation where your system gets corrupt and you are forced to boot into single user mode. Now the filesystem is mounted read-only. To make any changes to the files, you will have to remount the filesystem as read-write.

How to mount an ISO file to view its contents


You can mount an ISO file to access its contents by mounting it as a loopback device.

# mount -t iso9660 -o loop,ro  knoppix-4.0.iso /mnt/iso

The above example mounts a Knoppix ISO in the location /mnt/iso.

This is useful if your computer BIOS does not support booting from the CD-ROM for some reason, and you need to access the contents of the ISO to create a boot floppy. Most Linux ISO's contain a floppy bootdisk image which you can copy to your floppy.

Move an already mounted filesystem to another location


I have already mounted a FAT32 partition in the /mnt/D/ location. Now if I want to delink it from the current location and make it available at another location, I use the --move option with the mount command.

# mount --move /mnt/D/ /mnt/newLocation/

This delinks the device/file system mounted at the /mnt/D/ location and links it to the new location specified by the /mnt/newLocation/.

Mount a filesystem simultaneously at two different places


Use the --bind or --rbind option to mount an already mounted device / filesystem to another location with different rights.

Lets say I want to provide read-write access to all the users to a location /mnt/D/softwares which has been mounted with read-only access. I can do it as follows.

Update: This doesn't seem to work. So please scratch out the above example.

# mount -o rw --bind /mnt/D/softwares /mnt/backup

Now only the subdirectory /mnt/D/softwares is accessible as read-write at the new location /mnt/backup.

Unmounting a drive


To unmount a drive/file system/device, use the umount command.

# umount mount-location

Where mount-location is the full path of the directory where you have mounted the removable device you wish to detach.

If a device is mounted, it should be unmounted before physically detaching it from your computer. Not doing so will corrupt the data on the removable device.

1 comments:

  • # mount -o rw --bind /mnt/D/softwares /mnt/backup

    The subdirectory 'softwares/' stays accessible as read-only in the location /mnt/backup !

    Please check.

    The contrary is true, within a rw filesystem you can make a subdirectory read-only .