There's any way to detect if a block device, like /dev/sda or /dev/sdc, is related to a local disk (scsi or sata I mean) or to a removable USB disk?
I'm writing a shell script that have to detect ONLY local disks block devices, excluding any removable disks.
Thanks!
You can use udev, the Linux device manager.
Querying for each block device will show several informations about it, including the bus, which you can use in order to discern if the device is a removable USB one.
This is the script:
for device in /sys/block/sd*; do
device_info="$(udevadm info --query=property --path=$device)"
device_name=$(echo "$device_info" | perl -ne 'print "$1" if /^DEVNAME=(.*)/')
device_bus=$(echo "$device_info" | perl -ne 'print "$1" if /^ID_BUS=(.*)/')
echo "Device $device_name bus: $device_bus"
done
and this is a sample result:
Device /dev/sda bus: ata
Device /dev/sdb bus: ata
Device /dev/sdc bus: usb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With