Episode: 2766
Title: HPR2766: Disk enumeration on Linux
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2766/hpr2766.mp3
Transcribed: 2025-10-19 16:33:23

---

This in HPR episode 2007-166 entitled Disc enumeration on Linux.
It is hosted by Klaatu and in about 24 minutes long and carry a clean flag.
The summary is Klaatu renews the various commands used to enumerate live on Linux.
This episode of HPR is brought to you by Ananasthost.com.
Get 15% discount on all shared hosting with the offer code HPR15.
That's HPR15.
Better web hosting that's honest and fair at Ananasthost.com.
Hey everyone, this is Klaatu.
You're listening to Hacker Public Radio and this is how to enumerate discs on Linux.
This is something that I feel has evolved over time and it's something that I'm kind of covered in another show
that I do called Gnu World Order. It's a different podcast and I'm kind of repeating content for Hacker Public Radio which I don't normally do.
I try to keep the two shows rather separate but this experience on Gnu World Order really sort of opened up my eyes to house some old unixie utilities that maybe I learned 10 years ago now have better versions now.
They've maybe not become deprecated, they've maybe not become improved but there are newer things that possibly are a little bit more useful than the ones that I knew.
So for instance it's a pretty common thing in Linux to need to or want to know where a device has been attached or what a device is called on the system.
Now I understand on Windows for instance there are device letters that somehow get assigned and I'm not clear on what those are.
I mean I know what the letters are. There's A and B and C and D and E and F and all the way through Z. I'm assuming I don't know how those get assigned.
I understand that C is I think the first assignable drive for whatever reason where it's the boot drive or something like that.
And on Linux it's similar to that in principle and the idea being there are devices that are attached that are block devices that are attached to your computer and they get assigned some designation.
So there's slash dev slash SDA SDB SD SD SD SD D and so on SD being the the the term that this group of or that this device group inherited after the original HD I think original HD a HD B HD B HD C and so on.
I don't remember what H was supposed to stand for probably your hard drive A maybe I don't know I'm making that up and then SD I think came along when scuzzy drives became prevalent or something like that.
And and you'll see other ones VDA VDB VDC for virtual disk in a virtual machine sometimes. So it doesn't really I mean it's just a bunch of designators really and as long as you know that the things exist that that the designator exists.
And you know that that's where the the devices attached and there I should even mention like others like MMC BLK for SD cards sometimes.
So it's there's it's not necessarily I guess what you would call standard although I mean there it's standardized but it's not it's not necessarily completely predictable and it can't really be because it depends on how your computer or what the how the operating system parses.
What is physically attached to it. So there are times where you need to know what those things you know what has been just attached to your computer if you've plugged in a thumb drive for instance and you want to put an up a bootable operating system on that thumb drive.
For instance then you need to know which where that thumb drive is located and so that you can target it effectively or it doesn't even have to be a thumb drive really you could maybe rebooted.
Your computer say that you can install a Linux onto that computer the problem is you don't know which drive you want to install it onto or you don't know the drive really and maybe there are if it's a desktop or a laptop with several drive days maybe you want to install it onto one drive but not the other and so on.
So there are reasons that you need to know where drives are and I feel like in the old days there were some sort of rules of thumbs on how to on how to determine those designators and there are some new tools that make it maybe even easier to determine where those things are and certainly to interact with them.
So the most basic sort of flipping this on its head of saying oh there are some new really new tools that you can use I'm going to kind of start at the basic I won't go too deep into detail because that's that is as I say not the point but if you do like an LS on LS space if you open a terminal and then just as a normal user just LS space slash dev slash that's DEV and then slash.
And then for instance sd and then maybe an asterisk then you'll get a list of drives that are or block devices should say that are that that your computer can can detect now right now I've got everything from sda sda one sda two sdb sdc sdc one all the way up to sdf one and the principal here is that the device itself gets the designations or devs sda for instance.
And then the partitions within that device are labeled numerically so you have sda one sda two being probably like a a boot partition and maybe a home partition or something like that something even more partition would be my sdd drive which sdd one sdd two three four so I've got I know that one of those is my home one of those is my var when one of those my temp and so on so that's just kind of that's the that's what's going on.
And that is certainly one way to to to determine where things are located right if you do an LLS slash dev slash sd asterisk then you see that you've got all those devices and then if you plug in I'm going to grab a thumb drive for demonstration purposes here.
So if you plug in a thumb drive so you've done your LLS on dev slash sd asterisk then you plug in a thumb drive for instance and then you do it again well now I have an sdg item in elisted in the results.
If I compare my new results to my old results the old results stopped at sdf the new result goes all the way up to sdg I think I know where my thumb drive that I've just plugged in to my computer is located and that would of course be sdg.
Okay so that's that's kind of one way to to to learn that information and and it is it is functional it does it does sort of it does the job.
There's another kind of old school method I feel and that is the tool f disk.
So f disk is I don't know actually what that stands for f disk manipulate disk partition table it's just f disk I don't know if it stands for anything at all.
So anyway f disk dash dash list provides a rather verbose listing of all the all the disks attached to your system.
It is pretty useful if you do f disk dash dash list and then pipe it to less for instance you'll see that it starts out well at least mine starts out with some ram disks dev ram one two three four five six seven eight nine while there's a bunch of them those are all auto generated I didn't make those.
And then there are things like dev sdc and it tells you well that's 111.8 gigabytes this many bytes this many sectors the units are sectors of one times 512 for 512 bytes sector size logical physical 512 bytes and so on and so on and it gives you a unique ID gives you the disk identifier it tells you the disk label type a GPT or I guess the other ones probably yeah DOS and then it kind of breaks down the partitions within those.
So there's dev sdc 1 starts at 2048 ends at 206 847 it is an EFI system partition and sdc 2 starts at 206 848 and goes all the way up and it's 111.7 gigabytes and it's the Linux file system and so on so you get that for every single device plugged into your attached to your computer right now.
And so that's pretty useful that's some pretty good output there really what you'll notice is not included in this in this output is whether or not any of those are actually currently mounted for instance so these these drives may are clearly attached to your to your drive but are they are the active are they mounted anywhere on your system.
So I'll tell you that kind of information it's very much just sort of the almost a forensic tool you know it's at that level of detail so that's F disk so exit out of route for that that's a good one now some of the newer tools that I've kind of discovered more recently and I don't know if that's because they are new tools or because it's just because nobody ever talked about them but these are good ones.
So LSBLK is a really really useful useful one oh you know what actually before we get into LSBLK I should just mention mount because mount if you just type in mount it tells you what drives are currently mounted on your system and so that's a very good breakdown of what's actually in use so for instance I just typed in mount and it looks like slash dev slash sdc 2 is my route partition says on slash so it's mounted at the beginning of my my file system.
Type EXC4 proc on slash proc sysfs on slash sys and so on here slash dev slash sdd 1 on var sdd 2 on temp sdd 3 on opt sdd 4 on home and then sdc 1 on slash boot slash EFI type fat V fat and then some other stuff about some virtual user fuse file systems rather so there you go.
That's that's mount and that is useful but the other one that I've the newer ones that I've found are for instance LSBLK if you type that in it tells you each the name of each device so under name it's sda and then under sda it shows me that there's an sda one and sda to sdb sdbc 1 and 2 and so on in addition to that in in in other columns it tells me information such as the size.
Of the drive so that's really really handy it just kind of gives you a nice little summary right there so sda sda is a 2.7 terabyte drive sda 1 being 23.3 gigabytes and sda 2 being 2.7 terabytes are they mounted well it tells you well what type is it so this is a disk it tells you sda is a disk and then sda 1 and 2 it tells you is if those are part partitions and then is it mounted well this is this is not sda sda is not mounted right now.
So then there's sdb that's not mounted either sdc is mounted it is again sdc 1 is slash boot slash EFI it is 100 megabytes in size it is a partition sdc 2 is 111.7 it is mounted as as root so there's a nice breakdown of of everything that is attached and everything that is.
Mounted or not mounted so now if I take out my sample thumb drive here then I get lsplk and it stops once again sdf meaning that yes indeed the thumb drive that I plugged in was sdg so that's useful because it it confirms i'm gonna plug it back in now confirms that the the thing that you are.
Possibly targeting is the thing that you think it is tells you where that is and it also tells you the size so if I happen to know that I've got an 8 gigabyte thumb drive here and I'm plugging it into my computer then I get to see that yeah a new entry has has been added sdg and sdg 1.
It is a disk and a partition and the total size is 7.5 gigabytes so that's just kind of extra confirmation especially if you have a couple of thumb drives you know if you got one 8 gig you got 164 gig whatever.
Then you can really zero in on something I mean arguably if you're doing something very destructive you should have as few things plugged into your system as possible just to really really avoid mistakes and I encourage you to take that to heart but that's not always possible so having that extra level of confirmation yes this is a thumb drive this is 8 gigabyte it's it's really truly the one that you think it is I mean the only thing that could possibly be better is if the thumb drive had an LED on it.
And I was able to flash the LED that is not true with that particular thumb drive anyway so I don't even know if that's within the scope of being able to be wished for.
So that's the LSBLK command it is it's it's pretty useful I use it pretty much all the time and I kind of just use it like that LSBLK.
Now there are a bunch of different there are lots of different options that you can use along with it to get more information so for instance LSBLK-F or the long the long command is dash dash F S so that's output outputs info about file systems.
And what that does is it tells you the FS type it tells you will label if there is a label and it tells you the UUID and of course the mount point as well.
So in this case I've got my SDG thumb drive here and and that's kind of nice because it tells me that the SDG thumb drive itself is so the partition table for for or the yeah the partition table for SDG rather the
FS type for the SDG drive itself is UDF I don't know why I did that this is just something that I made quickly for this demo so yeah it's kind of interesting to see what kind of remnants I left behind.
The label is BSD because the thumb drive itself if you were to see it in person it says it's a BSD foundation USB drive so it's got so it was labeled USB and I never bothered changing that.
Then SDG1 the partition is file assistant EXC4 and its label is white 8 GB because it is physically it's colored white it is 8 GB.
And so sometimes looking at this kind of information gives you maybe more information than than even what you're looking for like for instance I didn't I didn't think that I might have left a bunch of craft on here from from when it was a UDF drive.
I just assumed that I'd made a EXC4 drive but obviously I had not so now I know and then that could cause problems for compatibility and stuff in theory so that that's something to know about and it's something useful.
You can also get you can also control well you can certainly do full device paths which is kind of interesting so that sort of explicitly tells you yes this is that slash dev slash SDA.
And you can also get all of this information formatted as JSON you can get it in key value pairs and so on.
So kind of a useful command and man LSBLK will give you lots of different options if you want them.
In other words it is not a it's not one of those super basic commands that it is it's it's got a couple of niceties in there that you might be able to to use.
Okay so including sorting you can sort by specific columns and stuff like that so yeah there's a lot of good options there so that's LSBLK.
And then I think the one that I'm probably most excited about and this is kind of the one that made me think to do this episode itself is called UDISKS.
So on my system for whatever reason UDISKS I have two UDISKS installed I have UDISKS 1 and UDISKS 2.
UDISKS 1 gives you a command called UDISKS and that is just the letter U and then the word discs UDISKS.
UDISKS 2 the the package that got installed is it provides a different command called UDISKS control or UDISKS CTL I guess.
So they're really really similar and I have to admit that I honestly prefer the first UDISKS that back command.
The interactivity of that command or I guess the yeah the way that you interact with it is to me a lot more reasonable but maybe it's just my use case I don't know.
But I'm going to go through really quickly some of the nice things about UDISKS which again I apologize I've actually done this on a new world order already.
If you've already heard it you can skip ahead a little bit or you can just just bear with it because it won't take too much time.
So UDISKS can be used as a user which I think in itself is significant because a lot of kind of disc interaction software that it requires you to have root permissions.
And at least on my system with with my groups and I'm in things like users I'm in plug dev is probably the one that gives me access to all this stuff I would have to verify that but I'm assuming that's what that's for.
I mean certainly plug dev is for for other UDev stuff so I think it's probably for this as well.
So UDISKS as normal user dash dash monitor space slash dev drops you down into kind of a monitoring mode as the name suggests or as the sub command the option suggests.
And if you for instance plug a drive into the computer then it tells you hey you've just plugged in a drive at dev SDG or SDH or whatever it has detected.
So that's really useful for dynamically getting confirmation that when you plug that thumb drive in or that hard drive in that is exactly the designation that it has earned.
Press control C to get out of there and if you if you're not can't remember what you just saw or whatever you can do in a numerate UDISKS dash dash enumerate and that lists all the drives for you.
It does so in a completely non-sorted way I don't really know why it's why it can't sort it correctly there but if you pipe it through sort then you get it in a nice normal kind of flow and SDA SDA 1 2.
DC and so on down to G1 for me so there you get confirmation of of well the same sort of thing that you got from listing the slash dev directory or doing LSBLK.
And admittedly this isn't all that much more information but at least you can just kind of it's a good way to get a list just a raw list of what is plugged in.
You can do a similar thing which is dash dash show dash info on a device and get all kinds of information about that.
So this is sort of similar in functionality to the FDISK dash dash list although I'm doing it on one device and it gives you all kinds of information about it including the device file.
So that's slash dev slash SDG1 you get the the device by ID by path when it was attached or when it was detected anyway you get what the label is if there's a label what kind of file system is there the block size the size of the disk and so on so it's really pretty good analog to FDISK dash dash list.
So here's the cool thing though if I do you disks and then dash dash mount slash dev slash SDG1 it mounts the drive for me at slash media slash white 8 GB without me having to create that mount point.
That is not a mount point that I've ever made that's just something that it dynamically created for me and it has attached to the drive there so if I open up a file manager I can go to I can look for the drive.
Here it is white 8 GB and there it is it's in slash media white 8 GB and I can click around look at files and it's all there just as one would expect and that's that's all done as a as a normal user that there's no root files no root permissions required or used so far.
You can do the opposite which is you disk dash dash unmount slash dev slash SDG1 and that does exactly what you would expect it to do which is to unmount the that device.
Those are obviously all commands and there are quite a few good little gooey disk tools that you could use.
There's certainly G parted which is pretty powerful. There's KDE partition manager for KDE and then there's GNOME disks which is quite nice as well.
So if you're just not sure what you're seeing on a command line can't can't quite make heads or tails of all the strings of letters and locations and paths then sometimes using a gooey tool is just easier.
You can kind of visualize and really see what the computer is I'll say consciously aware of meaning that sometimes on the on in a terminal you'll see stuff that now you can confirm that the thing is there that doesn't mean the computer is agreeing with you or at least the part of the computer that you maybe normally interact with.
So maybe something isn't being read correctly it's great to be able to see to confirm through U disks or through LS block or whatever that yes that drive is there it doesn't necessarily mean that that drive is being recognized by parts of the computer that you want to use it with.
So that's sometimes kind of a good thing to fall back on as well all the gooey programs again those are G parted KDE partition manager and GNOME disks.
There are lots of other great tools for disk identification and disk manipulation I haven't covered them all I'm really just trying to favor the ones that I think are probably the most immediately useful and the most immediately useful frankly I think is is U disks I think that ones are really useful tool to have especially since you can do it all from the user rather than going through root which maybe that matters maybe it doesn't just comes depends on your setup but I find that pretty handy.
But hopefully this has taught you about maybe a new tool or two or a new trick here and there if you have any other cool disc related tips and tricks be sure to record an episode and tell everyone about it thanks for listening.
You've been listening to hecka public radio at hecka public radio dot org we are a community podcast network that release the shows every weekday Monday through Friday.
Today's show like all our shows was contributed by an HBR listener like yourself if you ever thought of recording a podcast then click on our contributing to find out how easy it really is.
Hecka public radio was founded by the digital dog pound and the infonomicon computer club and it's part of the binary revolution at binwreff.com.
If you have comments on today's show please email the host directly leave a comment on the website or record a follow up episode yourself unless otherwise stated today's show is released on the creative comments, attribution, share a light 3.0 license.
Thanks for watching.
