CommandsLinux

How To List Disks on Linux

Listing Disks in Linux

Are you looking for an easy way to list disks on your Linux system? Maybe you need to check if a new disk is properly installed or you want to see how your disks are partitioned. Whatever your reason, you’re in luck because there are several commands you can use to list disks on Linux. In this post, we’ll cover the most popular commands for listing disks on Linux: lsblk, fdisk, parted, and blkid.

We’ll start with the lsblk command, which is a simple and straightforward way to list all the disks connected to your Linux system. Then we’ll move on to the more powerful fdisk and parted commands, which allow you to view and manipulate disk partitions. Finally, we’ll cover the blkid command, which is used to view the UUID of a disk or partition.

Whether you’re a Linux newbie or an experienced user, this post will give you the knowledge you need to effectively list disks on your Linux system. So let’s get started and explore the world of Linux disk listing!

Understanding Block Devices in Linux

Before we dive into the commands used to list disks in Linux, it’s important to understand the concept of block devices. In Linux, a block device is any storage device that can be accessed at the block level. This includes hard disks, USB drives, CD/DVD drives, and more.

Block devices are identified by a device file, typically located in the /dev directory. For example, the device file for the first hard disk in a system is usually /dev/sda. Block devices can also be divided into partitions, which are identified by a partition number appended to the end of the device file name. For example, the first partition on the first hard disk is usually /dev/sda1.

Linux Commands to List Disks

There are several commands you can use to list disks in Linux. The most commonly used commands are lsblk, fdisk, and parted.

  • lsblk

The lsblk command lists all block devices in the system, including disks, partitions, and other storage devices. The output includes the device name, size, and partition information, as well as mount points and other details. Here’s an example of how to use lsblk:

lsblk

Example usage and output:

$ lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda
├─sda1 ext4         1E03-DA6D                            /boot
└─sda2 ext4         58f42e7e-8b1c-4c33-9e4e-6a3c122e8c4e /

This will list all block devices in the system in a hierarchical format. You can also use the -a option to show all devices, even those that are not currently in use.

  • fdisk

The fdisk command lists all disks and their partitions in the system, similar to the lsblk command. The output includes the device name, size, and partition information, as well as the partition table type and other details. Here’s an example of how to use fdisk:

sudo fdisk -l

Example usage and output:

$ sudo fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Device     Boot Start       End   Sectors Size Id Type
/dev/sda1  *     2048 167772159 167770112  80G 83 Linux

This will list all disks and their partitions in the system. You need to run this command with superuser privileges using sudo to view information about all disks and their partitions.

  • parted

The parted command also lists all disks and their partitions in the system. The output includes the device name, size, and partition information, as well as the partition table type and other details. Here’s an example of how to use parted:

sudo parted -l

This will list all disks and their partitions in the system. Like fdisk, you need to run this command with superuser privileges using sudo to view information about all disks and their partitions.

  • df

df reports the amount of disk space used and available on filesystems. The -h option makes the output human-readable, and -T includes the filesystem type.

Example:

df -hT
  • lshw

lshw – short for list hardware, when used with the -class disk option, lists detailed information about all disk devices. It provides comprehensive hardware details including product and vendor information.

Example:

sudo lshw -class disk
  • Using blkid to List Block Device UUIDs:

Another useful command for managing storage devices in Linux is blkid. This command lists all block devices and their UUIDs, which can be useful for identifying specific devices. Here’s an example of how to use blkid:

sudo blkid

This will list all block devices and their UUIDs. Like fdisk and parted, you need to run this command with superuser privileges using sudo to view information about all block devices.

Conclusion

In conclusion, we have discussed the concept of block devices in Linux and the various commands used to list disks and their partitions. By mastering these commands, you can effectively manage your storage devices and ensure the proper functioning of your Linux system.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button