Jump to content

Extract partition data from xen image file

From TetraWiki

THE ISSUE WAS FACED ON 192.168.1.15 where a virtual machine had boot error :

ERROR: boot loader didn't return any data!

The virtual machine was not getting up so data has to be extracted


GETTING DATA FROM XEN IMAGE FILE

using kpartx utility

  1. losetup -f -- find unused

/dev/loop0

  1. losetup /dev/loop0 /HDD_500/images/javapostgresql.img
  1. kpartx -av /dev/loop0

add map loop1p1 : 0 1024000 linear /dev/loop1 2048 add map loop1p2 : 0 60413952 linear /dev/loop1 1026048

  1. losetup -a ---lists all used

/dev/loop0: [0811]:32571394 (/HDD_500GB/images/javapostgresql.img) /dev/loop1: [0811]:32571394 (/HDD_500GB/images/javapostgresql.img)

  1. vgscan
Reading all physical volumes.  This may take a while...
 Found volume group "VolGroup" using metadata type lvm2


  1. vgchange -ay VolGroup
2 logical volume(s) in volume group "VolGroup" now active

  1. lvs
LV      VG       Attr   LSize  Origin Snap%  Move Log Copy%  Convert
 lv_root VolGroup -wi-a- 27.80G                                      
 lv_swap VolGroup -wi-a-  1.00G    
 
 
  1. mount /dev/VolGroup/lv_root /mnt/data/

NOW you can access your root partition in image on /mnt/data folder


After data is copied unmount the partition

  1. umount /mnt/data/


  1. vgchange -an VolGroup

0 logical volume(s) in volume group "VolGroup" now active

  1. losetup -d /dev/loop0 --delete from used

NOTE: always remember to deactivate the logical volumes with "vgchange -an", remove the partitions with "kpartx -d", and (if appropriate) delete the loop device with "losetup -d" after you are finished. There are two reasons: first of all, the default volume group name for a install is always the same, so if you end up activating two disk images at the same time you'll end up with two separate LVM volume groups with the same name. LVM will cope as best it can, but you won't be able to distinguish between these two groups on the command line.

And secondly, if you don't deactivate it, then if the guest is started up again, you might end up with the LVM being active in both the guest and the dom0 at the same time, and this may lead to VG or filesystem corruption.