Mounting a Filesystem Manually
First, consider a temporary mount directory. In this example, we will mount an XFS filesystem (created in a previous lesson) located on/dev/vdb1 at the directory /mnt.
Ensure that the directory exists and is empty before mounting the filesystem.
lsblk command:
umount command (note the spelling without the “n”):
lsblk will show that /mnt is empty.
Automatic Mounting with fstab
Some filesystems mount automatically at boot time. For instance,/dev/vda2 is typically mounted to /boot based on system configuration. To automate the mounting of additional filesystems such as the XFS filesystem on /dev/vdb1, you need to add an entry to the /etc/fstab file.
Understanding the fstab File Format
The/etc/fstab file uses six fields for each filesystem entry:
- Block Device: The partition (e.g.,
/dev/vdb1). - Mount Point: The directory to attach the filesystem (e.g.,
/mybackups). - Filesystem Type: The type of filesystem (e.g.,
xfsorext4). - Mount Options: Commonly set to
defaultsbut can be customized. - Dump: Typically set to
0to disable dump backups. - Pass: Determines the order for filesystem checks at boot (usually
1for the root and2for others;0disables checks).
Use a text editor like Vim to modify the
/etc/fstab file. Always back up this file before making changes./mybackups, follow these steps:
-
Create the mount point directory:
-
Edit the
/etc/fstabfile: -
Add the following lines to the file:
/dev/vdb1 will be mounted automatically, and previously created files (for example, testfile) will become visible:
Configuring a Swap Partition
In a previous lesson, you created a swap partition at/dev/vdb3. To enable the swap partition automatically at boot, add the following line to the /etc/fstab file:
- The second field is set to
nonesince swap space does not require a mount point. - The third field specifies the type as
swap. - Both the dump and pass fields are set to
0because swap space is not backed up or checked during boot.
Using UUIDs for Reliable Mounting
Sometimes,/etc/fstab entries reference devices by their UUID (Universally Unique Identifier) rather than device names. For example, instead of using /dev/vda2, an entry might use a UUID from /dev/disk/by-uuid/. The major advantage of using UUIDs is that they remain constant even if the device names change (for instance, due to varying connection orders).
To check the UUID of a block device, execute: