it-swarm.cn

我如何找出系统中有哪些硬盘?

我需要知道有哪些可用的硬盘,包括未安装且可能未格式化的硬盘。我在dmesg/var/log/messages(滚动太多)。我希望有一种使用/dev 要么 /proc查找此信息,但我不知道如何。我正在使用Linux。

238
xenoterracide

这是高度依赖平台的。同样,不同的方法可能会以不同的方式对待Edge案例(各种“假”磁盘,RAID卷等)。

在现代udev安装中,在/dev/disk子目录中有指向存储介质的符号链接,可让您通过序列号(/dev/disk/by-id/),UUID(/dev/disk/by-uuid)查找磁盘或分区。 ),文件系统标签(/dev/disk/by-label/)或硬件连接(/dev/disk/by-path/)。

在Linux 2.6下,每个磁盘和类似磁盘的设备在/sys/block中都有一个条目。自Linux发行以来,磁盘和分区在/proc/partitions中列出。或者,您可以使用 lshwlshw -class disk

Linux还提供了 lsblk 实用程序,该实用程序显示存储卷的尼斯树形视图(因为util-linux 2.19,在BusyBox的嵌入式设备上不存在)。

如果您使用fdiskdisklabel实用程序,它可能会告诉您它可以在哪些设备上工作。

您会在 用于Unix的Rosetta Stone 上找到许多Unix变体的实用程序名称,尤其是“列出硬件配置”和“读取磁盘标签”行。

194

lsblk将列出所有块设备。它非常适合脚本编写:

$ lsblk -io KNAME,TYPE,SIZE,MODEL
KNAME TYPE   SIZE MODEL
sda   disk 149.1G Toshiba MK1637GS
sda1  part  23.3G 
sda2  part    28G 
sda3  part  93.6G 
sda4  part   4.3G 
sr0   rom   1024M CD/DVDW TS-L632M

lsblk存在于util-linux软件包中,因此比提出的替代方案更通用。

160
K3---rnc

怎么样

lshw -class disk
70
nc3b

hwinfo 帮助:

> hwinfo --disk
21: IDE 00.0: 10600 Disk                                        
[Created at block.245]
Unique ID: 3OOL.8MZXfAWnuH8
Parent ID: w7Y8.1T_0outZkp6
SysFS ID: /class/block/sda
SysFS BusID: 0:0:0:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/Host0/target0:0:0/0:0:0:0
Hardware Class: disk
Model: "Hitachi HTS54322"
Vendor: "Hitachi"
Device: "HTS54322"
Revision: "ESBO"
Driver: "ahci", "sd"
Driver Modules: "ahci"
Device File: /dev/sda
Device Files: /dev/sda, /dev/disk/by-id/ata-Hitachi_HTS543225A7A384_E2021342GEPG4J, /dev/disk/by-id/scsi-SATA_Hitachi_HTS5432_E2021342GEPG4J, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0, /dev/disk/by-id/wwn-0x5000cca614c6395e
Device Number: block 8:0-8:15
BIOS id: 0x80
Geometry (BIOS EDD): CHS 484521/16/63
Size (BIOS EDD): 488397168 sectors
Geometry (BIOS Legacy): CHS 1023/255/63
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #17 (SATA controller)
> hwinfo --block --short
disk:                                                           
  /dev/sda             Hitachi HTS54322
partition:
  /dev/sda1            Partition
  /dev/sda2            Partition
  /dev/sda3            Partition
  /dev/sda4            Partition
  /dev/sda5            Partition
26

@Giles说,这高度依赖平台。这是一个这样的例子。

我正在运行CentOS 5.5系统。该系统有4个磁盘和3ware RAID控制器。

就我而言,lshw -class diskcat /proc/scsi/scsiparted --list显示RAID控制器(3ware 9650SE-4LP)。这不会显示实际的磁盘:

仅显示提供/ dev/sda卷的3ware RAID控制器:

# lshw -class disk
  *-disk                  
       description: SCSI Disk
       product: 9650SE-4LP DISK
       vendor: AMCC
       physical id: 0.0.0
       bus info: [email protected]:0.0.0
       logical name: /dev/sda

# cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: AMCC     Model: 9650SE-4LP DISK  Rev: 4.06
  Type:   Direct-Access                    ANSI SCSI revision: 05

