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
.