Armbian System Secure Disk Mounting Tutorial: Achieving Accurate and Stable Auto-Mounting with UUID

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?

  1. 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.
  2. 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.
  3. Safety: Using systemd mount unit files can prevent system crashes in case of mount failures. With the nofail option, 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

  1. Open a terminal and enter the following command to view available storage devices and partition information:

    lsblk
    
  2. 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/sda1
    

    Example output:

    /dev/sda1: UUID="40de5d2b-7e3e-624d-8280-9cecbcb97894" TYPE="ext4"
    

    Note down the UUID and TYPE, as they will be used in subsequent steps.

Step 2: Create a Mount Point

  1. Create a mount point in the /mnt directory (for example, /mnt/disk):

    sudo mkdir -p /mnt/disk
    

Step 3: Create a systemd Mount Unit File

  1. Create a new systemd mount unit file with sudo privileges:

    sudo nano /etc/systemd/system/mnt-disk.mount
    
  2. Paste the following content into the file, making sure to replace UUID and Type with 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
    
  3. Save and exit the editor (in nano, press Ctrl + X, then press Y to confirm saving).

Step 4: Enable and Start the Mount Unit

  1. Use the following command to enable the mount unit so that it automatically mounts at system startup:

    sudo systemctl enable mnt-disk.mount
    
  2. 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

  1. Use the following command to check if the mount was successful:

    mount | grep /mnt/disk
    

    Or check the status of the systemd unit:

    sudo systemctl status mnt-disk.mount
    
  2. 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 blkid command to view the UUID of the disk.
  • Filesystem Type: Ensure that Type=ext4 matches your disk’s filesystem type. If it is not ext4, please modify it according to your actual situation.
  • Mount Options: The Options=defaults,nofail option 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 the nofail option.

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.

Leave a Comment