Linux devices by uuid

How to find Linux filesystem by Label or UUID using findfs, lsblk, blkid

Linux includes by default a bunch of useful filesystem tools that can be used to locate filesystems or partitions with specified tags or display the whole list of block devices along with their labels, universally unique identifiers (UUIDs) or default mount points.

Below we present common tools to locate filesystem, block device or list all block devices in Linux.

1. findfs – used to search the block devices in the system for a filesystem or partition with specified tag, supported tags: LABEL, UUID, PARTUUID, PARTLABEL.

    search block devices by filesystem label:

[root@tuxfixer ~]# findfs LABEL=swap /dev/sdb4
[root@tuxfixer ~]# findfs UUID=ae344cef-02bd-41a0-9ae5-a65ca9b473a8 /dev/sda1
[root@tuxfixer ~]# findfs PARTUUID=00006b3e-03 /dev/sdb3

2. lsblk – displays information about all or specified block devices (reads the sysfs filesystem and udev db to gather information).

[root@tuxfixer ~]# lsblk -a NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk └─sda1 8:1 0 931.5G 0 part /var/lib/libvirt/images sdb 8:16 0 465.8G 0 disk ├─sdb1 8:17 0 61.5G 0 part / ├─sdb2 8:18 0 147.3G 0 part ├─sdb3 8:19 0 253.1G 0 part /home └─sdb4 8:20 0 3.9G 0 part [SWAP] sr0 11:0 1 1024M 0 rom 
[root@tuxfixer ~]# lsblk -f NAME FSTYPE LABEL UUID MOUNTPOINT sda └─sda1 ext4 kvm ae344cef-02bd-41a0-9ae5-a65ca9b473a8 /var/lib/libvirt/images sdb ├─sdb1 ext4 linux ef15b875-ee2a-4def-8e16-a3ccdb41ff36 / ├─sdb2 ntfs win7 56FCCA5FFCCA394F ├─sdb3 ext4 home 5279bdb7-aecb-4bb2-9a54-d7d042f70e6c /home └─sdb4 swap swap 087470ac-4819-44cb-81df-9980fd601a73 [SWAP] sr0 
[root@tuxfixer ~]# lsblk -r NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk sda1 8:1 0 931.5G 0 part /var/lib/libvirt/images sdb 8:16 0 465.8G 0 disk sdb1 8:17 0 61.5G 0 part / sdb2 8:18 0 147.3G 0 part sdb3 8:19 0 253.1G 0 part /home sdb4 8:20 0 3.9G 0 part [SWAP] sr0 11:0 1 1024M 0 rom
[root@tuxfixer ~]# lsblk -t NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME sda 0 512 0 512 512 1 cfq 128 128 0B └─sda1 0 512 0 512 512 1 cfq 128 128 0B sdb 0 4096 0 4096 512 1 cfq 128 128 0B ├─sdb1 0 4096 0 4096 512 1 cfq 128 128 0B ├─sdb2 0 4096 0 4096 512 1 cfq 128 128 0B ├─sdb3 0 4096 0 4096 512 1 cfq 128 128 0B └─sdb4 0 4096 0 4096 512 1 cfq 128 128 0B sr0 0 512 0 512 512 1 cfq 128 128 0B
[root@tuxfixer ~]# lsblk -o NAME,LABEL NAME LABEL sda └─sda1 kvm sdb ├─sdb1 linux ├─sdb2 win7 ├─sdb3 home └─sdb4 swap sr0

3. blkid – locates or displays block device attributes (similar to lsblk, but provides less information and worse formatting).

[root@tuxfixer ~]# blkid /dev/sda1: LABEL="kvm" UUID="ae344cef-02bd-41a0-9ae5-a65ca9b473a8" TYPE="ext4" PARTUUID="5802aed2-01" /dev/sdb1: LABEL="linux" UUID="ef15b875-ee2a-4def-8e16-a3ccdb41ff36" TYPE="ext4" PARTUUID="00006b3e-01" /dev/sdb2: LABEL="win7" UUID="56FCCA5FFCCA394F" TYPE="ntfs" PARTUUID="00006b3e-02" /dev/sdb3: LABEL="home" UUID="5279bdb7-aecb-4bb2-9a54-d7d042f70e6c" TYPE="ext4" PARTUUID="00006b3e-03" /dev/sdb4: LABEL="swap" UUID="087470ac-4819-44cb-81df-9980fd601a73" TYPE="swap" PARTUUID="00006b3e-04"
[root@tuxfixer ~]# blkid -L win7 /dev/sdb2
[root@tuxfixer ~]# blkid -i /dev/sdb1 DEVNAME=/dev/sdb1 MINIMUM_IO_SIZE=4096 PHYSICAL_SECTOR_SIZE=4096 LOGICAL_SECTOR_SIZE=512
[root@tuxfixer ~]# blkid -o value kvm ae344cef-02bd-41a0-9ae5-a65ca9b473a8 ext4 5802aed2-01 linux ef15b875-ee2a-4def-8e16-a3ccdb41ff36 ext4 00006b3e-01 win7 56FCCA5FFCCA394F ntfs 00006b3e-02 home 5279bdb7-aecb-4bb2-9a54-d7d042f70e6c ext4 00006b3e-03 swap 087470ac-4819-44cb-81df-9980fd601a73 swap 00006b3e-04

