How to list the hard disks in the system?
Hi,
I need to write a script that will list all the hard disks in the system. The output of the script will be fed into another script. Hence the output has to be machine readable. I have tried lshw -class disk -short which shows both the usb and the disk I have also tried ls /dev/{hs}d? but again it shows both the hard disk and usb drive. Hence the problem is to get rid of usb from the output. The usb will always be there as the scripts will be run from a live usb. I tried google search but none of the solutions seem to address my problem. So please help and would appreciate greatly. Thanks |
"ls /dev/disk/by-id"
|
removed... probably not the best advice.
|
Is the script being run as root? And does it need to output physical disks or mounted/unmounted partitions?
This might help. /dev/sd[a-d] are internal SATA disk, /dev/sdi is a USB HDD, and I have a USB flash drive that doesn't show in this list. Code:
$ /usr/sbin/smartctl --scan |
Unfortunately "ls /dev/disk/by-id" won't work because USB drives use SCSI emulation so they're marked as /dev/sd* devices as well. That's also the reason the OP's
Code:
lshw -class disk -short Code:
lshw -disable usb -class disk -short Quote:
Code:
#!/bin/sh -- |
Use lsusb to subtract from list.
It took many years to get a usb to act like a scsi to linux. It is a feature that has proved very useful. |
Quote:
I did a quick check prior to posting with a USB key, and it showed as "usb-...". Out of curiosity I just tested a USB hard drive and it did likewise. Fedora 17. |
Quote:
Code:
env GLOBIGNORE=*usb-* /bin/ls -1 /dev/disk/by-id/* |
Thanks guys for the quick replies. The output of
ls /dev/{hs}d? was different in case of virtual machine: ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001 dm-name-vgbip-volbip1 dm-uuid-LVM-fqAYJKNxQJeTW8OBsfxoJ5k215KBRd9W83of4hByz2cmz7UnKjUDdc6ZWBYoB7X5 Hence I guess that command has limitations. ls /dev/disks/by-id shows dm-....-LVM kind of entries while run on a RHEL virtual machine. The smartctl command seems to work fine in opensuse virtual machine but I could not download it for ubuntu using apt-get. But anyhow I can try to find a suitable package for ubuntu. Is there any other solution better than smartctl using standard commands generally available in all distros (like ls, find, etc)? Thanks |
Quote:
And LVM on top of that apparently - which adds another block-device layer on top of all the other software layers. The commands are providing you with what you asked for - and what the hipervisor is designed to allow the guest(s) to see. Not a limitation in the command IMHO. |
I would assume the package name for Ubuntu is the same for Debian. apt-get install smartmontools
|
arent all hard disks (internal/external/usb/ide/sata/camera/phone/mp3 player/...) treated the same. i think fdisk -l should give you what you want and you can grep out the content you dont want.
i am pretty sure îf you are running a live-usb then /dev/sda will be the usb. |
All times are GMT -5. The time now is 11:48 PM. |