Staring into the Void - Need Help Listing Disk Names

jardows

2[H]4U
Joined
Jun 10, 2015
Messages
2,308
I've been writing some script utilities for hard drives, with the intention of having a non-graphical, quick to boot, text menu-driven system to perform operations such as SMART tests and secure erase. I had been using FreeBSD to develop, but the incompatibility with many HP UEFI implementations makes this not the best choice. I have been looking into Void Linux, as it provides a very basic install with no GUI as I desire.
There are certain commands that I use in the script that are different between Void Linux and FreeBSD, but I have been able to find the counterpart to most. One command I have used that i am having problems with is one that pulls just the drive device names, excluding CD-ROM devices.
On FreeBSD, I can run
Code:
sysctl -n kern.disks
to get output like:

Code:
da0 ada0 cd0

On the Linux installations I have worked with (both Void and Ubuntu) the kern.disks sysctl does not exist, and I cannot find any equivalent. Everything I have found through searching is a utility that returns far more information than I need, and would require complex processing to get just the device names.

Any advise on the best way to extract this information in Linux?
 
`lsblk -o name`
^^ that's about the closest equiv I can think of. May need another option to remove unnecessary formatting, or it might automatically do that if you pipe it into another program like `cat`.
 
`blkid -o device -u filesystem`
^^ would maybe be the closest equiv, omit "-u filesystem" to list all block devices by name, or change it to list what you want. "-u filesystem" lists all block devices which contain a filesystem.
 
`lsblk -o name`
^^ that's about the closest equiv I can think of. May need another option to remove unnecessary formatting, or it might automatically do that if you pipe it into another program like `cat`.
Thanks! This seems to be the best option. I can do "lsblk -o name,type | grep disk" and it returns just the disk names, omitting the partitions, and even omits the cd drive, which is something I need. I've made the updates to my script and it seems to be working.
 
Back
Top