Sometimes we would like to access directly to the data of a XEN virtual machine just mounting the volume that act as physical device in the virtual machine, instead of booting it with a recovery cd, like in case of a faulty change in a configuration file inside the VM.
Be careful!, this must be run stopping first the virtual machine.
Let’s start checking the name of the physical volume containing a linux virtual machine inside (it works with windows data, but check NTFS support in XEN first).
[root@xenserver2 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdc VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678 lvm2 a- 33.91G 0
Now use the name of the VG to check structure:
[root@xenserver2 ~]# lvdisplay VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678 --- Logical volume --- LV Name /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-9c8d7d63-7f81-4542-af59-0b2f82ed11a5 VG Name VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678 LV UUID 3At62f-mVzV-K2W6-S9lw-YloT-oNmQ-UCRwZm LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors 0 Block device 252:2 --- Logical volume --- LV Name /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-04588d2b-9012-4366-9eb5-c36b35c9f731 VG Name VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678 LV UUID mxu7q4-WLrB-2jkr-G48Y-tX1c-NZ9M-AKASs8 LV Write Access read/write LV Status available # open 1 LV Size 12.00 GB Current LE 3072 Segments 1 Allocation inherit Read ahead sectors 0 Block device 252:1 [.................] well, there would be more, let's stop the output here... [.................] --- Logical volume --- LV Name /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9541-0ea04792144d VG Name VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678 LV UUID 2Y0MHV-BZOq-274t-SUq0-MsNo-0Q84-52Kq2d LV Write Access read/write LV Status available # open 2 LV Size 5.00 GB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors 0 Block device 252:5
As the output is only a range of numbers-letters, you can try one by one, or checking LV size to compare it with the one you think is. Let’s try with this already known volume. List the content of the LV with sfdisk partition manipulator.
[root@xenserver2 ~]# sfdisk -l -uS /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9541-0ea04792144d Disk /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9541-0ea04792144d: 652 cylinders, 255 heads, 63 sectors/track Warning: extended partition does not start at a cylinder boundary. DOS and Linux will interpret the contents differently. Units = sectors of 512 bytes, counting from 0 Device Boot Start End #sectors Id System /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 63 9719387 9719325 f W95 Ext'd (LBA) /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 0 - 0 0 Empty /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 0 - 0 0 Empty /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 0 - 0 0 Empty /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 126 1526237 1526112 82 Linux swap / Solaris start: (c,h,s) expected (0,2,1) found (0,1,1) end: (c,h,s) expected (95,0,63) found (94,254,63) /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9 1526301 9719387 8193087 83 Linux start: (c,h,s) expected (95,2,1) found (0,1,1) end: (c,h,s) expected (605,0,63) found (509,254,63)
here is the trick, we must multiply 512 by the start offset of the partition, in our case 1526301 found checking the partition type (83, Linux).
Now mount the device as a full filesystem, note the offset mathematical multiplication.
[root@xenserver2 ~]# mount -o loop,ro,offset=$(( 512*1526301 )) /dev/VG_XenStorage-29311dce-3490-2e6e-1b82-db9b65f2d678/LV-d116c860-f1eb-48eb-9541-0ea04792144d /mnt/ [root@xenserver2 ~]# ls /mnt/ bin dev etc lib opt sbin sys usr boot donkey home lost+found proc root var core mnt tmp [root@xenserver2 ~]# umount /mnt
Remember, the virtual machine should be stopped before do this ;).