Ict-innovation/LPI/104.3

104.3 Control mounting and unmounting of filesystems

edit

Candidates should be able to configure the mounting of a filesystem

Key Knowledge Areas

  • Manually mount and unmount filesystems.
  • Configure filesystem mounting on bootup.
  • Configure user mountable removable filesystems.



Mounting Filesystems at Bootup

At boot time the /etc/fstab file assigns mount points for block devices.

The /etc/fstab format

device mount-point fstype options dump-number fsck-number

Sample /etc/fstab

LABEL=//ext2defaults1 1

LABEL=/boot /boot ext2defaults1 2

LABEL=/home /home ext3defaults1 2

/dev/fd0/mnt/floppy autonoauto,owner0 0

LABEL=/usr/usrext2defaults1 2

LABEL=/var/varext3defaults1 2

none/procprocdefaults0 0

none/dev/shmtmpfsdefaults0 0

none/dev/pts devpts gid=5,mode=6200 0

/dev/hdc9swap,pri=-1swapdefaults0 0

/dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0

The options that are available for use with fstab file:

  • atime / noatime / relatime The Unix stat structure records when files are last accessed (atime), modified (mtime), and created (ctime). One result is that atime is written every time a file is read, which has been heavily criticized for causing performance degradation and increased wear. However, atime is used by some applications and desired by some users, and thus is configurable as atime (update on access), noatime (do not update), or (in Linux) relatime (update atime if older than mtime). Through Linux 2.6.29, atime was the default; as of 2.6.30 (9 June 2009), relatime is the default,
  • auto / noauto - With the auto option, the device will be mounted automatically at bootup or when the mount -a command is issued. auto is the default option. If you don't want the device to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be only mounted explicitly.
  • dev / nodev - Interpret/do not interpret block special devices on the filesystem.
  • exec / noexec - exec lets you execute binaries that are on that partition, whereas noexec doesn't let you do that. noexec might be useful for a partition that contains no binaries, like /var, or contains binaries you don't want to execute on your system, or that can't even be executed on your system. Last might be the case of a Windows partition.
  • ro - Mount read-only.
  • rw - Mount the filesystem read-write. Again, using this option might alleviate confusion on the part of new Linux users who are frustrated because they can't write to their floppies, Windows partitions, or other media,
  • sync / async -How the input and output to the filesystem should be done. sync means it's done synchronously. If you look at the example fstab, you'll notice that this is the option used with the floppy. In plain English, this means that when you, for example, copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command.
  • suid / nosuid - Permit/Block the operation of suid, and sgid bits.
  • user / users / nouser - user permits any user to mount the filesystem. This automatically implies noexec, nosuid, nodev unless overridden. If nouser is specified, only root can mount the filesystem. If users is specified, every user in group users will be able to unmount the volume.
  • owner - Permit the owner of device to mount,
  • defaults - Use default settings. Default settings are defined per file system at the file system level. For ext3 file systems these can be set with the tune2fs command. The normal default for Ext3 file systems is equivalent to rw,suid,dev,exec,auto,nouser,async(no acl support). Modern Red Hat based systems set acl support as default on the root file system but not on user created Ext3 file systems. Some file systems such as XFS enable acls by default. Default file system mount attributes can be over ridden in /etc/fstab.


Manually Mounting and Unmounting Filesystems

edit

The mount command is used to make a particular device available on a specific directory (mount point). The syntax is:

mount  -t [FSTYPE] -o [OPTIONS] DEVICE DIRECTORY

For example we can mount a CDROM on the mount point /media/cdrom with:

# mount -t iso9660 /dev/cdrom /media/cdrom

Mount maintains the list of mounted filesystems in /etc/mtab. Typing mount with no options will show all filesystems currently mounted. The output is similar to /etc/mtab. The kernel also keeps track of mounted filesystems in /proc/mounts.


User Mountable Configurable Systems

On a running system the /etc/fstab file also acts as a shortcut for assigning a resource to a specific directory. For example:

# mount /dev/cdrom

The mount utility reads fstab and deduces where to mount the resource. Notice that some of the devices are accessed using a label. Labels are assigned to devices with the tune2fs tool:

#tune2fs -L /usr/local /dev/hdb12

Mount can take most of the fstab options that have been listed above. This allows a user to mount a filesystem read-only or with noexec for example. Beside mounting filesystems that have been defined in the /etc/fstab file, mount can also be used to mount new devices not defined in fstab. If an external SATA drive is plugged into the machine for example, and given the device node of /dev/sdc, its first partition can be mounted as

# mount /dev/sdc1 /mnt

This will make the 1st partition of the device available under the /mnt directory.

NOTICE
Remember that mount -a will mount all filesytems in /etc/fstab that have not been mounted and do not have the option noauto

The umount command will unmount a device. Notice that the command is misspelled! The syntax is:

umount DEVICE or MOUNT-POINT

For example the following commands will both unmount the CDROM device:

# umount /dev/cdrom

or

# umount /media/cdrom

Conventionally, mount points under /media are used for removable devices such as CDs or USB storage drives.



Used files, terms and utilities:* /etc/fstab

  • /media
  • mount
  • umount


Previous Chapter | Next Chapter