blkidShow filesystem type, UUID and label of devices
blkid identifies what is on a block device: filesystem type, UUID, label, and partition UUIDs. It's the standard way to get the UUID for /etc/fstab and to check, in a script, whether a disk is still empty.
blkid [OPTIONS] [DEVICE...]You want the type, UUID and label of every filesystem on the instance in one go.
sudoblkid probes the raw device; without root it can only show possibly stale cached data.
libblkid reads small regions of the device and looks for magic numbers: the ext4 superblock magic 0xEF53 at byte 1080, XFS's 'XFSB' at offset 0, swap's signature at the end of the first page, LUKS, LVM, RAID and partition-table headers. When it recognises one it parses the superblock for the UUID, label, block size and version. Results are cached in /run/blkid/blkid.tab; as root, blkid re-validates them, while a normal user only gets the cache. udev runs the same probe when a device appears and stores the results, which is where lsblk -f and the /dev/disk/by-uuid and by-label symlinks come from. UUID is the filesystem's own ID (changes with mkfs); PARTUUID belongs to the GPT partition entry and survives reformatting. If no signature is found blkid prints nothing and exits with status 2.
-s TAGShow only this tag: UUID, TYPE, LABEL, PARTUUID, BLOCK_SIZE-o valuePrint only values (one per line)-o exportPrint KEY=value lines you can eval or source in shell-o full / listDefault NAME: KEY="value" format / a table-L LABELPrint the device that has this label-U UUIDPrint the device that has this UUID-t NAME=valueList devices matching a tag, e.g. -t TYPE=xfs-pLow-level probe, bypassing the cache (shows more detail)-c /dev/nullIgnore the cache fileRunning blkid without sudo and trusting the resultAs a normal user blkid only reads its cache, which can be stale or empty for new devices.
sudo blkid, or lsblk -f which reads udev's dataUsing PARTUUID and UUID interchangeablyUUID belongs to the filesystem and changes when you run mkfs; PARTUUID belongs to the partition table entry and doesn't.
Use UUID= in fstab for filesystems; PARTUUID= mainly for kernel root= parametersCloning a disk or volume and mounting both copies on one hostBoth have the same UUID: mount by UUID becomes ambiguous and XFS refuses the second mount.
Give the copy a new UUID: tune2fs -U random /dev/X (ext4) or xfs_admin -U generate /dev/X (xfs)Try these on a Linux machine of your own. Each task has a hint and a solution.
Create an ext4 image file labelled 'lab' and print only its UUID.
Show lab.img's tags as shell variables, then load them and echo the type.
Check whether an empty file has any filesystem signature, using only the exit code.
blkidShow filesystem type, UUID and label of devices
blkid identifies what is on a block device: filesystem type, UUID, label, and partition UUIDs. It's the standard way to get the UUID for /etc/fstab and to check, in a script, whether a disk is still empty.
blkid [OPTIONS] [DEVICE...]You want the type, UUID and label of every filesystem on the instance in one go.
sudoblkid probes the raw device; without root it can only show possibly stale cached data.
libblkid reads small regions of the device and looks for magic numbers: the ext4 superblock magic 0xEF53 at byte 1080, XFS's 'XFSB' at offset 0, swap's signature at the end of the first page, LUKS, LVM, RAID and partition-table headers. When it recognises one it parses the superblock for the UUID, label, block size and version. Results are cached in /run/blkid/blkid.tab; as root, blkid re-validates them, while a normal user only gets the cache. udev runs the same probe when a device appears and stores the results, which is where lsblk -f and the /dev/disk/by-uuid and by-label symlinks come from. UUID is the filesystem's own ID (changes with mkfs); PARTUUID belongs to the GPT partition entry and survives reformatting. If no signature is found blkid prints nothing and exits with status 2.
-s TAGShow only this tag: UUID, TYPE, LABEL, PARTUUID, BLOCK_SIZE-o valuePrint only values (one per line)-o exportPrint KEY=value lines you can eval or source in shell-o full / listDefault NAME: KEY="value" format / a table-L LABELPrint the device that has this label-U UUIDPrint the device that has this UUID-t NAME=valueList devices matching a tag, e.g. -t TYPE=xfs-pLow-level probe, bypassing the cache (shows more detail)-c /dev/nullIgnore the cache fileRunning blkid without sudo and trusting the resultAs a normal user blkid only reads its cache, which can be stale or empty for new devices.
sudo blkid, or lsblk -f which reads udev's dataUsing PARTUUID and UUID interchangeablyUUID belongs to the filesystem and changes when you run mkfs; PARTUUID belongs to the partition table entry and doesn't.
Use UUID= in fstab for filesystems; PARTUUID= mainly for kernel root= parametersCloning a disk or volume and mounting both copies on one hostBoth have the same UUID: mount by UUID becomes ambiguous and XFS refuses the second mount.
Give the copy a new UUID: tune2fs -U random /dev/X (ext4) or xfs_admin -U generate /dev/X (xfs)Try these on a Linux machine of your own. Each task has a hint and a solution.
Create an ext4 image file labelled 'lab' and print only its UUID.
Show lab.img's tags as shell variables, then load them and echo the type.
Check whether an empty file has any filesystem signature, using only the exit code.