Storage

Xen guests can use several types of storage. This page covers the most common options.

File-backed disk images

The simplest storage option is a raw disk image file stored in dom0’s filesystem.

Create an image:

dd if=/dev/zero of=/var/lib/xen/images/myguest.img bs=1M count=20480

This creates a 20 GB sparse file. Use it in a guest configuration with:

disk = [ "file:/var/lib/xen/images/myguest.img,xvda,w" ]

File images are easy to manage and move, but have some performance overhead compared to block devices.

Physical block devices and LVM

For better performance, give guests direct access to a physical block device or a logical volume managed by LVM.

Create an LVM logical volume:

lvcreate -L 20G -n myguest vg0

Use it in a guest configuration:

disk = [ "phy:/dev/vg0/myguest,xvda,w" ]

The phy: prefix tells Xen to use the block device directly. This avoids the filesystem overhead of file images, and lets the guest use the blkback driver rather than the slower drivers (blktap or qdisk) that back file images. File images remain more flexible for snapshots and moving disks between hosts, so the two approaches are often mixed: an LVM volume group for guest disks that need performance, with individual guests still able to use file images where flexibility matters more.

Remote storage

Guest disks can also live on network storage — commonly NFS (as a file image, the same as local file-backed storage but on a mounted network path) or iSCSI (as a block device, the same as local LVM/physical devices once the target is attached in dom0). Both work with the same disk = syntax already shown above; the only difference is where the underlying file or block device comes from. There is nothing Xen-specific to configure — set up the mount or iSCSI initiator in dom0 first, using your distribution’s normal tools.

Distributed storage systems like Ceph (via RBD, as a block device) and GlusterFS (as a file image over its native client or NFS) work the same way, at larger scale — useful once guest disks need to survive a single host failing rather than just living on that host’s network share.

Accessing a guest disk image from dom0

To inspect, repair, or copy files out of a guest’s disk without booting it, mount it from dom0 with kpartx, which works the same way for a raw file image or an LVM volume:

kpartx -a /path/to/guest.img
mount /dev/mapper/loop0p1 /mnt

kpartx -l lists the partitions first if you’re not sure which one you need. When you’re done, unmount it and remove the mappings with kpartx -d /path/to/guest.img — don’t do this while the guest is running, since dom0 and the guest writing to the same disk at once will corrupt it.

Disk configuration format

The general format for a disk entry is:

"source,target,access"
source

The storage source: phy:/dev/... for a block device, file:/path/to/... for a file image.

target

The device name seen by the guest: xvda for a paravirtualized disk, hda for an emulated IDE disk (HVM only).

access

w for read-write, r for read-only.

Multiple disks can be listed:

disk = [ "phy:/dev/vg0/root,xvda,w",
         "phy:/dev/vg0/data,xvdb,w",
         "file:/path/to/installer.iso,xvdc:cdrom,r" ]