6 Linux lsblk command examples

6 Linux lsblk Command Examples

 

lsblk useful terminal command for analysis Linux storage devices.

lsblk – LiSt BLocK devices. Linux lsblk command lists information about all available or the specified block devices – disks. The lsblk command reads the sysfs filesystem and udev db to gather information. If the udev db is not available or lsblk is compiled without udev support than it tries to read LABELs, UUIDs and filesystem types from the block device. In this case root permissions are necessary.

The lsblk command prints all block devices (except RAM disks) in a tree-like format by default.

To get list off all available options use lsblk –help or man lsblk. Also full documentation available in LSBLK Linux man page.

 

1. Example output of lsblk command without any options :

$ lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 88.5M  1 loop /snap/core/7270
loop1                       7:1    0 88.7M  1 loop /snap/core/7396
sda                         8:0    0  7.3T  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    1G  0 part /boot
└─sda3                      8:3    0  7.3T  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0  7.3T  0 lvm  /
sdb                         8:16   0  7.3T  0 disk
└─sdb1                      8:17   0  7.3T  0 part
sr0                        11:0    1 1024M  0 rom

 

2. Same as previous command, but just list disks without tree-like formatting:

$ lsblk -l
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                   7:0    0 88.5M  1 loop /snap/core/7270
loop1                   7:1    0 88.7M  1 loop /snap/core/7396
sda                     8:0    0  7.3T  0 disk
sda1                    8:1    0    1M  0 part
sda2                    8:2    0    1G  0 part /boot
sda3                    8:3    0  7.3T  0 part
sdb                     8:16   0  7.3T  0 disk
sdb1                    8:17   0  7.3T  0 part
sr0                    11:0    1 1024M  0 rom
ubuntu--vg-ubuntu--lv 253:0    0  7.3T  0 lvm  /

 

3. This example will print the SIZE column in bytes rather than in a human-readable format:

$ lsblk -b
NAME            MAJ:MIN RM        SIZE RO TYPE MOUNTPOINT
sda               8:0    0 34359738368  0 disk
├─sda1            8:1    0  1073741824  0 part /boot
└─sda2            8:2    0 33284947968  0 part
  ├─centos-root 253:0    0 31130124288  0 lvm  /
  └─centos-swap 253:1    0  2147483648  0 lvm  [SWAP]
sr0              11:0    1   962592768  0 rom

 

4. Option -f or –fs will show info about filesystem:

$ lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda
├─sda1          xfs                         4cd404a1-275c-4614-870e-d2936c11ddd6   /boot
└─sda2          LVM2_member                 7BSlmC-9Q30-M68i-R9Os-oExP-wMky-nTd7fs
  ├─centos-root xfs                         dcb861b3-fdde-41d8-8c4b-f4859d400bac   /
  └─centos-swap swap                        25441b13-1886-4b47-b72a-e5d0c16982a7   [SWAP]
sr0             iso9660     CentOS 7 x86_64 2018-11-25-21-21-31-00

 

5. lsblk -d will not output holder devices or slaves. In my case, lsblk -d /dev/sdb prints information about the sdb device only:

$ lsblk -d /dev/sdb
NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb    8:16   0 233.8G  0 disk

 

6. In last example I want to show -D or –discard, which printing information about devices discarding capabilities:

$ lsblk --discard
NAME                              DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                                      0        0B       0B         0
├─sda1                                   0        0B       0B         0
├─sda2                                   0        0B       0B         0
└─sda3                                   0        0B       0B         0
  ├─pve-swap                             0        0B       0B         0
  ├─pve-root                             0        0B       0B         0
  ├─pve-data_tmeta                       0        0B       0B         0
  │ └─pve-data-tpool                     0        0B       0B         0
  │   ├─pve-data                         0        0B       0B         0
  │   ├─pve-vm--100--disk--0             0       64K      16G         0
  │   ├─pve-vm--101--disk--0             0       64K      16G         0
  │   └─pve-vm--100--state--fresh        0       64K      16G         0
  └─pve-data_tdata                       0        0B       0B         0
    └─pve-data-tpool                     0        0B       0B         0
      ├─pve-data                         0        0B       0B         0
      ├─pve-vm--100--disk--0             0       64K      16G         0
      ├─pve-vm--101--disk--0             0       64K      16G         0
      └─pve-vm--100--state--fresh        0       64K      16G         0
sdb                                      0        0B       0B         0
└─sdb1                                   0        0B       0B         0
sdc                                      0        0B       0B         0
└─sdc1                                   0        0B       0B         0
sdd                                      0        0B       0B         0
├─sdd1                                   0        0B       0B         0
└─sdd2                                   0        0B       0B         0
sr0                                      0        0B       0B         0

 
 


 

If you like what you are reading, please:

Buy me a coffeeBuy me a coffee

arstech

Leave a Reply