Linux: 3 commands for listing disks and partitions

Linux - 3 commands for listing disks and partitions

How do I list disks and partitions on a Linux system? That's a good question to answer in this article. Although I'll be concentrating on command-line tools, I'll also mention the option available with a graphical interface: that way, there's something for everyone! After reading this article, you'll know how to display or retrieve information about disks and partitions on your Linux serveror simply your Linux computer.

1. List disks and partitions with the fdisk command

fdisk is an essential command-line tool when you need to manipulate a disk partition table. In simple terms, you can use it to display your server's disks and partitions, as we shall see.

The -l option implies listing partitions and if no device is specified, fdisk will display the partitions of all disks present on your machine. This utility requires root privileges, so use the sudo command if necessary, unless you are logged in as root:

sudo fdisk -l

Thus, the above command willdisplay disk partitions under Linux. Here is an example of the result:

List Linux disks - Commands

If we look at the image above, we can see that there's a 10 GB disk, associated with the "/dev/sda" device. This disk has 3 partitions (sda1, sda2 and sda5) and relies on the LVM system for volume management on the main partition. The fdisk command gives precise information on the partitioning of the machine's disks.

2. View Linux disk partitions using the lsblk command

Let's move on to the second utility: lsblkwhich is a utility for listing block devices. You can use it to view the disks and partitions of your Linux machine as shown below. Unlike the previous tool, this one works without the sudo command:

lsblk

Without option, we obtain the following result:

Linux - Command lsblk.jpg

The cool thing about this command is that it displays a synthetic view, with a notion of hierarchy. The result is very easy to interpret, even easier than with fdisk.

However, there is very little information and this may frustrate you... Don't panic! To display additional information about the disks on your Linux machine, use the -f option like this:

lsblk -f

There is some additional information, including theavailable disk space :

Display information on Linux partitions

Let's move on to the next tool...

3. Get disk information with the hwinfo command

Third tool for disc information : hwinfo. This is another useful utility for displaying information about hardware, in particular disks, but also network cards, etc... It's highly likely that the command isn't available on your machine, as you'll need to install an additional package. The above two commands are native to Linux.

Here's how to install hwinfo under Linux, on several distributions:

# Debian, Ubuntu and Mint
sudo apt-get install hwinfo
# Rocky Linux, Fedora, CentOS, RHEL
sudo yum install hwinfo
# Arch Linux
sudo pacman -S hwinfo
# OpenSUSE
sudo zypper install hwinfo

Once the package hwinfo installed, run the following command with theoption -disk which provides targeted information on disks:

sudo hwinfo --disk

This command returns very precise information about the disk. Here, it is a virtual hard disk in a virtual machine, but with a real disk, we would have the manufacturer, model, serial number, etc... Rather than displaying information about partitions, this command focuses more on the hardware itself.

Display Linux disk information

But it has not said its last word, as it is also capable of displaying score information. To do this, you need to add the -short and -block like this:

sudo hwinfo --short --block

This gives you an overview of the Linux machine's disks:

Overview of Linux disks

To list only the disks without going down to the partition level, here is the command to use:

sudo hwinfo --disk --short

4. Disk Tool, the graphical alternative

On a machine with a desktop environment, you don't have to use the Terminal, as there are applications available in graphics mode. When it comes to obtaining disk and partition information from the Linux desktop interfaceYou can use the Disk Tool application. This application should be available in the System menu of your Linux environment.

5. Conclusion

After reading this article from the Computer Tutorials box, you'll be able to get precise information about your Linux machine's disks and partitions!

Resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *