restoring real disk partiton to logical volume
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/
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: get(partpath. c_str() )
device = ped_device_
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.