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.
Examples:
- 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).
Examples:
- list all block devices:
[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).
Examples:
- list all block devices:
[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