Skip to content

Instantly share code, notes, and snippets.

@cu
Last active February 25, 2025 13:43
Show Gist options
  • Save cu/f6c40542e680067ad7573704a6af2dbf to your computer and use it in GitHub Desktop.
Save cu/f6c40542e680067ad7573704a6af2dbf to your computer and use it in GitHub Desktop.
Linux: Mounting a filesystem with a UUID/PARTUUID

To get the UUID of a block device, use blkid:

$ blkid /dev/sdb1
/dev/sdb1: UUID="1c46a3c1-cbe7-4bb6-a412-445f317e2b5d" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="7f943a21-be92-304f-8bae-45aa7c4b0c78"

There are typically two UUIDs given, UUID and PARTUUID. UUID is a property of the filesystem, while PARTUUID is a property of the GPT partition table. In a lot of cases, you can use either/or but keep in mind your future use cases before settling on one or the other. For example:

  • If you might be cloning a filesystem on the same host, this will result in a duplicate UUID but not a duplicate PARTUUID. If there are two filesystems with the same UUID present on the system, Linux will refuse to guess which one you mean.
  • If you will be moving a filesystem (but not the whole disk) from one machine to another, the UUID will move with the filesystem, not the PARTUUID.
  • If you're not using a partition table on the block device, then there is no PARTUUID, just a UUID.

If it doesn't matter, UUID is more common. Paste the UUID into the first field of /etc/fstab, with or without quotes doesn't seem to matter:

UUID="1c46a3c1-cbe7-4bb6-a412-445f317e2b5d" /data xfs defaults 0 0

Reload systemd:

$ systemctl daemon-reload

Create your mount point, optionally make it immutable to prevent writing to it while the filesystem is unmounted, and mount it:

$ mkdir /data
$ chattr +i /data
$ mount /data

The mount command generally prints the same generic and ambiguous error message for any errors encountered while mounting a filesystem, so for details on what went wrong, check the output of dmesg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment