Creating a Debian Guest on Xen Using a Partition-Based Filesystem

June 29, 2013 · By Stephen Reese

This guide explains how to create a partition-backed Debian guest for the Xen hypervisor. It assumes that Xen is already installed and that the host, or Dom0, is operational. I have described setting up a Xen hypervisor from source in another post titled Installing Xen on CentOS 6 from source.

Create a partition to store virtual machines on. A partition-based filesystem is used because it generally provides better performance than a file-backed virtual disk.

$ sudo parted /dev/sdb
mklabel gpt
(parted) unit GB
(parted) mkpart VolGroup00 0GB 400GB
(parted) set 1 lvm on
(parted) quit
(parted) p
Model: DELL PERC 6/i (scsi)
Disk /dev/sdb: 3999GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 400GB 400GB VolGroup00 lvm

Initialize the partition as an LVM physical volume and create a volume group for the virtual machines.

$ sudo pvcreate /dev/sdb1
$ sudo vgcreate VolGroup00 /dev/sdb1
$ sudo vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 372.53 GiB
PE Size 4.00 MiB
Total PE 95367
Alloc PE / Size 0 / 0
Free PE / Size 95367 / 372.53 GiB
VG UUID hdCkfh-twnj-Nu2V-FsTe-RsQg-PzlE-5w4QGR

Create a logical volume for the virtual machine.

$ sudo lvcreate -L 10GB -n Wheezy VolGroup00
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup00/Wheezy
LV Name Wheezy
VG Name VolGroup00
LV UUID jQqEFZ-sd39-siY6-kqCZ-l8Lq-UWWk-3f4oh5
LV Write Access read/write
LV Creation host, time host.localdomain, 2013-05-14 12:32:00 -0400
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

Get the latest Debian hd-media. Add the following parameters to the temporary Xen configuration used to boot the Debian installer. After installation, use a second configuration file to boot the installed guest.

kernel = "/scratch/debian/wheezy/vmlinuz"
ramdisk = "/scratch/debian/wheezy/initrd.gz"
extra = "debian-installer/exit/always_halt=true -- console=hvc0"
memory = 512
name = "Wheezy"
vif = ['bridge=br0']
disk = ['phy:/dev/VolGroup00/Wheezy,xvda,w']

Connect to the new guest with a console and perform the installation.

$ sudo xl create -c /etc/xen/install-debian.cfg

Start a guest without a console.

$ sudo xl create /etc/xen/debian.cfg

Leave the console.

To detach from the console, press Ctrl+].

List the instances.

$ sudo xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 2048 1 r----- 237.4
Wheezy 11 512 1 -b---- 6.8

Connect to the console.

$ sudo xl console Wheezy

Leave the console.

To detach from the console, press Ctrl+].