Jump to content

Extract partition data from xen image file: Difference between revisions

From TetraWiki
Hemant (talk | contribs)
Hemant (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:




using kpartx utility


# losetup -f -- find unused
== using kpartx utility ==
 
 
# losetup -f    
/dev/loop0
/dev/loop0
'''This shows the avialable physical loop file/device that is unused and can be used to add a loop device
'''


#losetup /dev/loop0 /HDD_500/images/javapostgresql.img
#losetup /dev/loop0 /HDD_500/images/javapostgresql.img
'''Associated the image file to loop file/device
'''


#kpartx -av /dev/loop0
#kpartx -av /dev/loop0
add map loop1p1 : 0 1024000 linear /dev/loop1 2048
add map loop1p2 : 0 60413952 linear /dev/loop1 1026048


#losetup -a                  ---lists all used
add map loop0p1 : 0 1024000 linear /dev/loop0 2048
add map loop0p2 : 0 60413952 linear /dev/loop0 1026048
 
'''This command reads partition tables on specified device and create device
      maps over partitions segments detected'''
 
 
#losetup -a                  [lists all used loop files ]
 
/dev/loop0: [0811]:32571394 (/HDD_500GB/images/javapostgresql.img)
/dev/loop0: [0811]:32571394 (/HDD_500GB/images/javapostgresql.img)
/dev/loop1: [0811]:32571394 (/HDD_500GB/images/javapostgresql.img)


#vgscan
#vgscan
Line 33: Line 46:
  2 logical volume(s) in volume group "VolGroup" now active
  2 logical volume(s) in volume group "VolGroup" now active
   
   
'''activate and  deactivate  VolumeGroupName, or all volume groups if none is specified.'''
#lvs
#lvs
  LV      VG      Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  LV      VG      Attr  LSize  Origin Snap%  Move Log Copy%  Convert
Line 55: Line 70:
#kpartx -d /dev/loop0
#kpartx -d /dev/loop0


#losetup -d /dev/loop0          --delete from used
#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.
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.
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.

Latest revision as of 15:20, 22 February 2014

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[edit]

using kpartx utility[edit]

  1. losetup -f

/dev/loop0

This shows the avialable physical loop file/device that is unused and can be used to add a loop device

  1. losetup /dev/loop0 /HDD_500/images/javapostgresql.img

Associated the image file to loop file/device

  1. kpartx -av /dev/loop0

add map loop0p1 : 0 1024000 linear /dev/loop0 2048 add map loop0p2 : 0 60413952 linear /dev/loop0 1026048

This command reads partition tables on specified device and create device

      maps over partitions segments detected


  1. losetup -a [lists all used loop files ]

/dev/loop0: [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

activate and deactivate VolumeGroupName, or all volume groups if none is specified.

  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. kpartx -d /dev/loop0
  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.