Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Linux determine the disk type

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to judge the disk type of Linux". In the daily operation, I believe that many people have doubts about how to judge the disk type of Linux. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to judge the disk type of Linux". Next, please follow the editor to study!

Method one

Judge the return value of cat / sys/block//queue/rotational (where is your hard disk device name, such as sda, etc.). If you return 1, the disk can be rotated, then it is HDD.

If 0 is returned, it means that the disk cannot be rotated, so it is SSD.

[pythontab@pythontab.com ~] $cat / sys/block/sda/queue/rotational0 [pythontab@pythontab.com ~] $grep ^ / sys/block/*/queue/rotational/sys/block/ram0/queue/rotational:1/sys/block/sda/queue/rotational:0/sys/block/sdb/queue/rotational:0/sys/block/sdc/queue/rotational:0/sys/block/sdd/queue/rotational:0

The problem with this approach is that there are not only hard drives under the / sys/block/, but there may also be other block devices that interfere with your judgment.

Method two

Use the lsblk command to determine, the parameter-d indicates the display device name, and the parameter-o indicates that only specific columns are displayed.

[pythontab@pyhontab.com ~] $lsblk-d-o name,rotaNAME ROTAsda 0sdb 0sdc 0sdd 0

The advantage of this method is that it only lists what you want to see, and the result is relatively concise and clear. Again, if ROTA is 1, it can be rotated, otherwise it cannot be rotated.

Method three

You can view it through the fdisk command, and the parameter-l indicates that the disk details are listed. In the output, the line that begins with Disk represents the disk profile. Here are some detailed parameters in which we can try to find some HDD-specific keywords, such as "heads" (magnetic head), "track" (track), and "cylinders" (cylinder).

Here are the output results of HDD and SSD, respectively.

Disk / dev/sda: 120.0 GB, 120034123776 bytes255 heads, 63 sectors/track, 14593 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00074f7d [pythontab@pyhontab.com ~] $sudo fdisk-lDisk / dev/nvme0n1: 238.5 GiB, 256060514304 bytes 500118192 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xad91c214. Other methods

You can use third-party tools, such as smartctl, whose results are intuitive, but need to be installed separately. Success!

At this point, the study on "how to determine the disk type of Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report