You are not logged in.

#1 2015-02-02 17:02:38

jernst
Member
From: Silicon Valley
Registered: 2014-03-04
Posts: 290
Website

Solved: Disk or partition?

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

#2 2015-02-02 17:34:49

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Solved: Disk or partition?

I'm not sure I understand, but isn't /dev/foo always a disk and /dev/foon always a partition?

Offline

#3 2015-02-02 17:57:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Solved: Disk or partition?

Not a GNU/Linux discussion, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2015-02-02 18:30:16

jernst
Member
From: Silicon Valley
Registered: 2014-03-04
Posts: 290
Website

Re: Solved: Disk or partition?

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

#5 2015-02-02 18:39:31

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: Solved: Disk or partition?

karol wrote:

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".

jasonwryan wrote:

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

#6 2015-02-02 20:19:28

nstgc
Member
Registered: 2014-03-17
Posts: 393

Re: Solved: Disk or partition?

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

Board footer

Powered by FluxBB