在Linux中检索硬盘驱动器信息,而无需使用额外的工具

时间:2022-02-14 17:17:54

I need to retrieve hard drive info (such us physical disk capacity, model, etc.). I know that this is possible using different utilities like lshw and hdparm. However I need to retrieve the info without using any utility that might not be installed, only with what is available by default on every Linux system.

我需要检索硬盘驱动器信息(例如我们的物理磁盘容量,型号等)。我知道这可以使用不同的实用程序,如lshw和hdparm。但是,我需要在不使用任何可能未安装的实用程序的情况下检索信息,仅使用每个Linux系统上默认可用的实用程序。

How do I retrieve hard drive information like disk capacity and serial number using pre-installed tools on Linux?

如何使用Linux上的预安装工具检索磁盘容量和序列号等硬盘驱动器信息?

3 个解决方案

#1


13  

if you think cat is utility in your "forbidden" circle, please ignore the answer.

如果你认为猫在你的“禁止”圈子中是实用的,请忽略答案。

to get the disk model, you could:

要获得磁盘模型,您可以:

 cat /proc/scsi/scsi

here with my laptop, it prints:

这里有我的笔记本电脑,它打印:

kent$  cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST9250410ASG     Rev: 0004
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: MATSHITA Model: DVD+-RW UJ892    Rev: 1.01
  Type:   CD-ROM 

it has model information. capacity I didn't find out how. /proc/partitions shows blocks not capacity.

它有模型信息。能力我没有发现如何。 / proc / partitions显示块不是容量。

#2


4  

cat /proc/partitions

Lists which HDs have what capacity. grep in this for your interesting disk.

列出哪些HD具有哪些容量。 grep在这里为你有趣的磁盘。

cat /proc/diskstats

This is less easily understandable but contains probably also some answers.

这不太容易理解,但也可能包含一些答案。

And as birg891 already pointed out, you can scan the /dev/disk/by-* directories, but probably they won't give much useful information (that's my experience).

正如birg891已经指出的那样,你可以扫描/ dev / disk / by- *目录,但可能它们不会提供太多有用的信息(这是我的经验)。

Better you get the option to use hdparm. For information about the manufacturer, if retrievable at all, you need to post a specific command to the device which is easy using hdparm but hard to achieve using no tools. I know of no way to perform ioctl()s using just bash.

更好的是你可以选择使用hdparm。有关制造商的信息,如果可以检索,则需要向设备发布特定命令,这很容易使用hdparm,但很难使用任何工具来实现。我知道没有办法只使用bash执行ioctl()。

#3


2  

You can try poking around /dev/disk/by-id. If you know the different brands of hard drives they usually have a listing by model. For instance, I know seagate includes information about the hard drive in their model numbers. So, if you poke around /dev/disk/by-id you can get a model number and look it up online.

你可以试试p / around / disk / by-id。如果你知道不同品牌的硬盘,他们通常会按型号列出。例如,我知道希捷在其型号中包含有关硬盘驱动器的信息。所以,如果你逛逛/ dev / disk / by-id,你可以获得一个型号并在线查找。

#1


13  

if you think cat is utility in your "forbidden" circle, please ignore the answer.

如果你认为猫在你的“禁止”圈子中是实用的,请忽略答案。

to get the disk model, you could:

要获得磁盘模型,您可以:

 cat /proc/scsi/scsi

here with my laptop, it prints:

这里有我的笔记本电脑,它打印:

kent$  cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST9250410ASG     Rev: 0004
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: MATSHITA Model: DVD+-RW UJ892    Rev: 1.01
  Type:   CD-ROM 

it has model information. capacity I didn't find out how. /proc/partitions shows blocks not capacity.

它有模型信息。能力我没有发现如何。 / proc / partitions显示块不是容量。

#2


4  

cat /proc/partitions

Lists which HDs have what capacity. grep in this for your interesting disk.

列出哪些HD具有哪些容量。 grep在这里为你有趣的磁盘。

cat /proc/diskstats

This is less easily understandable but contains probably also some answers.

这不太容易理解,但也可能包含一些答案。

And as birg891 already pointed out, you can scan the /dev/disk/by-* directories, but probably they won't give much useful information (that's my experience).

正如birg891已经指出的那样,你可以扫描/ dev / disk / by- *目录,但可能它们不会提供太多有用的信息(这是我的经验)。

Better you get the option to use hdparm. For information about the manufacturer, if retrievable at all, you need to post a specific command to the device which is easy using hdparm but hard to achieve using no tools. I know of no way to perform ioctl()s using just bash.

更好的是你可以选择使用hdparm。有关制造商的信息,如果可以检索,则需要向设备发布特定命令,这很容易使用hdparm,但很难使用任何工具来实现。我知道没有办法只使用bash执行ioctl()。

#3


2  

You can try poking around /dev/disk/by-id. If you know the different brands of hard drives they usually have a listing by model. For instance, I know seagate includes information about the hard drive in their model numbers. So, if you poke around /dev/disk/by-id you can get a model number and look it up online.

你可以试试p / around / disk / by-id。如果你知道不同品牌的硬盘,他们通常会按型号列出。例如,我知道希捷在其型号中包含有关硬盘驱动器的信息。所以,如果你逛逛/ dev / disk / by-id,你可以获得一个型号并在线查找。