restoring real disk partiton to logical volume

Bug #247635 reported by Gene Czarcinski
2
Affects Status Importance Assigned to Milestone
partimage-ng
New
Undecided
Unassigned

Bug Description

The new branches of partimage-ng which support LVM (currently lvm-support and devel-gc1) have a problem when you restore a real disk partition which had grub installed into the partition (sector 0 of the partition).

The real problem is that when grub installs its boot code into sector 0 of the partition, it also puts in a fake partition table and marks the sector as being a "msdos" partition table (label). While an "msdos" partition talbe/label may be valid for the MBR of the disk, it is not really valid for a partition.

Now on real disk partition but it causes problems when such a "grubified" partition is restored to an LVM Logical Volume. I am not sure what partimage-ng can do about this itself ... yes, code could be added to zero sector 0 on a Logical Volume after the restore or not restore if it is sector 0 but this is ??

Work around: for now, the work around is to do the restore and then go back an zero-ize sector 0 ... once that is done, the partition can be accessed as normal.

to zero-ize: dd bs=512 count=1 if=/dev/zero of=/dev/mapper/<your_LV>

Revision history for this message
Gene Czarcinski (gene-czarc) wrote :

I have given some thought to how to "fix" this problem and describe what I consider to be a "solution".

First of all, partition restore in imager.cpp simply does not have enough information to determine if the partition is really a Logical Volume or not. The reason is that the device path for a Logical Volume has two forms and both forms are required by the lvm2 package: /dev/mapper/<vg_whatever>-<lv_whatever> and /dev/<vg_whatever>/<lv_whatever>.

Imager's partition restore cannot instantiate a Partition for the restored partition because the kernel becomes confused what a Logical Volume has a "msdos" "label" in sector zero and everything goes downhill from there.

Therefore, the first part of my solution is to add a new public function to PartitionManger's API which can "safely" determineif the partition is a Logical Volume or not ... lets call it "isLV(<partpath>)". isLV() can do:
    device = ped_device_get(partpath.c_str())
and then compare the first 12 characters if "device->path" to "/dev/mapper/" ... if equal, then the partition is a Logical Volume.

Once partition restore in imager.cpp determines if the partition is a Logical Volume or not, then there are the following options if it is a Logical Volume:

1. simply zero out the entire sector 0. [I do not know if any "file system" or "swap" has a sector zero which is not all zeros]

2. read in sector 0, zero out the "msdos" signature in the last two bytes, and write it back out.

3. Have a command line option such as "--zero" or "--nozero" which determines the action to be taken.

I prefer option 1.

Revision history for this message
Gene Czarcinski (gene-czarc) wrote :

I put out a question on the LVM mailing list about this problem.

While there does not seem to be any linux filesystems which use sector 0, GRUB, ntfs and fat32 all have a label (partition table) with the "msdos" signature in sector 0. However, Logical Volumes are not currently bootable.

However, a user could be using an LVM Logical Volume as a "virtual" physical volume for virtualizing software such as vmware or xen. In that case, having an "msdos" label in sector 0 would be valid.

Given this situation, I believe that the best that can be done is:

If a Logical Volume is being restored, issue a warning message if sector 0 has the "msdos" label signature in the last two bytes.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.