Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
doesn't work (and no,
Code:
lshw -disable usb -class disk -short
doesn't work either). I'd say
Quote:
Originally Posted by replica9000
Code:
/usr/sbin/smartctl --scan
would be a better option compared to mine, even though what I came up with can print only hard disks
Code:
#!/bin/sh --
for UDI in $(/usr/bin/hal-find-by-capability --capability storage); do
DEVICE=$(hal-get-property --udi $UDI --key block.device)
[[ $(hal-get-property --udi $UDI --key storage.bus) != "usb" ]] && printf "${DEVICE}\n"
done; exit 0
but this requires udev / HAL (or finding a way to achieve the same with DeviceKit).
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.
Hmmm - interesting.
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.
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)?
I need to write a script that will list all the hard disks in the system.
We (I at least) took you at your word - I don't see any mention of virtual in your initial post.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.