TECHNOLOGYtech

How To Check If Disk Is SSD Or HDD On Linux

how-to-check-if-disk-is-ssd-or-hdd-on-linux

Introduction

When working with Linux systems, it can be useful to know whether a disk is a solid-state drive (SSD) or a hard disk drive (HDD). This information is important for various reasons, such as optimizing disk performance, troubleshooting issues, or making informed decisions about storage upgrades.

Fortunately, there are multiple methods to determine if a disk is an SSD or an HDD in a Linux environment. In this article, we will explore four different approaches that you can use to check the disk type on your Linux system.

We will cover the following methods:

  1. Using the “lsblk” command
  2. Checking the “/sys/block” directory
  3. Using the “fstab” file
  4. Checking the “hdparm” info

Each method has its advantages and can be used on different Linux distributions. By understanding and implementing these methods, you will gain valuable insights into the disk types on your Linux system.

So, without further ado, let’s dive into the different methods and learn how to check if a disk is an SSD or HDD in Linux.

 

Method 1: Using the “lsblk” Command

The “lsblk” command is a powerful utility in Linux that provides information about storage devices connected to the system. It can help us determine if a disk is an SSD or an HDD.

To use the “lsblk” command, open a terminal and enter the following command:

lsblk -d -o name,rota

Running this command will display a list of storage devices along with their rotational status. If the value under the “rota” column is “1”, it indicates that the disk is an HDD. On the other hand, if the value is “0”, it means the disk is an SSD.

By examining the output of the “lsblk” command, you can easily identify the type of disk connected to your Linux system. This information can be handy when analyzing the performance characteristics or planning for disk upgrades.

This method is generally reliable and should work on most Linux distributions. However, keep in mind that the “lsblk” command requires administrative privileges. Therefore, you may need to prefix the command with “sudo” and enter your password if prompted.

Now that you know how to use the “lsblk” command to check if a disk is an SSD or HDD, let’s move on to the next method.

 

Method 2: Checking the “/sys/block” Directory

Another method to determine if a disk is an SSD or an HDD in Linux is by examining the contents of the “/sys/block” directory. This directory contains information about the block devices connected to your system.

To check the disk type using this method, open a terminal and enter the following command:

cat /sys/block/*/{queue/rotational,device/model} | awk '{ORS = (NR % 2 == 0)? "\n" : " "; print}' | awk '{print $2, $1}' | sort

The output of this command will list all the connected disks, along with their corresponding rotational status and model information. If the rotational status is “1”, it suggests that the disk is an HDD. Conversely, if the rotational status is “0”, it indicates that the disk is an SSD.

This method provides a detailed view of each individual disk and allows you to gather information such as the model name, rotational status, and more. It can be useful when you need precise and comprehensive details about the disks connected to your Linux system.

Keep in mind that this method also requires administrative privileges. Hence, you might need to run the command with “sudo” if you encounter any permission issues.

Now that you know how to check the disk type using the “/sys/block” directory, let’s explore another method in the next section.

 

Method 3: Using the “fstab” File

The “fstab” file in Linux contains information about the filesystems and disk partitions on your system. By examining this file, you can also determine if a disk is an SSD or an HDD.

To check the disk type using the “fstab” file, open a terminal and enter the following command:

grep ' / ' /etc/fstab | grep -Eo 'ssd|nvme|rotational|hdd'

This command searches for the line in the “fstab” file that corresponds to the root file system (“/”) and extracts the relevant information about the disk type. If the output includes terms like “ssd” or “nvme”, it indicates that the disk is an SSD. On the other hand, if the output contains terms like “rotational” or “hdd”, it suggests that the disk is an HDD.

Using this method, you can quickly determine the disk type without the need for additional utilities or commands. It relies on the information stored in the “fstab” file, which is a central configuration file for file system mounting in Linux.

As with the previous methods, keep in mind that administrative privileges may be required to access the “fstab” file. If you encounter any permission issues, try running the command with “sudo”.

Now that you know how to check the disk type using the “fstab” file, let’s move on to the final method in the next section.

 

Method 4: Checking the “hdparm” Info

The “hdparm” command is a useful utility in Linux for querying and controlling various parameters of IDE or SATA hard drives. By using the “hdparm” command, you can also check if a disk is an SSD or an HDD.

To check the disk type using this method, open a terminal and enter the following command:

sudo hdparm -I /dev/sda | grep 'Model\|Transport\|SATA'

This command retrieves information about the specified disk (here, “/dev/sda”) using the “hdparm” utility. It specifically looks for lines containing the keywords “Model”, “Transport”, and “SATA”. By examining this output, you can identify the disk type.

If the “Transport” line indicates “SATA” and the “Model” line provides details about a specific SSD model, it confirms that the disk is an SSD. On the other hand, if the “Transport” line indicates “SATA” and the “Model” line provides details about an HDD model, it suggests that the disk is an HDD.

This method is particularly helpful if you want to obtain detailed information about a specific disk’s properties beyond just its type. As the “hdparm” command interacts directly with the drives, it can provide more detailed insights into their characteristics.

Remember to replace “/dev/sda” with the appropriate device name if you want to check a different disk.

Now that you are familiar with the method of checking the disk type using the “hdparm” info, we can conclude our exploration of the different methods.

 

Conclusion

Determining whether a disk is an SSD or an HDD in a Linux environment is crucial for optimizing system performance, troubleshooting issues, and making informed decisions about storage upgrades. In this article, we explored four different methods to check the disk type.

We started with the “lsblk” command, which provides information about storage devices and their rotational status. By analyzing the output, we can easily identify whether a disk is an SSD or an HDD.

Next, we discussed the method of checking the “/sys/block” directory. By examining the relevant files in this directory, we can gather information about the rotational status and model of the connected disks.

The third method involved examining the “fstab” file, which contains information about file systems and disk partitions. By analyzing the relevant line for the root file system (“/”), we can determine the disk type based on keywords like “ssd” or “hdd”.

Lastly, we explored the “hdparm” command, which allows us to query and control various parameters of IDE or SATA hard drives. By examining the output of the “hdparm” command, we can identify the disk type based on the model and transport information.

Each method provides a unique way to determine if a disk is an SSD or an HDD, and the choice of method may depend on your specific requirements or Linux distribution. By understanding and applying these methods, you can gain valuable insights into the disk types on your Linux system.

Now that you have a solid understanding of these four methods, you can confidently check the disk type in your Linux environment and take appropriate actions to optimize your storage configuration.

Leave a Reply

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