How to attach and mount Xen DomU’s disk to Dom0
Attaching and Mounting Xen DomU Disks in Dom0
There are times when you need direct access to a DomU’s disk from Dom0—for recovery, backup, or maintenance. This is straightforward with Xen’s block device tools, though the commands have evolved depending on your Xen version.
Attaching the Disk
The method depends on which Xen toolstack you’re using.
With xl (Xen 4.1+, recommended):
xl block-attach Domain-0 phy:/dev/vg_xen/vm-10.1.1.228 xvda w
With xm (older Xen, deprecated):
xm block-attach Domain-0 phy:vg_xen/vm-10.1.1.228 xvda w
The format is:
phy:— physical device backend/dev/vg_xen/vm-10.1.1.228— LVM volume path (or raw partition like/dev/sda1)xvda— device name as it will appear in Dom0w— read-write mode (rfor read-only)
Discovering Attached Partitions
After attaching, the block device should appear as /dev/xvda. To see available partitions:
lsblk /dev/xvda
# or
fdisk -l /dev/xvda
# or
parted /dev/xvda print
For example, if the DomU had /dev/xvda1 as /boot and /dev/xvda2 as /, you’ll see:
xvda
├─xvda1 512M
└─xvda2 19.5G
Mounting the Partition
Create a mount point and mount the partition:
mkdir -p /mnt/xvda2
mount /dev/xvda2 /mnt/xvda2
If the filesystem is damaged or needs checking first:
fsck -n /dev/xvda2 # Read-only check
fsck /dev/xvda2 # Fix errors
mount /dev/xvda2 /mnt/xvda2
For read-only access (safer when you’re just examining):
mount -o ro /dev/xvda2 /mnt/xvda2
Unmounting and Detaching
When done, unmount cleanly:
umount /mnt/xvda2
If the device is busy, find what’s using it:
lsof /mnt/xvda2
fuser -m /mnt/xvda2
Then detach the block device. With xl:
xl block-detach Domain-0 xvda
Or with xm:
xm block-detach Domain-0 xvda
You can also use the device ID shown in xl block-list Domain-0:
xl block-list Domain-0
# Output: Name ID State ...
xl block-detach Domain-0 0 # ID instead of device name
Working with Multiple Partitions
If you need multiple partitions mounted simultaneously, attach them with different device names:
xl block-attach Domain-0 phy:/dev/vg_xen/vm-10.1.1.228 xvda w
xl block-attach Domain-0 phy:/dev/vg_xen/vm-10.1.1.229 xvdb w
mount /dev/xvda1 /mnt/vm1
mount /dev/xvdb1 /mnt/vm2
Then detach each one separately when done.
Common Issues
Device already in use: If a DomU is currently running and using the disk, attaching will fail or cause corruption. Always shut down the DomU first:
xl shutdown vm-name
xl destroy vm-name # If shutdown hangs
Stale block device: After detaching, if /dev/xvda still exists, scan for changes:
echo 1 > /sys/block/xvda/device/delete
LVM not found: Ensure the LVM volume group is available in Dom0:
vgs
lvs
If the VG isn’t visible, activate it:
vgchange -ay vg_xen