Skip to contentSkip to conversation

how to determine if /dev/... is an LV?

linux-lvm Brian J. Murrell 7 participants 7 messages Aug 22, 2001 – Aug 23, 2001

lore
Share & tools
lore
#0 lore raw

Hi all,

This should hopefully be simple. I am modifying some code to deal with LVM. If I am given a device path for an LV, say, /dev/VG/1, programatically, how can I determine that it actually is an LV and not some other kind of device? The best I have come up with is:

lvdisplay -D -c /dev/VG/lvol1 2>&1 | grep "^/dev/VG/lvol1" >/dev/null

and testing "$?".

Seems kind of "hacky" though. Is there a better way?

Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

Thanx,
b.

Signature · 1 line
Brian J. Murrell
#1 lore raw

Well,

You could always check the major number of the device file with the one in /proc/devices, and see whether it is the major number of the lvm driver. Then check whether the minor number is that of a valid logical volume (not 0).

++Jos

And thus it came to pass that Brian J. Murrell wrote:
(on Wed, Aug 22, 2001 at 03:44:25AM -0400 to be exact)

Quoted 27 lines

Hi all,

This should hopefully be simple. I am modifying some code to deal with LVM. If I am given a device path for an LV, say, /dev/VG/1, programatically, how can I determine that it actually is an LV and not some other kind of device? The best I have come up with is:

lvdisplay -D -c /dev/VG/lvol1 2>&1 | grep "^/dev/VG/lvol1" >/dev/null

and testing "$?".

Seems kind of "hacky" though. Is there a better way?

Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

Thanx,
b.

Signature · 7 lines
Brian J. Murrell

_______________________________________________
linux-lvm mailing list
[email protected]
http://lists.sistina.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://www.sistina.com/lvm/Pages/howto.html
Signature · 1 line
Fear the Muppet! Winner of the HAL2001 Hacker Quiz...
#3 lore raw
In reply to José Luis Domingo López
Quoted 7 lines · José Luis Domingo López
Quoted 4 lines · Brian J. Murrell

Hi all,
[...]
Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

[ snip ]

Quoted 1 line

Hope it helps. Regards,

Well I do apreciate your efforts (thanx!), but no, it doesn't. You told me everything I already knew but nothing of what I didn't. :-) What I mean is what is the relationship of the MINOR number to LVs.

b.

Signature · 1 line
Brian J. Murrell
#2 lore raw
In reply to Brian J. Murrell
Quoted 5 lines · Brian J. Murrell

Hi all,
[...]
Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

As /usr/src/linux/Documentation/devices.txt says:

58 char Hayes ESP serial card - alternate devices
0 = /dev/cup0 Callout device for ttyP0
1 = /dev/cup1 Callout device for ttyP1
...
block Reserved for logical volume manager

109 char Reserved for logical volume manager

That is, LVM has block major number 58 reserved for its own use, as well as char major number 109. One of my machines has LVM installed, with a VG called Grupo00 and two LV, "mp3" and "usr" (ls -l /dev/Grupo00):

total 0

crw-r-----    1 root     disk     109,   0 jun  4 12:33 group
brw-rw----    1 root     disk      58,   0 jun  5 04:48 mp3
brw-rw----    1 root     disk      58,   1 jun  4 17:50 usr

Hope it helps. Regards,

Signature · 5 lines
Jos� Luis Domingo L�pez
Linux Registered User #189436     Debian GNU/Linux Potato (P166 64 MB RAM)
 
jdomingo EN internautas PUNTO org  => � Spam ? Atente a las consecuencias
jdomingo AT internautas DOT   org  => Spam at your own risk
#4 lore raw
In reply to Brian J. Murrell
Quoted 9 lines · Brian J. Murrell
Quoted 7 lines · José Luis Domingo López
Quoted 4 lines · Brian J. Murrell

Hi all,
[...]
Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

Quoted 7 lines

[ snip ]

Quoted 1 line

Hope it helps. Regards,

Well I do apreciate your efforts (thanx!), but no, it doesn't. You told me everything I already knew but nothing of what I didn't. :-) What I mean is what is the relationship of the MINOR number to LVs.

# lvdisplay /dev/vg00/u1
--- Logical volume ---
LV Name                /dev/vg00/u1
<SNIP>
Block device           58:0

The last line of the lvdisplay output contains the block major:minor numbers. Internally the LVM driver uses a minor number addressed table (today) to access a particular LVs in core meteadata.

Quoted 11 lines

b.

Signature · 7 lines
Brian J. Murrell

_______________________________________________
linux-lvm mailing list
[email protected]
http://lists.sistina.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://www.sistina.com/lvm/Pages/howto.html
Signature · 15 lines
Regards,
Heinz    -- The LVM Guy --

*** Software bugs are stupid.
    Nevertheless it needs not so stupid people to solve them ***

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Heinz Mauelshagen                                 Sistina Software Inc.
Senior Consultant/Developer                       Am Sonnenhang 11
                                                  56242 Marienrachdorf
                                                  Germany
