LPI Linux Certification/Control Mounting And Unmounting Of Filesystems

Detailed Objectives
(LPIC-1 Version 5.0)

Weight: 3

Description: 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 removeable filesystems.
 * Use of labels and UUIDs for identifying and mounting file systems.
 * Awareness of systemd mount units.

The following is a partial list of the used files, terms and utilities:

Attach a filesystem
The mount command serves to attach the file system found on some device to the big file tree.

mount [options] mount [options] [-t vfstype] [-o options] device dir

If the device or directory is listed in /etc/fstab you can use the following:

mount [options] [-o options [,...]] device | dir

Normally only root has the privilege to mount devices unless it is specified in the /etc/fstab file. Examples: mount
 * 1) Print all the mounted filesystems (/etc/mtab).

mount -a
 * 1) Mount devices or dirs listed in /etc/fstab.

mount -n -o ro /dev/hdc /mnt
 * 1) Mount /dev/hdc partition in read only mode without updating /etc/mtab.

mount /media/cdrom mount /dev/cdrom
 * 1) Allow a user to mount the CDROM if the following line is in /etc/fstab:
 * 2) /dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide

mount -o sync /dev/sdb1 /mnt/usb
 * 1) Sync in realtime

Detach a filesystem
To detach a filesystem from the file tree, use umount.

umount [options] umount [options] [-o options [,...]] device | dir

A busy filesystem cannot be unmounted.
 * Open files
 * Working directory of a process.

Examples: umount -a # Unmount devices or dirs listed in /etc/fstab. umount /mnt # Unmount the filesystem attached to /mnt. umount /media/cdrom # Allow a user to unmount the CDROM if the following line is in /etc/fstab: /dev/cdrom /media/cdrom  iso9660  ro,user,noauto,unhide

File system information
The file /etc/fstab contains all the file systems and related information that will be used when doing a mount -a. (Boot time)

The file /etc/mtab is maintained by the kernel and keeps track on what is or isn't mounted. The /etc/fstab format is:

/dev/hda3  /              reiserfs defaults            1 2 /dev/hda1  /boot          ext2     defaults            1 2 /dev/cdrom /media/cdrom   auto     ro,noauto,user,exec 0 0 usbdevfs   /proc/bus/usb  usbdevfs noauto              0 0 /dev/hda2  swap           swap     pri=42              0 0
 * 1) Device    Mount point    Fs type  Options             1 2

Common options:
 * ro:     read only
 * noauto: Don't mount automatically
 * exec:   Can execute binary on the filesystem
 * suid:   Allow to setuser bit
 * user:   Allow a user to mount/unmount it
 * unhide: hidden file visible
 * async:  All operations will be done asynchronously
 * default: rw, suid, dev, exec, auto, nouser, and async

Exercises

 * Exercises results


 * 1) Create a line in /etc/fstab that allows any user to access the floppy disk. Check that you can mount the floppy and can create a file with touch.
 * 2) Do the following manipulation:
 * 3) * Create a ext2 file system on the floppy.
 * 4) * Mount the floppy.
 * 5) *Copy all the files /etc/*.conf into the floppy.
 * 6) * Unmount it. What's happening?
 * 7) * Mount it back and check that all the files are there.
 * 8) * Issue the following command:
 * 9) * Tar cvf /dev/fd0 /etc/*.conf
 * 10) * Try to mount it back. What's happening?
 * 11) * Use tar to view the contents of the floppy.