How to List Disks on Linux

HOW TO LIST DISKS ON LINUX


If you are a Linux user looking to see all the disks connected to your system then this article will help you. Listing disks on Linux is a basic system administration task that everyone should know how to perform.

One of the big worries for the system administrator is to check whether disks are up and running in optimal condition. Quite often, you will be required to display all the disks present in your computer along with their sizes to avoid them running out of disk space. You could literally have your server down, and most of your users would not be able to use it if they were to run out of capacity. Today we learned how to List Disks Available on Linux Server easily using the command line.



INTRODUCTION: UNDERSTANDING DISK MANAGEMENT IN LINUX


Disk Management Is An Essential Part Of A Healthy Linux System In this article, we are going to explore disk management in Linux, the significance of it and few changes which should be done as best practices.

BRIEF INTRODUCTION TO DISK MANAGEMENT IN LINUX


Disk management is the process of organizing and managing storage media that are like hard drive, solid-state drive, USB drives in Linux. Disk Management: Disk management is used for executing queries to view the disk information, create partitions and delete them as well and also one can manage the file system.

IMPORTANCE OF PROPER DISK AND FILESYSTEM MANAGEMENT


Optimizes Storage Space: Parted magic allows you to use the storage space efficiency. Disks are divided and filesystems are arranged so that space can be allocated to system files, user files or temporary files.

System Reliability and Stability: A good disk system management brings improvement to the credibility of the Linux operating system. Keeping the disk clean, checking to fix file system errors and monitoring disk space will help you avoid that system crashes and destroying your hard drive. It can also check the disk which helps a storage device to live longer and prevents data loss.

So knowing about disk management in Linux is a key concept to maintain a good and secure system. It doesn't matter if you are a beginner Linux user or an experienced system administrator, correct management of the disks is crucial to use all power that lies in your Linux/UNIX box.



KEY TOOLS FOR DISK LISTING IN LINUX


USING lsblk: THE MOST COMMON TOOL


With Linux, the simplest method to list drives is to run the "lsblk" command without any parameters.

lsblk


DISK MANAGEMENT 1


You have the option to use the "-f" option for "filesystems." Your drives, along with the partitions and filesystems that are formatted on them, will be listed in this manner.

lsblk –f


DISK MANAGEMENT 2


The following columns are displayed when you run the “lsblk” command:


Name: the name of the device. It is quite important for you to know that Linux devices have a specific prefix depending on the nature of the device. “sd” in this case refers to SCSI devices but it is also short for SATA connections as most drives use SATA nowadays;

Filesystem type: if your partition contains a filesystem, it should be listed in this column (xfs, swap or encrypted devices);

Label: in some cases, in order to avoid using a UUID, you can choose to have a label for your device;

UUID: a universal unique identifier. This identifier should be unique worldwide and uniquely identify your device;

Mountpoint: if your filesystem is mounted, you should be able to see the actual mountpoint.

Awesome, you successfully listed your disks on Linux using “lsblk”. However, in some cases, you are interested in listing your disks with the actual hardware information linked to it.

RETRIEVING DETAILED DISK INFORMATION WITH lshw


Under Linux, you must use the “lshw” command with the “class” option set to “disk” in order to list disk information. When you use the commands "lshw" and "grep," you can get detailed information about a disk on your computer.

sudo lshw -class disk


sudo lshw -class disk | grep -A 5 -B <disk_name>


DISK MANAGEMENT 3


As you can see, you are shown every disk that is available on your machine when you execute "lshw" without any grep filters.

You can "pipe" the command with "grep" to limit the list of disks to just the ones you wish to see if you want to target a specific disk on your machine.

DISK MANAGEMENT 4


As you can see, you can get a lot more information about your disks with this command: the product and vendor details, the description, and the bus information (where the disk may be plugged on your motherboard).

Greate, you now know how to use "lshw" to list the contents of your disk.



ALTERNATIVE METHODS FOR DISK MANAGEMENT


Alternatives to lsblk : fdisk or hwinfo


