User Tools

Site Tools


handbook:handbook:mount

Mounting and Unmounting filesystem

In modern computers, the data you use can be stored on many different devices. First, the HDD ( Hard Drive Disk), then the removable media, like the Floppies and CD-ROMs(CD’s). If you are regular Windows user, then you probably know that the different filesystems in this operating system are available to you automatically. But, in Linux, every user should execute a process called mounting. Mounting means assigning physical location to every storage device you mount. Mounting is done by using the mount command. In order to use this command successfully, you must also specify a mount point and the device you would like to mount. For example, to mount your CD-ROM drive (assuming it resides in /dev/cdrom):

$mount /dev/cdrom /mnt/cdrom

Here, the first parameter to the mount command is “/dev/cdrom”. It is , of course the device we would like to mount, the CD-ROM in this case. The second parameter is the mount point, saying that we would like to mount the content of the CD-ROM to the /mnt/cdrom directory. But, every Linux system can be configured to have default mount points for particular devices. This configuration usually is stored in the /etc/fstab file.

Fstab

The fstab file resides in the /etc directory. It is nothing more then a configuration file for every device, showing how it can be mounted and where. Changing the fstab file means changing your system configuration, so only the root user has to right to edit it.

Understanding the fstab file

Here an example is shown of a typical fstab file:

	/dev/hda2 / ext2 defaults 1 1 
        /dev/hdb1 /home ext2 defaults 1 2 
        /dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0 
        /dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0 proc 
        /proc proc defaults 0 0 /dev/hda1 swap swap pri=42 0 0

Every line of the fstab file contains information about the device specified. The first piece of information is the device name ( /dev/hda2, /dev/hdv1 ..). The second part of every line is the mount point of that device, which is followed by the type of the filesystem. After the type of the filesystem come the mount options ( defaults, noauto..) and then dump options and filesystem check options.

As you can see, every device specified here, has a coordinated mount point. So, when you mount some device using the mount command, which is configured in the fstab file, it is not necessary to specify a mount point. For example, to mount the CD-ROM in this case, the following would suffice:

$mount /dev/cdrom

As configured, you know that the cdrom will be mounted to its mount point, the /media/cdrom directory.

Filesystem types

There are a lot of filesystem types and one of the most common are:

  • ext2: The standard Linux filesystem type.
  • ext3: This filesystem is a journaling extension of the ext2.
  • iso9660: The standard filesystem used for CD-ROMs.
  • msdos: This is the filesystem used by MS-DOS.
  • vfat: The filesystem used by Windows 3.x and 9x. There is also a vfat32 filesystem type, used by Windows 9x.
  • ntfs: This is a filesystem type used by Windows NT. Linux has read-only access to this type.
  • nfs: Network filesystem. Developed by Sun Microsystems, used to access remote filesystems.

Mount options

The mount options show how and by who the devices can be mounted. There are many mount options available and here is the explanation of some of them:

  • auto: When the auto option is on, then the device will be mounted automatically, on start-up , or by using the mount –a command.
  • noauto: It is the opposite option of auto, it says that the device must be mounted explicitly, using the mount command, not automatically.
  • user: The user option allows every user to mount the device.
  • nouser: This option allows only to the root user to mount the device, excluding the regular users.
  • exec and noexec: The exec option allows the ability to execute binaries on the device, while the noexec option disallows it. The noexec option should be enabled only when you mount storage device where you don’t need or can’t execute binaries. Windows partitions would be perfect for this.
  • ro: It mounts the device as read-only.
  • rw: It mounts the device as read-write.
  • sync: This option , along with async , specify how the input and the output to the filesystem should be done. Sync means synchronous, which means that the input/output is done synchronously. For example, you issue a command to copy files to a floppy device. If sync is on, then the files will be copied at the same time with the issuing of the command.
  • async: Input/output can be asynchronous too. That means, the input/output will not occur in the same time as the commands issued. If you take the sync example, but now use the async option, then the files will be written to the floopy disk after giving the command for that.
  • default: It is a default set of options. Actually, rw, suid, dev, exec, auto, nouser, and async are enabled.

Dump and filesystem check options

Dump is a back up utility. The dump option is a number which is in the fifth column of the fstab file. If the dump option is set to 0, then no backup of the filesystem will take place. The filesystem check option is in the sixth column of the fstab file. It is used by the fsck utility, of course, a filesystem check utility. This option gives the order in which the filesystems should be checked. Again, if fsck option is set to 0, the filesystem will never be checked.

Unmounting filesystems

Unmounting is the opposite process of mounting. When a certain device is unmounted, that means it can’t be accessed or modified anymore. In other words, the unmounting process is one way of preserving the device contents.

All removable storage devices, like CD-ROMs and floppies, should be unmounted before removed. That ensures that all changes are properly and successfully made. But, if you remove the media before unmounting it, then the media can easily become corrupted.

Unmounting is done by the umount command.

For example, if you unmount by the mount point:

$umount /mnt/floppy

This will unmount the floppy device, which mount point is set to /mnt/floppy. Or, you can unmount by the device name/file:

$umount /dev/floppy

Unmounting is not possible, if you do it to an active filesystem. For example, if some of the files of the filesystem are opened and in use, then the unmounting of that filesystem is impossible.

Unmounting the filesystem which contains your current working directory is also a common problem. So, make sure that you relocate to other filesystem before unmounting the current one.

handbook/handbook/mount.txt · Last modified: 2010/04/15 21:18 (external edit)