In the Armbian system, mounting disks is a common operation, but traditional mounting methods (such as directly modifying /etc/fstab) carry certain risks. If a disk fails to mount properly, it may lead to system failure or even damage. To avoid this situation, this article will introduce a safer and more stable mounting method: using UUID and systemd mount unit files. This method is not only precise but also ensures that the system can still boot normally even if the disk fails to mount.
Why is using UUID for mounting safer?
- Precision: UUID (Universally Unique Identifier) is a unique identifier for disk partitions that does not change with device names (such as
/dev/sda1). Using UUID for mounting can prevent mount failures caused by changes in device names. - Stability: Traditional mounting methods rely on device names, which may change due to system boot order or other factors. UUIDs are always unique, ensuring stable mounting.
- Safety: Using systemd mount unit files can prevent system crashes in case of mount failures. With the
nofailoption, the system can still boot normally even if the disk fails to mount.
Tutorial: Using UUID and systemd mount unit files
Step 1: Check Disk Information and Obtain UUID
-
Open a terminal and enter the following command to view available storage devices and partition information:
lsblk -
Find the disk partition you want to mount (for example,
/dev/sda1), and then use the following command to obtain its UUID and filesystem type:sudo blkid /dev/sda1Example output:
/dev/sda1: UUID="40de5d2b-7e3e-624d-8280-9cecbcb97894" TYPE="ext4"Note down the
UUIDandTYPE, as they will be used in subsequent steps.
Step 2: Create a Mount Point
-
Create a mount point in the
/mntdirectory (for example,/mnt/disk):sudo mkdir -p /mnt/disk
Step 3: Create a systemd Mount Unit File
-
Create a new systemd mount unit file with
sudoprivileges:sudo nano /etc/systemd/system/mnt-disk.mount -
Paste the following content into the file, making sure to replace
UUIDandTypewith your disk information:[Unit] Description=Mount Disk with UUID Requires=local-fs.target After=local-fs.target [Mount] What=/dev/disk/by-uuid/40de5d2b-7e3e-624d-8280-9cecbcb97894 Where=/mnt/disk Type=ext4 Options=defaults,nofail [Install] WantedBy=multi-user.target -
Save and exit the editor (in
nano, pressCtrl + X, then pressYto confirm saving).
Step 4: Enable and Start the Mount Unit
-
Use the following command to enable the mount unit so that it automatically mounts at system startup:
sudo systemctl enable mnt-disk.mount -
If you want to mount the disk immediately without rebooting the system, you can run:
sudo systemctl start mnt-disk.mount
Step 5: Verify the Mount
-
Use the following command to check if the mount was successful:
mount | grep /mnt/diskOr check the status of the systemd unit:
sudo systemctl status mnt-disk.mount -
If the mount was successful, you will see output similar to the following:
/dev/sda1 on /mnt/disk type ext4 (rw,relatime)
Step 6: Reboot the System (Optional)
To ensure the mount takes effect automatically at system startup, you can reboot the system:
sudo reboot
After rebooting, check if the disk is automatically mounted at /mnt/disk.
Other Considerations
- UUID Check: Ensure that the UUID you provided is correct. You can always use the
blkidcommand to view the UUID of the disk. - Filesystem Type: Ensure that
Type=ext4matches your disk’s filesystem type. If it is not ext4, please modify it according to your actual situation. - Mount Options: The
Options=defaults,nofailoption indicates that even if the disk does not exist, the system will not report an error. If you want the disk to be mandatory, you can remove thenofailoption.
Conclusion
By using UUID and systemd mount unit files, you can achieve a safer and more stable disk mounting process. This method not only avoids the risks associated with traditional mounting methods but also ensures that the system continues to operate normally even if the disk fails to mount. We hope this tutorial helps you better manage disk mounting in your Armbian system.