[email protected]                           +49 2626 141200
                                                       FAX 924446
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#5 lore raw
In reply to Brian J. Murrell
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also, is there any relationship between the output from the lvdisplay and the minor number for the device?

Yes.

example from lvdisplay for lvol1:
Block device 58:0

major 58: minor:0

If you look at the devices for, you may notice, hey, they match!

crw-r-----    1 root     disk     109,   0 Aug 23 21:00 group
brw-rw----    1 root     disk      58,   0 Aug 23 21:04 lvol1
brw-rw----    1 root     disk      58,   1 Aug 23 21:03 lvol2

other correlation:
all minor numbers for char 109 (group files) are unique across the system. all minor numbers for block 58 (lvols) are unique across the system.

without looking at the source, when it comes to recovering/rebuilding vg info in the file system, I am assuming that lvm doesn't really care about device files when it is recording info into the vg headers (vgda & such), and since the advent of UUIDs, I doubt if it really cares about minor numbers either.

here is an test layout I created just for the heck of it.

I created vga across /dev/sda1 & sda4, vgb on sda2, vgc on sda3. I then lvcreated 3 times on vga,vgb,vgc in turn. [lvcreate -l 1 vg(a-c)] I then lvremoved vga/lvol1.
I then lvcreated 3 times on vga,vgb,vgc in turn. (again)
the lvcreate makes default names for the lvols.

/dev/vga:
total 46

dr-xr-xr-x    2 root     root          161 Aug 23 21:04 .
drwxr-xr-x   17 root     root        46444 Aug 23 21:01 ..
crw-r-----    1 root     disk     109,   0 Aug 23 21:00 group
brw-rw----    1 root     disk      58,   0 Aug 23 21:04 lvol1
brw-rw----    1 root     disk      58,   1 Aug 23 21:03 lvol2
brw-rw----    1 root     disk      58,   2 Aug 23 21:03 lvol3
brw-rw----    1 root     disk      58,   9 Aug 23 21:04 lvol4
brw-rw----    1 root     disk      58,  10 Aug 23 21:04 lvol5

interestingly enough, it recreated lvol1 here on the fourth lvcreate and started with the lowest minor number available (0), even though higher numbers had already been used.

/dev/vgb:
total 46

dr-xr-xr-x    2 root     root          182 Aug 23 21:04 .
drwxr-xr-x   17 root     root        46444 Aug 23 21:01 ..
crw-r-----    1 root     disk     109,   1 Aug 23 21:00 group
brw-rw----    1 root     disk      58,   3 Aug 23 21:03 lvol1
brw-rw----    1 root     disk      58,   4 Aug 23 21:03 lvol2
brw-rw----    1 root     disk      58,   5 Aug 23 21:03 lvol3
brw-rw----    1 root     disk      58,  11 Aug 23 21:04 lvol4
brw-rw----    1 root     disk      58,  12 Aug 23 21:04 lvol5
brw-rw----    1 root     disk      58,  13 Aug 23 21:04 lvol6

/dev/vgc:
total 46

dr-xr-xr-x    2 root     root          182 Aug 23 21:04 .
drwxr-xr-x   17 root     root        46444 Aug 23 21:01 ..
crw-r-----    1 root     disk     109,   2 Aug 23 21:00 group
brw-rw----    1 root     disk      58,   6 Aug 23 21:03 lvol1
brw-rw----    1 root     disk      58,   7 Aug 23 21:03 lvol2
brw-rw----    1 root     disk      58,   8 Aug 23 21:03 lvol3
brw-rw----    1 root     disk      58,  14 Aug 23 21:04 lvol4
brw-rw----    1 root     disk      58,  15 Aug 23 21:04 lvol5
brw-rw----    1 root     disk      58,  16 Aug 23 21:04 lvol6

This was all gone on a SuSE 7.1 system with the stock 2.2.18 kernel. LVM 0.9 13/11/2000 (IOP 10)

Lost in Tokyo,
Keith

P.S. My, what a big e-mail address you have Grandma!

#6 lore raw
In reply to Brian J. Murrell
Quoted 1 line · Brian J. Murrell

lvdisplay -D -c /dev/VG/lvol1 2>&1 | grep "^/dev/VG/lvol1" >/dev/null

lvdisplay -D -c /dev/VG/lvol1 2>&1 | grep -q ^/dev/VG/lvol1 && do whatever you want :-)

Signature · 4 lines
Harald Milz           |     [email protected]     | "He was a modest,
Linux New Media AG    | phone  +49 (0) 89 993411-20 | good-humored boy. It
Stefan-George-Ring 24 | fax    +49 (0) 89 993411-99 | was Oxford that made
D-81929 Muenchen      | http://www.linux-magazin.de | him insufferable."