« Back to Frequently Asked Questions

How to see the available hard disks

Show available hard disk devices

Using blkid

The first tool to query the available disks is blkid. It shows a list of devices and is available on most Linux distributions.

blkid

Using lsblk

Another great utility is lsblk. As the name implies, it shows block devices, like a hard disk. It will show a tree-like structure with the basic details. Its output is easier to read than that of blkid.

# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0                       7:0    0   87M  1 loop /snap/lxd/27948
loop1                       7:1    0   87M  1 loop /snap/lxd/28373
loop2                       7:2    0 39.1M  1 loop /snap/snapd/21184
loop4                       7:4    0 63.9M  1 loop /snap/core20/2182
loop5                       7:5    0 63.9M  1 loop /snap/core20/2264
loop6                       7:6    0 38.7M  1 loop /snap/snapd/21465
sda                         8:0    0   16G  0 disk 
├─sda1                      8:1    0    1M  0 part 
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 14.2G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0 14.2G  0 lvm  /
sr0                        11:0    1 1024M  0 rom  

In this output we can see that we have one disk (sda) that contains multiple partitions (sda{1,2,3}). A valuable piece of information is the major device identifier (8). It is a block device and the shortened name is sd, which stands for SCSI disk devices. For NVMe devices, the major device ID is 259.

If we want to query which hard disks are available, we can do an alternative query using a filter with the major device IDs 8 and 259.

lsblk --nodeps --noheadings --include 8,259 --output NAME

Here we ask lsblk to show us only the name of the devices with major type 8 or 259. No dependencies and no headings in the output.

Query disk devices using the lshw command

Another great tool is lshw and lists hardware. By defining the class to disk, we see hard drivers and other disk devices.

# lshw -class disk
  *-cdrom                   
       description: DVD reader
       product: QEMU DVD-ROM
       vendor: QEMU
       physical id: 0.0.0
       bus info: scsi@1:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/sr0
       version: 2.5+
       capabilities: removable audio dvd
       configuration: ansiversion=5 status=nodisc
  *-disk
       description: SCSI Disk
       product: QEMU HARDDISK
       vendor: QEMU
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: 2.5+
       size: 16GiB (17GB)
       capabilities: 5400rpm gpt-1.00 partitioned partitioned:gpt
       configuration: ansiversion=5 guid=59907fc9-3694-4808-8f5b-9032ae1b279d logicalsectorsize=512 sectorsize=512

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also cheat sheet available.

  • blkid
  • lsblk
  • lshw

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution.

Mastodon icon