Mount

From LQWiki
Jump to navigation Jump to search

Mount refers to both an action and a command. Linux and other Unix-like operating systems deal with disks and file systems in a different manner than some operating systems such as Windows. Instead of assigning a drive letter to each drive, operating systems such as Linux instead deal with a single hierachy, known as a unified filesystem. A drive (represented by a device, listed under /dev) is mounted, and the files on the drive are made accessible as a directory under this single hierachy. The mount tool is used to mount a device.

Usage

Linux and other Unix-based operating systems, however, can deal with disks and devices in multiple formats. Consider trying to mount a CD-ROM. We need to know the following information:

For example, CD-ROM disks use the ISO9660 format, and the device name is /dev/cdrom. There is a directory available for mounting CD-ROM disks, and that is /mnt/cdrom, so we might use this command to mount a CD-ROM disk:

mount -t iso9660 /dev/cdrom /mnt/cdrom

To mount a samba share:

 mount -t cifs -o username=<name>,password=<passwd> //MYSAMBA /mnt

In general, you can call mount directly from the command line, using the following general syntax:

  mount [options] [device] [dir]

unmount

To unmount, use the command umount. If it complains like

device in use

call lsof (list open files) and find which processes are blocking the device.

fstab

During the installation process, most linux distributions create a file called /etc/fstab, the filesystem table. This file contains mount settings for the volumes installed in your system. This means that we can avoid having to type in the device name, format, etcetera, if we merely want to mount a CD. For example, if line did not exist already, you could add the following line in your /etc/fstab file for your cdrom drive (the first line here is just a helper for you; only add the /dev/cdrom line to /etc/fstab):

  (device name)  (mount point)   (filesystem types)   (options)        (usually 0 0)
  /dev/cdrom      /cdrom          iso9660              ro,user,noauto   0 0

Then, when you want to mount a new CD, you would just type mount /cdrom.

By default, many linux distributions will require you to go root to mount and unmount volumes (this is signified by the lack of an option "user" or "users" on the line). Example of a root-only-mountable device:

  /dev/floppy      /mnt/floppy    auto                 noauto,defaults  0 0

The "user" option is so that any user can mount the cdrom and then only he can unmount it.

The "users" option is so that any user can mount the cdrom and he or any other regular user can unmount it. Examples:

  /dev/floppy1      /mnt/floppy1    auto                 noauto,defaults,user   0 0
  /dev/floppy2      /mnt/floppy2    auto                 noauto,defaults,users  0 0

Mounting an ISO image from an ordinary file

Sometimes it is useful to mount an ISO image file that you made or have downloaded to be able to access or check the contents. In Linux, this is known as loopback mounting and is done by using the loopback device. This is possible with the following command:

  mount -t iso9660 -o ro,loop=/dev/loop0 NameOfISOFile MountPoint

Other Unix-like systems may provide other means.

Provided by

Most (all?) Linux distributions incorporate this from the [util-linux] project.

See also