Using the blkid Command
blkid
command allows you to display information about available block devices. To do so, type the following at a shell prompt as root
:blkid
blkid
command displays available attributes such as its universally unique identifier(UUID
), file system type (TYPE
), or volume label (LABEL
). For example:~]# blkid
/dev/vda1: UUID="4ea24c68-ab10-47d4-8a6b-b8d3a002acba" TYPE="ext4"
/dev/vda2: UUID="iJ9YwJ-leFf-A1zb-VVaK-H9t1-raLW-HoqlUG" TYPE="LVM2_member"
/dev/mapper/vg_fedora-lv_swap: UUID="d6d755bc-3e3e-4e8f-9bb5-a5e7f4d86ffd" TYPE="swap"
/dev/mapper/vg_fedora-lv_root: LABEL="_Fedora-17-x86_6" UUID="77ba9149-751a-48e0-974f-ad94911734b9" TYPE="ext4"
lsblk
command lists all available block devices. To display information about a particular device only, specify the device name on the command line:blkid
device_name
/dev/vda1
, type:~]# blkid /dev/vda1
/dev/vda1: UUID="4ea24c68-ab10-47d4-8a6b-b8d3a002acba" TYPE="ext4"
-p
and -o udev
command line options to obtain more detailed information. Note that root
privileges are required to run this command:blkid
-po
udev
device_name
# blkid -po udev /dev/vda1
ID_FS_UUID=4ea24c68-ab10-47d4-8a6b-b8d3a002acba
ID_FS_UUID_ENC=4ea24c68-ab10-47d4-8a6b-b8d3a002acba
ID_FS_VERSION=1.0
ID_FS_TYPE=ext4
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_TYPE=0x83
ID_PART_ENTRY_FLAGS=0x80
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SIZE=1024000
ID_PART_ENTRY_DISK=252:0
blkid -L
device fs_type label mount point UUID
-------------------------------------------------------------------------------
/dev/sda1 ext3 / 727cac18-044b-4504-87f1-a5aefa774bda
/dev/sdc ext3 /home 467c4aa9-963d-4467-8cd0-d58caaacaff4
UUID and Partitions
Linux’s ext2/ext3 filesystem uses UUID to identify partitions.
UUID benefits
As a sesonded UNIX admin I have to deal with various data storage technologies such as SAN, iSCSI, DAS, scsi disks volumes. Sometime you may need to move storage from one device to another and updating /etc/fstab can be pain in a$$. With UUID Linux kernel should automatically find and map (read as mount to exact location) volumes to storage device. This saves lots of time and avoid /etc/fstab breaks.
However, UUID may be not very useful for single desktop computer at home as you do not have enterprise grade storage and requirements.
How do I find out UUID for /dev/sdb2?
To probe filesystem type and read label and uuid for /dev/sdb2 (or any other device) use vol_id command:
# vol_id --uuid {/dev/device}
# vol_id --uuid /dev/sdb2
$ sudo vol_id --uuid /dev/sdb2
Sample output:
41c22818-fbad-4da6-8196-c816df0b7aa8
List all UUIDs
Use blkid command-line utility to locate/print block device attributes:
$ sudo blkid
Sample output:
/dev/sda1: TYPE="ntfs" UUID="A0F0582EF0580CC2" /dev/sda2: UUID="8c2da865-13f4-47a2-9c92-2f31738469e8" SEC_TYPE="ext2" TYPE="ext3" /dev/sda3: TYPE="swap" UUID="5641913f-9bcc-4d8a-8bcb-ddfc3159e70f" /dev/sda5: UUID="FAB008D6B0089AF1" TYPE="ntfs" /dev/sdb1: UUID="32c61b65-f2f8-4041-a5d5-3d5ef4182723" SEC_TYPE="ext2" TYPE="ext3" /dev/sdb2: UUID="41c22818-fbad-4da6-8196-c816df0b7aa8" SEC_TYPE="ext2" TYPE="ext3"
How do I use UUID to update /etc/fstab file?
Simply use following syntax:
UUID={YOUR-UID} {/path/to/mount/point} {file-system-type} defaults,errors=remount-ro 0 1
Open /etc/fstab:
$ sudo vi /etc/fstab
Append line as follows:
UUID=41c22818-fbad-4da6-8196-c816df0b7aa8 /disk2p2 ext3 defaults,errors=remount-ro 0 1
Save and close the file. To mount new partition immediately using /etc/fstab type:
$ sudo mount -a
Example /etc/fstab entries:
# device-spec mount-point fs-type options dump pass LABEL=/ / ext4 defaults 1 1 /dev/sda6 none swap defaults 0 0 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 # Removable media /dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,ro 0 0 # NTFS Windows 7 partition /dev/sda1 /mnt/Windows ntfs-3g quiet,defaults,locale=en_US.utf8,umask=0,noexec 0 0 # Partition shared by Windows and Linux /dev/sda7 /mnt/shared vfat umask=000 0 0 # mounting tmpfs tmpfs /mnt/tmpfschk tmpfs size=100m 0 0 # mounting cifs //pingu/ashare /store/pingu cifs credentials=/root/smbpass.txt 0 0 # mounting NFS pingu:/store /store nfs rw 0 0