Источник

Читайте также:  Arch linux double commander

UsingUUID

IconsPage/hdd.png

Linux prefers to use UUID (Universally Unique Identifier), LABEL, or symlinks to identify media storage devices on a system. Using device assignments (like /dev/hd*# or /dev/sd*#) is not preferred since these can change between system boots:

  • all filesystems should be specified by UUID= or LABEL= for each partition.
  • all physical devices should be specified by a symlink, like /dev/cdrom for a cd drive and /dev/disk/by-id/. for each physical hard drive.

IconsPage/editor.png

The files for which UUID is most critical:

  • /boot/grub/menu.lst
  • /etc/fstab
  • /etc/initramfs-tools/conf.d/resume

This page uses the terminal a lot, so if you are new to this, see UsingTheTerminal.

The Fstab page provides some excellent examples of UUID in action.

Finding UUIDs

IconsPage/note.png

UUIDs can be determined using the blkid command. This command lists UUIDs for all attached devices (mounted or not).

IconsPage/example.png

Here are examples (your output will be different, but similarly formatted). The command:

/dev/sda1: TYPE="ntfs" UUID="72C0DE8EC0DE57C5" LABEL="windows" /dev/sda2: UUID="30fcb748-ad1e-4228-af2f-951e8e7b56df" SEC_TYPE="ext2" TYPE="ext3" /dev/sda5: TYPE="swap" UUID="8c4e69f8-5074-42c0-8134-0b2429c4c02c" /dev/sdb1: SEC_TYPE="msdos" UUID="4848-E35A" TYPE="vfat"

Alternatively you can list them from their listing in your root filesystem:

total 0 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 30fcb748-ad1e-4228-af2f- 951e8e7b56df -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-07 16:51 4848-E35A -> ../../sdb1 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 72C0DE8EC0DE57C5 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-04 03:10 8c4e69f8-5074-42c0-8134-0b2429c4c02c -> ../../sda5

Using LABEL

IconsPage/note.png

Labels can be very useful for external media, like flash drives and USB hard drives since these are generally automounted by hal (Hardware Abstraction Layer). If a device has a label, it will be mounted at the /media/ location and appear with the label on the desktop.

IconsPage/tip.png

For help with labeling devices, see RenameUSBDrive.

Symlinks (symbolic links) are used to make it easier to identify a device. For example /dev/cdrom can link to /dev/scd0. These are normally created by udev which is the device manager program used in the Linux 2.6 kernel series. We will not cover creating your own symlinks here (may be added later).

IconsPage/example.png

Other examples of symlinks include /dev/floppy to /dev/fd0 or /dev/dvd to /dev/scd1 .

You can view the linked device on a symlink with the ls command, like so:

lrwxrwxrwx 1 root root 4 2008-06-22 17:31 /dev/cdrom -> scd0

This tell us that /dev/cdrom is a symlink to the device /dev/scd0 .

To view the physical device identifiers (like for a hard drive, not to be confused with a disk's partitions), the command:

total 0 lrwxrwxrwx 1 root root 9 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 ata-Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5 lrwxrwxrwx 1 root root 9 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb lrwxrwxrwx 1 root root 10 2008-06-22 17:31 ata-LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1 lrwxrwxrwx 1 root root 9 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G -> ../../sda lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part1 -> ../../sda1 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part2 -> ../../sda2 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part3 -> ../../sda3 lrwxrwxrwx 1 root root 10 2008-06-22 10:30 scsi-1ATA_Hitachi_HTS541080G9AT00_MPB4PAX6H6B68G-part5 -> ../../sda5 lrwxrwxrwx 1 root root 9 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034 -> ../../sdb lrwxrwxrwx 1 root root 10 2008-06-22 17:31 scsi-1ATA_LEXAR_ATA_FLASH_13523623189499090034-part1 -> ../../sdb1

Note that each partition (called part#) identifies with their parent device - this is because they exist on that physical piece of hardware. You will also notice that the drives and partitions appear twice, the first time as ata and the second time as scsi. I am unclear as to why this is, but I believe it is related to IDE hard drives being identified to the system as SCSI drives (because of ide-scsi emulation?).

Other Resources

IconsPage/resources.png

Here are some other useful and related pages.

  • Fstab
  • RenameUSBDrive - help with adding LABELs to partitions
  • LinuxFilesystemsExplained
  • Editing FAT32 Partition Labels using mtools.

UsingUUID (последним исправлял пользователь knome 2017-02-17 11:14:17)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Оцените статью
Adblock
detector