This applies to a default (=debian-packages) installation of Xen on “squeeze” using LVM for storage management.
Tested with these package versions:
- xen-hypervisor-4.0-amd64: 4.0.1-5.5
- xen-tools: 4.2-1
Choose a name for the DomU host and select the LVM volume group to be used for the new filesystem:
VM_NAME=“foohost”
LVM_VG_NAME=“raid1_md3”
Assuming a physical extent (PE) size of 256 MB, create a new logical volume with 10GB (= 40 × 256MB).
sudo lvcreate —verbose —extents 40 —name ${VM_NAME}_root $LVM_VG_NAME
Now the DomU can be installed using the following command. The new LV will be used for the root filesystem, the RAM will be set to 1GB and a private IP will be assigned. The xen-create-image
tool will use the current testing
distribution for installation via debootstrap
.
Using the --pygrub
switch is essential, as otherwise the DomU won’t be able to boot (no kernel and bootloader would be installed).
sudo xen-create-image \
—hostname=$VM_NAME \
—image-dev=/dev/$LVM_VG_NAME/${VM_NAME}_root \
—noswap \
—size=10G \
—memory=1024M \
—ip=10.1.23.1 \
—netmask=255.255.255.0 \
—gateway=10.1.23.254 \
—broadcast=10.1.23.255 \
—dist=testing \
—pygrub \
—verbose
Now, create a mount point for the root filesystem and mount it there. This is done since we need to fix the kernel image before we can actually start up the DomU:
sudo mkdir -pv /mnt/domUs/$VM_NAME/root
sudo mount /dev/mapper/$LVM_VG_NAME-${VM_NAME}_root /mnt/domUs/$VM_NAME/root
The above described Xen installation unfortunately can’t boot the bzImage
kernels shipped by Debian (see bugs 519149 and 695056). Therefore we need to extract them and re-compress them with gzip
. For the first part we use a script that is part of the official Linux kernel source tree: extract-vmlinux.
cd /mnt/domUs/$VM_NAME/root/boot/
KERNEL_IMG=$(ls vmlinuz-*-amd64 | tail -n 1)
sudo cp -v ${KERNEL_IMG} ${KERNEL_IMG}.orig
cd /tmp
wget —no-check-certificate https://github.com/torvalds/linux/raw/master/scripts/extract-vmlinux
chmod +x extract-vmlinux
./extract-vmlinux /mnt/domUs/$VM_NAME/root/boot/${KERNEL_IMG} > ${KERNEL_IMG}
gzip ${KERNEL_IMG}
sudo cp -v ${KERNEL_IMG}.gz /mnt/domUs/$VM_NAME/root/boot/${KERNEL_IMG}
Finally, we can unmount the DomU root filesystem and start up the host:
sudo umount /mnt/domUs/$VM_NAME/root
sudo xm create /etc/xen/domUs/${VM_NAME}.cfg —console_autoconnect