LinuxMedium

How to Configure UUID-based Mounting in fstab on Linux

In this guide, you'll learn to use unique identifiers (UUIDs) instead of device names in the fstab file to guarantee disk mounting during Linux boot, even if device names change.

Updated at February 15, 2026
15-30 min
Medium
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 11+CentOS 7+Fedora 35+Arch Linux

Introduction / Why This Is Needed

The /etc/fstab (file systems table) file is a central configuration file in Linux that defines how and where disks and partitions should be mounted at boot time. By default, it often uses device names like /dev/sda1 or /dev/nvme0n1p1.

The Problem: These names are not stable. For example, if you add a new disk, the detection order may change, and the old /dev/sda1 might become /dev/sdb1. This will cause the system to fail to mount the partition at the path specified in fstab, leading to boot errors or inability to access data.

The Solution: Use UUID (Universally Unique Identifier)—a unique identifier generated when the file system is created and remains unchanged regardless of disk detection order. In this guide, we will break down in detail how to replace device names with UUIDs in fstab to make disk mounting reliable and portable.

Requirements / Preparation

Before you begin, ensure you have:

  1. Access to a terminal with superuser (root) privileges or the ability to run commands via sudo.
  2. Knowledge of the specific disk/partition you want to configure for mounting (e.g., a second hard drive, a data partition, a swap partition).
  3. A backup of important data (just in case, although correct fstab editing is safe).
  4. The current working /etc/fstab file. It is recommended to back it up before editing:
    sudo cp /etc/fstab /etc/fstab.backup.$(date +%Y%m%d)
    

Step-by-Step Instructions

Step 1: Determine the UUID of the Target Disk or Partition

First, you need to find the unique identifier (UUID) of the target partition. There are two main methods:

Method A: Using blkid (recommended) The blkid command outputs information about all block devices and their file systems.

sudo blkid

Example output:

/dev/sda1: UUID="a1b2c3d4-e5f6-7890-abcd-ef1234567890" TYPE="ext4" PARTUUID="..."
/dev/sdb1: UUID="b2c3d4e5-f6a7-8901-bcde-f23456789012" TYPE="ntfs"
/dev/nvme0n1p1: UUID="c3d4e5f6-a7b8-9012-cdef-345678901234" TYPE="vfat" PARTLABEL="EFI system partition"

Find the partition you need in the list (by size, file system type, or previous device name) and copy the value of the UUID field (do not include the quotes).

Method B: Using lsblk with file system output

lsblk -f

This command provides a more tree-like view, which can be convenient when dealing with many partitions.

💡 Tip: You can find the UUID for a swap partition using the same blkid command. It will have TYPE="swap".

Step 2: Edit the /etc/fstab File

Now open the /etc/fstab file in a text editor with superuser privileges.

sudo nano /etc/fstab

Or, if you prefer vi/vim:

sudo vi /etc/fstab

Inside the file, you will see lines, each describing one mountable resource. An example line with a device name:

/dev/sda1  /mnt/data  ext4  defaults  0  2

Your task: Replace /dev/sda1 with UUID=<your_uuid>. Use the UUID you obtained in Step 1.

Example transformation: Before:

/dev/sdb1  /home  ext4  defaults,noatime  0  2

After (UUID taken from the blkid output example above for /dev/sdb1):

UUID=b2c3d4e5-f6a7-8901-bcde-f23456789012  /home  ext4  defaults,noatime  0  2

Key points when editing:

  • The UUID field must be specified exactly as UUID=<value>, without quotes.
  • The order of fields is important: UUID (or device) -> mount point -> FS type -> mount options -> dump -> pass.
  • For a swap partition, the FS type is swap, options are usually sw, and the dump and pass fields are 0 0:
    UUID=<swap_uuid>  none  swap  sw  0  0
    
  • If you are adding a new entry, ensure the mount point (e.g., /mnt/backup) already exists on the file system. If not, create it: sudo mkdir -p /mnt/backup.

⚠️ Important: Do not delete or comment out old entries until you are sure the new UUID-based one works. You can temporarily comment out the old line by putting a # at the beginning.

Step 3: Check Syntax and Apply Changes

Do not reboot immediately! First, verify the configuration.

  1. Save the file in your editor (in nano this is Ctrl+O, Enter, then Ctrl+X; in vi it's :wq).
  2. Run a test check of the syntax and attempt to mount all partitions from fstab:
    sudo mount -a
    
    • If the command runs without output and without errors – congratulations, the fstab configuration is syntactically correct, and the system was able to mount all specified partitions.
    • If errors appear (e.g., mount: /mnt/data: special device UUID=... does not exist.), then:
      • The UUID is incorrect (check again via blkid).
      • The file system on that partition is corrupted (may require fsck).
      • The mount point does not exist.
      • You are trying to mount a partition that is already mounted elsewhere (use findmnt to search).
  3. Additional check: See which partitions are currently mounted and with what parameters:
    findmnt -l
    

    Or
    mount | grep /mnt/your_point
    

    Ensure your partition is mounted at the correct point with the right FS type.
  4. If everything is good, you can reboot the system (sudo reboot) to ensure partitions mount correctly during boot. After rebooting, check findmnt again.

Verification

After completing all steps and rebooting (if you did), verify that:

  1. The system booted without mount-related errors (did not drop to emergency mode).
  2. The mount point (e.g., /home or /mnt/data) is accessible and contains your files.
  3. The command lsblk -f shows the partition mounted in the correct location.
  4. For swap: sudo swapon --show should display your swap partition.

Potential Issues

  • Error: "special device UUID=... does not exist"
    • Cause: Incorrect UUID or the partition does not exist (e.g., an external disk is unplugged).
    • Solution: Re-check the UUID via sudo blkid. Ensure the disk is connected and visible to the system.
  • Error: "wrong fs type, bad option, bad superblock"
    • Cause: File system corruption, incorrectly specified FS type (e.g., you specified ext4 but it's actually ntfs), or invalid mount options.
    • Solution: Check the FS type in the blkid output. To check/repair the file system (for ext4), you may need sudo fsck /dev/sdXY (but only for unmounted partitions!).
  • System fails to boot, hangs at mount stage
    • Cause: An error in fstab for the root (/) partition or an important system partition (e.g., /boot).
    • Solution: Boot into recovery mode via GRUB. Open the root file system in read-write mode, edit /etc/fstab, either reverting to the old device name entry or fixing the UUID. Use your /etc/fstab.backup.* backup.
  • Partition mounts but with wrong permissions
    • Cause: The issue is not the UUID but the mount options (e.g., uid, gid, umask for FAT/NTFS) or permissions on the mount point directory.
    • Solution: Adjust the mount options in fstab accordingly or fix the directory permissions (sudo chown).
  • UUID for a disk is not shown in blkid
    • Cause: There is no file system on the disk or it is not recognized.
    • Solution: Ensure the disk is formatted. If not – format it (first confirm data is not needed). After formatting, the UUID will be created automatically.

⚠️ Important: Changing the file system's UUID is only possible by recreating it (e.g., via mkfs). The partition itself has its own PARTUUID, which can also be used in fstab, but this is a less common practice. In this guide, we work with the file system's UUID.


After successfully configuring mounting by UUID, your Linux server or workstation will become significantly more resilient to hardware changes (connecting new disks, replacing old ones). This practice is the gold standard for Linux system administration.

If you are working with network file systems (NFS, SMB/CIFS), network paths and parameters are used instead of UUIDs, but the principle of configuration stability remains the same. To learn about their settings, refer to our guides on NFS and Samba.

F.A.Q.

Why is it better to use UUID instead of /dev/sdX in fstab?
What to do if a disk's UUID changed after recreating the filesystem?
Can UUID be used for swap partitions?
How to verify that fstab with UUID works correctly without rebooting the system?

Hints

Identify the UUID of the target disk or partition
Edit the /etc/fstab file
Check syntax and apply changes
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community