Skip to content

Auto-Mounting Hard Drives on Ubuntu

Checking Available Drives

  1. List all partitions:
    lsblk
    
  2. Get partition UUIDs:
    blkid
    

Editing fstab for Auto-Mounting

  1. Backup fstab before modification:
    sudo cp /etc/fstab /etc/fstab.bak
    
  2. Open the fstab file:
    sudo vim /etc/fstab
    
  3. Add an entry in the following format:
    UUID=your-uuid  /mnt/your-mount-point  ext4  defaults,nofail  0  2
    
  4. Replace your-uuid with the actual UUID.
  5. Ensure /mnt/your-mount-point exists and is an empty directory.
  6. The nofail option allows the system to boot even if the drive is missing.

Applying Changes

Run:

sudo mount -a

Verifying the Mount

Check if the disk is mounted correctly:

df -h

Other issues

Why Use UUID Instead of Device Names?

A UUID (Universally Unique Identifier) is a persistent identifier for a disk partition. Unlike device names such as /dev/sda1, which can change due to hardware modifications, BIOS settings, or disk rearrangement, UUIDs remain consistent. Using UUIDs in /etc/fstab enhances system stability and prevents boot failures caused by disk name changes.

Identifier Type Behavior on System Changes Reliability
/dev/sdX (Device Name) May change with new hardware, BIOS updates, or disk reordering Unstable
UUID Remains constant across reboots and hardware changes Stable ✅

Important Considerations

  • Ensure mount points exist before adding entries in /etc/fstab.
  • Use nofail for external or secondary drives to avoid boot failures.
  • Improper fstab configurations can prevent system startup. If this happens on a cloud server, you may need to recover from an image backup or rescue mode.

Comments