列出Linux系统中的所有硬盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7107000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List all harddrives in a linux system
提问by Allan
I'm having problems to detect which one of my block devices is the hard drive. My system has a cd-rom drive, USB drives, and a single hard drive of unknown vendor/type.
我在检测哪个块设备是硬盘时遇到问题。我的系统有一个 cd-rom 驱动器、USB 驱动器和一个未知供应商/类型的硬盘驱动器。
How can I identify the hard drive with a linux command, script, or C application?
如何使用 linux 命令、脚本或 C 应用程序识别硬盘驱动器?
采纳答案by Daniel Fekete
sudo lshw -class disk
will show you the available disks in the system
将显示系统中的可用磁盘
回答by janneb
If you have a list of the plausible block devices, then the file
如果你有一个合理的块设备列表,那么文件
/sys/block/[blockdevname]/removable
/sys/block/[blockdevname]/removable
will contain "1" if the device is removable, "0" if not removable.
如果设备可移动,将包含“1”,如果不可移动,将包含“0”。
回答by Lars Nordin
As shuttle87 pointed out, there are several other posts that answer this question. The solution that I prefer is:
正如shuttle87 指出的,还有其他几个帖子回答了这个问题。我更喜欢的解决方案是:
root# lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL
root# lsblk -io NAME,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL
NAME TYPE SIZE MOUNTPOINT FSTYPE MODEL
sdb disk 2.7T WDC WD30EZRX-00D
`-sdb1 part 2.7T linux_raid_member
`-md0 raid1 2.7T /home xfs
sda disk 1.8T ST2000DL003-9VT1
|-sda1 part 196.1M /boot ext3
|-sda2 part 980.5M [SWAP] swap
|-sda3 part 8.8G / ext3
|-sda4 part 1K
`-sda5 part 1.8T /samba xfs
sdc disk 2.7T WDC WD30EZRX-00D
`-sdc1 part 2.7T linux_raid_member
`-md0 raid1 2.7T /home xfs
sr0 rom 1024M CDRWDVD DH-48C2S
References:
参考: