Staring into the Void - Need Help Listing Disk Names

jardows

[H]ard|Gawd
Joined
Jun 10, 2015
Messages
2,015
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?
 

Nobu

Supreme [H]ardness
Joined
Jun 7, 2007
Messages
5,917
`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`.
 

Nobu

Supreme [H]ardness
Joined
Jun 7, 2007
Messages
5,917
`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.
 

jardows

[H]ard|Gawd
Joined
Jun 10, 2015
Messages
2,015
`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.
 
Top