diff options
author | Karel Zak | 2016-08-30 12:07:40 +0200 |
---|---|---|
committer | Karel Zak | 2016-08-30 12:07:40 +0200 |
commit | 4db236f7e4b9c54b04cb1bb4e4dcdbdc11aec2cc (patch) | |
tree | 8bf91584f6d072435ad62403ae2bcfffe3ea217b | |
parent | libblkid: remove unused function (diff) | |
download | kernel-qcow2-util-linux-4db236f7e4b9c54b04cb1bb4e4dcdbdc11aec2cc.tar.gz kernel-qcow2-util-linux-4db236f7e4b9c54b04cb1bb4e4dcdbdc11aec2cc.tar.xz kernel-qcow2-util-linux-4db236f7e4b9c54b04cb1bb4e4dcdbdc11aec2cc.zip |
libblkid: ignore empty MBR on LVM device
It's possible to use boot sector and empty MBR on LVM physical volume
to make LVM disk bootable. In this case MBR should be ignored and disk
reported as LVM.
Just for the record, this is ugly non-default LVM setup maintained for
backward compatibility (yes, LVM guys don't like it too).
Unfortunately people still use it. The proper way is to use regular
partitioned disk.
Reported-by: Xen <list@xenhideout.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | libblkid/src/partitions/dos.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index 2a6414025..30e3e9e73 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -146,6 +146,27 @@ leave: return BLKID_PROBE_OK; } +static inline int is_lvm(blkid_probe pr) +{ + struct blkid_prval *v = __blkid_probe_lookup_value(pr, "TYPE"); + + return (v && v->data && strcmp((char *) v->data, "LVM2_member") == 0); +} + +static inline int is_empty_mbr(unsigned char *mbr) +{ + struct dos_partition *p = mbr_get_partition(mbr, 0); + int i, nparts = 0; + + for (i = 0; i < 4; i++) { + if (dos_partition_get_size(p) > 0) + nparts++; + p++; + } + + return nparts == 0; +} + static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag __attribute__((__unused__))) { @@ -201,6 +222,16 @@ static int probe_dos_pt(blkid_probe pr, goto nothing; } + /* + * Ugly exception, if the device contains a valid LVM physical volume + * and empty MBR (=no partition defined) then it's LVM and MBR should + * be ignored. Crazy people use it to boot from LVM devices. + */ + if (is_lvm(pr) && is_empty_mbr(data)) { + DBG(LOWPROBE, ul_debug("empty MBR on LVM device -- ignore")); + goto nothing; + } + blkid_probe_use_wiper(pr, MBR_PT_OFFSET, 512 - MBR_PT_OFFSET); id = mbr_get_id(data); |