104.3 Control Mounting and Unmounting of Filesystems

LPIC-1 Exam Objective 104.3: Control Mounting and Unmounting of Filesystems #

In this tutorial, we’ll cover how to control the mounting and unmounting of filesystems on Linux systems. We’ll explore commands and configurations for both Ubuntu/Debian and Enterprise Linux (such as RHEL/CentOS) distributions, noting any differences between them.

Key Knowledge Areas #

  1. Manually mount and unmount filesystems.
  2. Configure filesystem mounting on bootup.
  3. Configure user-mountable removable filesystems.
  4. Use of labels and UUIDs for identifying and mounting filesystems.
  5. Awareness of systemd mount units.

Tools and Files #

  • /etc/fstab
  • /media/
  • mount
  • umount
  • blkid
  • lsblk

1. Manually Mount and Unmount Filesystems #

Mounting a Filesystem #

The mount command is used to attach a filesystem to the filesystem hierarchy at a given mount point.

Example:

sudo mount /dev/sda1 /mnt

This mounts the device /dev/sda1 to the directory /mnt.

Unmounting a Filesystem #

The umount command is used to detach a filesystem from the filesystem hierarchy.

Example:

sudo umount /mnt

This unmounts the filesystem mounted at /mnt.

2. Configure Filesystem Mounting on Bootup #

The /etc/fstab file contains information about filesystems and where they should be mounted. Entries in this file will be mounted at boot time.

Example /etc/fstab entry:

/dev/sda1 /mnt ext4 defaults 0 2

This line configures /dev/sda1 to be mounted at /mnt using the ext4 filesystem with default options.

3. Configure User-Mountable Removable Filesystems #

To allow users to mount removable filesystems, entries can be added to /etc/fstab with the user option.

Example /etc/fstab entry:

/dev/sdb1 /media/usb vfat noauto,user 0 0

This line allows any user to mount the /dev/sdb1 device to /media/usb using the vfat filesystem.

4. Use of Labels and UUIDs for Identifying and Mounting Filesystems #

Using labels and UUIDs can be more reliable than device names, which can change between boots.

Finding UUIDs and Labels #

The blkid command can be used to display UUIDs and labels of devices.

Example:

sudo blkid /dev/sda1

Output:

/dev/sda1: UUID="e2e2e2e2-2e2e-2e2e-2e2e-2e2e2e2e2e2e" TYPE="ext4" LABEL="mydisk"

Using UUIDs and Labels in /etc/fstab #

Example using UUID:

UUID=e2e2e2e2-2e2e-2e2e-2e2e-2e2e2e2e2e2e /mnt ext4 defaults 0 2

Example using Label:

LABEL=mydisk /mnt ext4 defaults 0 2

5. Awareness of systemd Mount Units #

Systemd uses mount units to manage mount points. These units are automatically created from /etc/fstab entries, but they can also be manually created.

Example of a Manual Mount Unit #

Create a file named /etc/systemd/system/mnt-data.mount with the following content:

[Unit]
Description=Mount data

[Mount]
What=/dev/sda1
Where=/mnt/data
Type=ext4

[Install]
WantedBy=multi-user.target

Reload the systemd manager configuration and start the mount unit:

sudo systemctl daemon-reload
sudo systemctl start mnt-data.mount
sudo systemctl enable mnt-data.mount

Commands and Utilities #

mount #

Used to mount filesystems.

Syntax:

mount [options] <device> <mount-point>

umount #

Used to unmount filesystems.

Syntax:

umount [options] <mount-point|device>

blkid #

Used to locate/print block device attributes.

Syntax:

blkid [options] <device>

lsblk #

Used to list information about block devices.

Syntax:

lsblk [options] [device]

Conclusion #

This tutorial has covered the essentials for controlling the mounting and unmounting of filesystems in Linux, including practical examples and configurations for both Ubuntu/Debian and Enterprise Linux systems. Understanding these concepts and commands is crucial for effectively managing Linux filesystems, especially for the LPIC-1 certification exam.