I need to list all block devices installed in my system. There is a command named lsblk to show all block devices.

[kni@hist ttyid:0 pią kwi 13 17:56:26 ~]$ lsblk 
sda                      8:0    0   16G  0 disk 
├─sda1                   8:1    0    1G  0 part /boot
└─sda2                   8:2    0 13,5G  0 part 
  ├─fedora_211829-root 253:0    0   10G  0 lvm  /
  ├─fedora_211829-swap 253:1    0  1,5G  0 lvm  [SWAP]
  └─fedora_211829-home 253:2    0    2G  0 lvm  /home
sr0                     11:0    1 55,3M  0 rom  /run/media/kni/VBox_GAs_5.2
[knis@hist ttyid:0 pią kwi 13 17:56:31 ~]$ 

This is the resault of lsblk command executed in my system. Is the sda disk the only one physical device in my system? Partitions and lvm are logical parts of the disk. Am I right?

Is there other way to print physical block devices?

  • sda and sr0 are the only physical block devices; sda1 and sda2 are indeed block devices, but they are logical and not physical. – DopeGhoti Apr 13 '18 at 16:04

Assuming you actually want to see physical devices, and not just all block devices:

My recommendation will then be:

lsblk -a -d -e 230


Let us review what these command line options do, from the man page:

       -a, --all
              Also list empty devices.  (By default they are skipped.)

Strangely, lsblk shows my laptop's DVD burner even when it is empty, without -a. But it doesn't seem to hurt anything to leave it present.

       -d, --nodeps
              Do not print holder  devices  or  slaves.   For  example,  lsblk
              --nodeps /dev/sda prints information about the sda device only.

This means we don't see partitions on a device, just the device itself.

       -e, --exclude list
              Exclude  the  devices  specified  by the comma-separated list of
              major  device  numbers.   Note  that  RAM  disks  (major=1)  are
              excluded  by  default.   The  filter is applied to the top-level
              devices only.

Finally, I use -e 230 to exclude ZFS zvols, which use this major number. They are entirely logical block devices, but the ZFS driver makes them appear in lsblk the same as physical disk devices. If you use ZFS, you can exclude zvols from display with -e 230.

[root@dalaran ~]# lsblk -a -d -e 230
sda       8:0    0 894.3G  0 disk 
sr0      11:0    1  1024M  0 rom  
nvme0n1 259:0    0   477G  0 disk 

I do not recommend using -S option, as this will cause NVMe devices to not be displayed.

There are several other options in the lsblk man page which allow for making the output more machine readable, in case you want to write a shell script. For instance -n and -o or -P.

  • Strictly speaking, NVMe devices are not physical block devices. The kernel provides a translation layer on top of the NVMe interface that lets you use it as a block device, but as far as the kernel is concerned, it is not natively a block device. – Austin Hemmelgarn Apr 13 '18 at 19:33
  • @AustinHemmelgarn If you put it in those terms, one could say the same thing about SATA or SCSI. And I'm sure I would be surprised to find out that my SSD doesn't have any physical existence. – Michael Hampton Apr 13 '18 at 19:49
  • Except thet the low level kernel interface doesn't treat NVMe devices like block devices, but it does treat SCSI (which may not be block devices) and SATA (which actually has a block device style interface at the protocol level) as block devices all the way down to the protocol drivers. – Austin Hemmelgarn Apr 13 '18 at 22:02

Get info (without partitions):

$ lsblk -a -d
sda    8:0    0   20G  0 disk
sdb    8:16   0   40G  0 disk
sr0   11:0    1 55.3M  0 rom

-a       print even empty devices (if disk is not loaded in CD/DVD device)
-d       discard print slaves
ls -l /sys/block/ | awk '$11 != "" && $11 !~ "^../devices/virtual" { print $9; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.