In Linux, there are more commands you may use to get a listing of your disks in addition to "lsblk." There are two more commands: hwinfo and fdisk, which is frequently used for partitioning.

First, all of the partitions and disks that are available on your computer will be shown to you if you use the “fdisk” command with the “-l” option.

sudo fdisk -l


DISK MANAGEMENT 5


You have a fairly thorough description of your primary disk, as you can see. It is even possible to confirm the bootable flag and the accessible partitions on it.

Also, “fdisk” is not the only way for you to list disks, you can also use the “hwinfo” command with the “–disk” option.

But first you need to install the hwinfo package on the operating system:

apt install hwinfo
OR
yum install hwinfo


Next, enter the following command:

sudo hwinfo --disk


DISK MANAGEMENT 6


Using the “hwinfo” command without any options is quite hard to read. Luckily for you, there is an option that you can use in order to restrict the output to the disk list.

In order to achieve that, you have to use the “–short” option.

sudo hwinfo --disk --short


DISK MANAGEMENT 7


As you can see, the output is quite concise but it gives you a clear idea on disks available.

Also, you can have a look at the “/dev/disk” folder.

ls -l /dev/disk/


DISK MANAGEMENT 8


In this folder, you can check the “by-id” folder if you are looking for disks or the “by-uuid” one if you are looking for partitions.

ls -l /dev/disk/by-id


DISK MANAGEMENT 9



VISUALIZING DISK INFORMATION USING GRAPHICAL TOOLS


You must navigate to "Activities" and search for a program named "Disks" in order to list disks on Linux using the graphical user interface.

You can search for an output like the one below by typing "Disks" into the "Activities" menu.

disks activity linux



When clicking on “Disks”, you will be presented with the list of disks available on your Linux machine.

disks-window-desktop linux



As you can see, in the “Disks” window, you have the “hard disk” as well as “block devices” which are the LVM devices.

You can view the size of the disk, its serial number, any partitions, and any potential contents by clicking on a particular disk.

Great! The list of disks that are inserted into your computer is now available to you.



TROUBLESHOOTING AND BEST PRACTICES IN DISK MANAGEMENT


COMMON ISSUES AND HOW TO RESOLVE THEM


Not Recognized: One of the main problems is when the disk is not recognized by the computer. The reasons may be faulty connection, out-of-date drivers, or a broken disk. Top of the list, paradoxically, check the physical connections of the disk to ensure. If everything is well connected, the next step is updating the drivers by going to Device Manager in the Control Panel. If it is still not recognized, it could be a hardware problem and you might have to replace the disk.

Fragmentation: The separation of the disk into non-contiguous clusters is the main cause of disk fragmentation, which consequently results in the system being slower. The defragmentation tool should be used on a regular basis for the purpose of fixing the fragmentation problem. It causes data to be more nearby to one another, which in turn contributes to the better functioning of the apparatus.

Error Checking: Disk errors are the main cause of system crashes and data loss if not dealt with in time. To check for errors, you can use the built-in error-checking tool in Windows. This tool checks for errors and fixes them automatically.

BEST PRACTICES FOR DISK MANAGEMENT


Regular backups: One of the best practices for disk management is to back up your data regularly. This guarantees that you have a copy of your essential files in case failure or data loss. The best way to backup your data is to use external storage devices or cloud storage services and set up automatic backups for convenience.

Cleanup: Scheduled cleanup is one of the main things you should do in order to keep your computer working well. Access the built-in disk cleanup function of Windows in order to clear away temporary files, old system files & even other data that are no longer necessary.



CONCLUSION: MASTERING DISK MANAGEMENT IN LINUX


Linux disk management proficiency is a prerequisite for efficient administration of systems. One can do this through the effective application of programs such as fdisk, gdisk, etc. In brief, as a result of the development of such proficiency, administrators can competently manage complexity, ensure the system is professional and well-organized, and provide optimal storage infrastructure.

FAQs

You ask, and we answer! Here are the most frequently asked questions!