This is an old revision of the document!
Table of Contents
XEN Debian 8 appliance
This installation process demonstrates how to set up Xen on debian. It doesn't go into great detail and only gives a general overview.
The process is to install Debian 8 with an official CD image and then remove and replace systemd after installation.
Debian 8 installation
Boot the image to perform the installation process and select `Install'.
From the language selection pages I chose the following.
English => United Kingdom => British English
After loading components from the CD, we enter some basic but essential host information.
hostname: xen domain name: example.com root password: XXX full name of new user: ABC XYZ username: ABC password: XXX
The next step is partitioning. Initially we choose Guided partitioning and after edit the automatic choice for the root partition.
Guided Partitioning - use entire disk and set up LVM All files in one partition (recommended for new users) Write the changes to disks and configure LVM? YES
Do not select finish just yet, go up the menu.
Configure the Logical Volume Manager Write the changes to disks and configure LVM? YES Delete Logical Volume root Create Logial Volume xen-vg Logical Volume Name root Logical Volume Size 8GB Finish
Inspect the partition list and select the root entry created above.
LVM VG xen-vg, LV root - 8.0 GB Linux device-mapper (linear) #1 Use-as: Ext4 journaling file system Mount point: / Mount options: [x] noatime Label: root Reserved Blocks: 1% Typical usage: standard Done setting up the partition
Finally, we finish creating the disk layout.
Finish partitioning and write changes to disk Write the changes to disks? YES
After some time installing the base system, the package selection process will begin.
First select a mirror, I chose UK.
United Kingdom => ftp.uk.debian.org Continue
Wait for some time.
Participate in the package usage Survey? NO
Finally we reach the software selection menu.
It's important to deselect every entry using the space bar and only select ssh server.
[*] SSH server Continue
Once installation is done the boot loader is installed and we are finished.
Install the GRUB boot loader to the master boot record? YES
Remove the ejected CD.
Installation complete Continue
Debian 8 update
Login, update the system and then reboot it.
apt-get update apt-get dist-upgrade reboot
Debian 8 sysvinit
If you used an official installation source then login and replace systemd with sysvinit.
This process may also be applied (later) to any virtual machines other than domain 0.
apt-get install sysvinit-core sysvinit sysvinit-utils
If this is a VM, configure the following.
- sshd root login (if required)
- inittab getty hvc0
Now reboot, login again and finish the job off.
apt-get remove --purge --auto-remove systemd /bin/echo -e 'Package: systemd\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemd /bin/echo -e '\nPackage: *systemd*\nPin: origin ""\nPin-Priority: -1' >> /etc/apt/preferences.d/systemd /bin/echo -e '\nPackage: systemd:amd64\nPin: origin ""\nPin-Priority: -1' >> /etc/apt/preferences.d/systemd /bin/echo -e '\nPackage: systemd:i386\nPin: origin ""\nPin-Priority: -1' >> /etc/apt/preferences.d/systemd
XEN Debian 8 installation
Install Xen kernel and tools.
apt-get install --no-install-recommends xen-linux-system xen-tools lvm2 bridge-utils dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen echo 'GRUB_CMDLINE_XEN="dom0_mem=512M"' >> /etc/default/grub update-grub
Here is an example set up for an Ethernet bridge.
Edit the interface file.
vi /etc/network/interfaces
Change the IP addresses for your host and network.
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto xenbr0 iface xenbr0 inet static bridge_ports eth0 address X.X.X.X netmask 255.255.255.X gateway X.X.X.X
Finally, reboot into Xen.
reboot
XEN VM installation
Using the Xen tools we create a Debian Wheezy virtual machine with 1GB RAM and 16GB disk space.
xen-create-image --cache=yes --fs=ext4 --memory=1GB --size=16G --swap=1G --vcpus=1 --gateway=X.X.X.X --ip=X.X.X.X --netmask=255.255.255.X --hostname=vm0 --lvm=xen-vg --dist=wheezy
The creation process will take some time, outputting the following.
General Information -------------------- Hostname : vm0 Distribution : wheezy Mirror : http://ftp.uk.debian.org/debian/ Partitions : swap 1G (swap) / 16G (ext4) Image type : full Memory size : 1GB Kernel path : /boot/vmlinuz-3.16.0-4-amd64 Initrd path : /boot/initrd.img-3.16.0-4-amd64 Networking Information ---------------------- IP Address 1 : X.X.X.X [MAC: XX:XX:XX:XX:XX:XX] Netmask : 255.255.255.X Gateway : X.X.X.X Creating swap on /dev/xen-vg/vm0-swap Done Creating ext4 filesystem on /dev/xen-vg/vm0-disk Done Installation method: debootstrap Running hooks Done No role scripts were specified. Skipping Creating Xen configuration file Done No role scripts were specified. Skipping Setting up root password Generating a password for the new guest. All done Logfile produced at: /var/log/xen-tools/vm0.log Installation Summary --------------------- Hostname : vm0 Distribution : wheezy MAC Address : XX:XX:XX:XX:XX:XX IP Address(es) : X.X.X.X RSA Fingerprint : XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX Root Password : XXXXXXXXXXXXXXXXXXXXXXX
XEN VM maintenance
List VM images.
xen-list-images Name: vm0 Memory: 1024 MB IP: X.X.X.X
Run VM with a console.
xl create -c /etc/xen/vm0.cfg
Run a VM silently without a console.
xl create -q /etc/xen/vm0.cfg
Attach a console to a running VM.
xl console vm0
List VMs.
xl list Name ID Mem VCPUs State Time(s) Domain-0 0 512 2 r----- 313.4 vm0 2 1024 1 -b---- 5.5
Shut down VM.
xl shutdown vm0
Auto-start a VM at boot time.
mkdir -p /etc/xen/auto ln /etc/xen/vm0.cfg /etc/xen/auto
XEN LVM disk maintenance
If we shut down a VM we can perform disk maintenance on it's virtual disk from Domain 0.
First ensure that the target VM is off-line. Here we only have 1 VM so our output only shows Domain 0 and our target vm-0 is not running.
xl list Name ID Mem VCPUs State Time(s) Domain-0
Now inspect the volumes for our target.
lvs | grep vm0 vm0-disk xen-vg -wi-a----- 16.00g vm0-swap xen-vg -wi-a----- 1.00g
We will increase the size of the virtual disk and leave swap alone.
lvextend --size 24G /dev/xen-vg/vm0-disk Size of logical volume xen-vg/vm0-disk changed from 16.00 GiB (4096 extents) to 24.00 GiB (6144 extents). Logical volume vm0-disk successfully resized lvs | grep vm0 vm0-disk xen-vg -wi-a----- 24.00g vm0-swap xen-vg -wi-a----- 1.00g
We must extend the size of the file system contained in the volume.
First check the disk for errors.
fsck -fy /dev/xen-vg/vm0-disk fsck from util-linux 2.25.2 e2fsck 1.42.12 (29-Aug-2014) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/xen--vg-vm0--disk: 15147/1048576 files (0.4% non-contiguous), 226267/4194304 blocks
And now resize it.
resize2fs /dev/xen-vg/vm0-disk resize2fs 1.42.12 (29-Aug-2014) Resizing the filesystem on /dev/xen-vg/vm0-disk to 6291456 (4k) blocks. The filesystem on /dev/xen-vg/vm0-disk is now 6291456 (4k) blocks long.
The VM can now be restarted with an increased disk capacity.
root@vm0:~# df -h / Filesystem Size Used Avail Use% Mounted on /dev/xvda2 24G 499M 22G 3% /
XEN LVM swap maintenance
We may discover that a choice for a swap partition size was incorrect so we may resize it.
In this example we will resize the Domain 0 swap partition but we can also resize the swap partition of a VM in a similar fashion.
First we take the swap partition off-line.
cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 6361084 0 -1 swapoff -a
Now we inspect the volumes.
lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root xen-vg -wi-ao---- 7.45g swap_1 xen-vg -wi-a----- 6.07g vm0-disk xen-vg -wi-a----- 16.00g vm0-swap xen-vg -wi-a----- 1.00g
We can reduce the size of an off-line swap partition with no dangerous side-effects, this wouldn't be true if it were a data partition.
lvreduce --size 2G /dev/xen-vg/swap_1 WARNING: Reducing active logical volume to 2.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce swap_1? [y/n]: y Size of logical volume xen-vg/swap_1 changed from 6.07 GiB (1553 extents) to 2.00 GiB (512 extents). Logical volume swap_1 successfully resized
We can also increase the size, for example, if the above step was incorrect.
lvresize --size 5G /dev/xen-vg/swap_1 Size of logical volume xen-vg/swap_1 changed from 2.00 GiB (512 extents) to 5.00 GiB (1280 extents). Logical volume swap_1 successfully resized
Now we rebuild the swap.
mkswap /dev/xen-vg/swap_1 mkswap: /dev/xen-vg/swap_1: warning: wiping old swap signature. Setting up swapspace version 1, size = 2097148 KiB no label, UUID=3ac8493d-4dee-4309-9a01-953560ede126
And remount it.
swapon -a cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1