# parted --list

Model: AMCC 9650SE-4LP DISK (scsi)
Disk /dev/sda: 2000GB

为了查看下面的磁盘,我必须从3ware安装tw_cli实用程序,并询问控制器本身。

# tw_cli info c0
...

VPort Status         Unit Size      Type  Phy Encl-Slot    Model
------------------------------------------------------------------------------
p0    OK             u0   931.51 GB SATA  0   -            WDC WD1002FBYS-02A6 
p1    OK             u0   931.51 GB SATA  1   -            WDC WD1002FBYS-02A6 
20
Stefan Lasiewski

由于“ 我能看到安装的硬盘吗? “和“ 如何确定存储设备的品牌和型号? ”都被标记为该问题的重复项。 ,我很惊讶没有人提到hdparmsmartctl。查看几台机器,似乎经常会发现其中任何一台(虽然不是两者都存在)已经安装在标准(甚至旧的)Linux发行版中。

# smartctl -i /dev/sda
smartctl 6.1 2013-03-16 r3800 [i686-linux-3.9.9-301.fc19.i686.PAE] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Toshiba 2.5" HDD MK..56GSY
Device Model:     Toshiba MK1656GSY
Serial Number:    60PKT43CT
LU WWN Device Id: 5 000039 2919874b6
Firmware Version: LH013D
User Capacity:    160 041 885 696 bytes [160 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Mon Jul 22 11:13:37 2013 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

# hdparm -i /dev/sda

/dev/sda:

 Model=Toshiba MK1656GSY, FwRev=LH013D, SerialNo=60PKT43CT
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
 BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=312581808
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4
 DMA modes:  sdma0 sdma1 sdma2 mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: Unspecified:  ATA/ATAPI-3,4,5,6,7

 * signifies the current active mode

与往常一样,请查看联机帮助页以获取更多选项。

14
Skippy le Grand Gourou

我正在运行Fedora 14,并且lshw在这里不可用(至少默认情况下不可用)。但是,就我而言,我使用fdisk -l命令(以root用户身份)以获取以下输出:

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006a697

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    16777215     7875584   8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/dm-0: 6509 MB, 6509559808 bytes
255 heads, 63 sectors/track, 791 cylinders, total 12713984 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 1543 MB, 1543503872 bytes
255 heads, 63 sectors/track, 187 cylinders, total 3014656 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table
12
Eugene S

在其他SE答案中找到inxi工具非常方便:

inxi -Dxx
Drives:    HDD Total Size: 810.2GB (42.9% used)
           ID-1: /dev/sdc model: ST3160827AS size: 160.0GB serial: 5MT2HMH6
           ID-2: /dev/sdb model: WDC_WD3200JD size: 320.1GB serial: WD-WCAMR1302926
           ID-3: /dev/sda model: ST380817AS size: 80.0GB serial: 4MR2EWBE
           ID-4: /dev/sdd model: ST3250824AS size: 250.1GB serial: 9ND08GKX
6
Grzegorz Wierzowiecki
sfdisk -l  

即使没有安装,也会为您提供有关硬件/物理磁盘的详细信息。

该程序已预装在我使用过的所有Linux变体上,但是您必须是root用户才能使用它。

4
codeslinger

列出的许多命令将帮助您查找启动时系统已识别的磁盘。使用现代驱动器,您可能会发现自己正在寻找在机器启动和运行时插入的东西(我这样做了)。我喜欢 http://fredericiana.com/2010/06/15/hot-plugging-a-sata-drive-under-linux/ 的建议:

尝试执行以下操作以重新扫描SCSI主机(每个SATA端口显示为SCSI总线):

echo“ 0 0 0”>/sys/class/scsi_Host/host/scan

...然后,您可以使用fdisk之类的Linux实用程序向您显示有关找到的磁盘的信息。

3
Mike Schwager

这为我工作:

fdisk -l 2>/dev/null | grep "Disk \/" | grep -v "\/dev\/md" | awk '{print $2}' | sed -e 's/://g'
2
Aldo Vargas

Sudo gparted将在GUI中显示所有这些内容。

(您未指定需要在终端内执行此操作,因此我想知道为什么缺少此解决方案。)

1
Ondra Žižka