How to attach and mount Xen DomU’s disk partitions on Linux without Xen?

How to attach and mount Xen DomU’s disk partitions on Linux without Xen?

You can use kpartx to create devices from the VM disk image (say, ./vmdisk0).

To activate all the partitions in a raw VM disk image:

# kpartx -av ./vmdisk0

This will output lines such as:

add map loop1p1 (253:8): 0 497664 linear /dev/loop1 2048
add map loop1p2 (253:9): 0 2 linear /dev/loop1 501758
add map loop1p5 (253:10): 0 63557632 linear /dev/loop1 501760
add map loop1p6 (253:11): 0 61769665 linear /dev/loop1 64059455

The loop1 is the name of a device file under /dev/mapper which you can use to access the partition. If the raw disk image’s partitions are LVM volumes, you may find the LVM volumes being found by Linux like vg0 here:

# vgs
VG      #PV #LV #SN Attr   VSize   VFree 
HomeLVM   1   1   0 wz--n- 683.59g     0 
vg0       2   2   0 wz--n-  59.75g 29.49g

When you’re done with the partitions (and with filesystems unmounted), you need to remove the devices

# vgchange -an vg0 # not need to do this if you have not LVM
# kpartx -dv ./vmdisk0

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *