Here, in this article, I will talk about how to mount disks and create fstab entries in Linux. We will explore step-by-step instructions to mount a disk using its UUID, create a mount point, and then add a corresponding entry in the /etc/fstab file for automounting. Additionally, we will delve into the concepts of relatime, atime, noatime, strictatime, and lazytime to help you understand their differences and applications. By the end of this guide, you'll be equipped with the knowledge to handle disk mounting and manage your filesystem more effectively.
Introduction
In the world of Linux, managing disks and their mount points is essential for efficient file storage and retrieval. Using Universally Unique Identifiers (UUIDs) to identify disks ensures reliability and stability, even when disk names may change. Moreover, automating disk mounting through the /etc/fstab file simplifies the process and enhances system usability. In this article, we will cover step-by-step instructions to mount a disk by its UUID and create an fstab entry. We will also explore the significance of various time settings like relatime, atime, noatime, strictatime, and lazytime, to optimize disk usage.
Step 1. Obtaining the File System Based UUID:
The first step is to identify the UUID of the disk you want to mount. To do this, open the terminal and use the following command:
ls -al /dev/disk/by-uuid
Output:
total 0
drwxr-xr-x 2 root root 160 Jul 20 17:35 .
drwxr-xr-x 9 root root 180 Jul 20 17:35 ..
lrwxrwxrwx 1 root root 15 Jul 20 17:35 00E8EAD5E8EAC7CC -> ../../nvme0n1p3
lrwxrwxrwx 1 root root 11 Jul 20 17:35 5627befe-b7a4-48c7-ae19-a71689a67d7e -> ../../loop0
lrwxrwxrwx 1 root root 15 Jul 20 17:35 B2E8-9A01 -> ../../nvme0n1p1
lrwxrwxrwx 1 root root 15 Jul 20 17:35 E4CA6C29CA6BF5E8 -> ../../nvme1n1p2
lrwxrwxrwx 1 root root 15 Jul 20 17:35 EAD2EB39D2EB08A1 -> ../../nvme0n1p4
lrwxrwxrwx 1 root root 15 Jul 20 17:35 fc986af0-b252-4c73-a921-a7cb75eb4c5f -> ../../nvme0n1p5
Use this along with lsblk
to find out your disk/partition.
Step 2. Creating a Mount Point:
Before mounting the disk, you need to create a directory that will act as the mount point. Use the following command to create a mount point named "crucial" in the /mnt directory:
mkdir /mnt/crucial
You can use any name instead of "crucial".
Step 3. Mounting the Disk using UUID:
To mount the disk using its UUID, employ the following command in the terminal:
sudo mount UUID=bd4da364-6f99-4859-8ca4-326c89e9b11f /mnt/crucial
Step 4. Creating an Fstab Entry:
To automate the mounting process at system startup, you can add an entry in the /etc/fstab file. Open the /etc/fstab file using a text editor, and add the following line at the end of the file:
UUID=bd4da364-6f99-4859-8ca4-326c89e9b11f /mnt/crucial ext4 rw,lazytime,strictatime,nofail 0 2
Remember to replace the UUID with the one specific to your disk. This entry specifies the filesystem type (ext4), mount options (rw,lazytime,strictatime,nofail), and other parameters.
Understanding the Fstab Entry:
-
UUID: The unique identifier of the disk partition.
-
/mnt/crucial: The mount point where the disk will be attached.
-
ext4: The file system type of the disk partition.
-
rw: Mount the disk as read-write.
-
lazytime: Delays the updating of inode access times to optimize disk performance.
-
strictatime: Access times are updated always. Use it with lazytime for disk performance.
-
nofail: The system will boot even if this disk fails to mount successfully.
-
0: Indicates that the dump utility will not back up the file system.
-
2: Specifies the order in which the fsck command checks file systems during boot.
More Information:
For more details on fstab entries, you can refer to the man 5 fstab
command in the terminal. Additionally, to gain further insights into fstab and its usage, you can visit the link - how to create fstab entry in linux.
Understanding relatime, atime, and More:
-
relatime: Relatime updates the access time only when it is earlier than the current modification time or change time of the file. This reduces disk I/O and enhances performance.
-
atime: Kernel's default time i.e. relatime.
-
noatime: Disables access time updates altogether, improving disk performance but preventing accurate access time information.
Note for NTFS in Dual Boot System:
If you have a dual boot system with both Windows and Linux, it's important to be aware of a potential issue related to Fast Reboot in Windows. Fast Reboot, also known as Fast Startup, uses hibernation to speed up the boot process. However, it may not shut down all disk properly, which can lead to problems when mounting NTFS partitions in Linux. To prevent data loss, Linux might mount these NTFS partitions in read-only mode.
To ensure a smoother experience when working with NTFS partitions in a dual boot setup, you can consider disabling Fast Reboot in Windows. For step-by-step instructions on how to disable Fast Startup, you can visit the link.
For Mounting NTFS file system
If you have a disk formatted with the NTFS file system that you want to mount in Linux, you can do so by adding an entry in the /etc/fstab file.
Use the following line in the /etc/fstab file to mount the Maxtor NTFS disk:
UUID=9674C20374C1E5D9 /mnt/Maxtor ntfs users,rw,uid=1000,gid=1000,async,auto,dmask=0000,fmask=0111,nofail 0 2
This entry includes specific mount options such as "users" (allowing ordinary users to mount the disk), "rw" (mounting the disk as read-write), "uid" and "gid" (setting the user and group ownership), "async" (enabling asynchronous I/O), "auto" (mounting the disk automatically at boot), "dmask" (setting directory permissions), "fmask" (setting file permissions), and "nofail" (allowing the system to boot even if the disk fails to mount).
Conclusion:
In this article, we have covered the step-by-step process of mounting disks using their UUIDs, creating mount points, and adding entries in the /etc/fstab file for automounting. We have also discussed the significance of various time settings to optimize disk usage. By following these guidelines, you can efficiently manage your disk storage, enhance system performance, and ensure a smooth computing experience in your Linux environment. Remember to refer to the provided links for further information on fstab entries and the various time settings for disk access. Happy disk management!