You are not logged in.
Pages: 1
Had this question: given a block device, how would I reliably determine whether it refers to a disk or a partition?
Found the answer before I could complete my question, and thought I post it here:
$ udevadm info /dev/sda | grep DEVTYPE
E: DEVTYPE=disk
$ udevadm info /dev/sda1 | grep DEVTYPE
E: DEVTYPE=partition
Offline
I'm not sure I understand, but isn't /dev/foo always a disk and /dev/foon always a partition?
Offline
Not a GNU/Linux discussion, moving to NC...
Offline
Turns out that this reports DEVTYPE=disk for partitions inside of an image file, accessed as mapped devices via kpartx:
> kpartx -a imagefile
> udevadm info /dev/loop0 | grep DEVTYPE
E: DEVTYPE=disk
> udevadm info /dev/mapper/loop0p1 | grep DEVTYPE
E: DEVTYPE=disk
lsblk gets it right. I guess I'll do this instead:
> lsblk -o TYPE -n /dev/mapper/loop0p1
part
Offline
I'm not sure I understand, but isn't /dev/foo always a disk and /dev/foon always a partition?
That depends on how much udev magic is in play. OP said "reliably".
Not a GNU/Linux discussion, moving to NC...
This is not really a newbie question... (udevadm is not a newbie tool...).
Regardless, are you really sure you only want partitions? IIRC, it's possible to format a device directly without partitioning.
Steven [ web : git ]
GPG: 327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com
Offline
In 14 years of using Linux, I've never known /dev/sdX do be anything other than a disk and /dev/sdXY anything other than a partition of the disk sdX. I personally would consider this "reliable" but then again your use case may be different from mine.
Offline
Pages: 1