<html>
<center>
</html>
Xen domU manual creation and configuration tutorial
<html>
</center>
</html>
This document will detail the steps needed to successfully create Xen VMs manually using the Debian (6.0) Squeeze distribution, which, at the time of writing, is neither supported by xen-tools nor officially released.
The procedure for installing other distributions will likely be quite similar.
Running a bleeding edge distribution in a VM is often far more likely than also running said bleeding edge distribution as the dom0. In the case of Debian, nothing past Lenny at the time of this writing has stable Xen dom0 support, so the dom0 is likely something older and more stable.
This will not stop us from running what we want in a VM, however.
In the LAIR, our Xen data directory structure is as follows:
/xen /boot /conf /domains /images /save
We configure xen-tools to create new VM images in /xen/domains, and place config files in /xen/conf, then typically migrate the VM images to /xen/images, and make the appropriate corrections in the config file.
Here, will just go make everything correctly from the start.
There are typically 2 images needed for a standard virtual machine- the main disk and the swap.
Here we will make a 4GB disk image:
vmserver:/xen/images# dd if=/dev/zero of=newvm.disk bs=1M count=4096 4096+0 records in 4096+0 records out 4294967296 bytes (4.3 GB) copied, 91.3332 s, 47.0 MB/s vmserver:/xen/images#
We'll also want to make swap (here we'll make a 256MB swap disk):
vmserver:/xen/images# dd if=/dev/zero of=newvm.swap bs=1M count=256 256+0 records in 256+0 records out 268435456 bytes (268 MB) copied, 7.20193 s, 37.3 MB/s vmserver:/xen/images#
Before we can install, we need to put a filesystem or some structure on our disks.
ere we will format our main disk image:
vmserver:/xen/images# mkfs.ext3 -j -O dir_index -v ./newvm.disk mke2fs 1.41.3 (12-Oct-2008) ./newvm.disk is not a block special device. Proceed anyway? (y,n) y fs_types for mke2fs.conf resolution: 'ext3', 'default' Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. vmserver:/xen/images#
And be sure to bless the swap disk:
vmserver:/xen/images# mkswap newvm.swap Setting up swapspace version 1, size = 268431 kB no label, UUID=a22e7d04-d2ea-4a6b-99db-4941c291648f vmserver:/xen/images#
Once created, we can local loopback mount the disk image, and install our distro of choice (since we're going to use squeeze, we'll debootstrap it).
Using a loopback mount, we mount the disk image so we can dump files onto it (ie install).
vmserver:/xen/images# mount -o loop /xen/images/newvm.disk /mnt vmserver:/xen/images#
Once mounted, proceed with the installation:
vmserver:/xen/images# debootstrap squeeze /mnt http://mirror/debian I: Retrieving Release I: Retrieving Packages I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages... I: Resolving dependencies of base packages... I: Found additional required dependencies: insserv libbz2-1.0 libdb4.8 libslang2 I: Found additional base dependencies: libnfnetlink0 libsqlite3-0 libudev0 I: Checking component main on http://mirror/debian... I: Retrieving libacl1 I: Validating libacl1 I: Retrieving adduser I: Validating adduser I: Retrieving apt-utils I: Validating apt-utils I: Retrieving apt I: Validating apt ... I: Configuring tasksel-data... I: Configuring tasksel... I: Base system installed successfully. vmserver:/xen/images#
Once we're done with the install, we should tend to some configuration matters.
Debian systems use /etc/network/interfaces for network configuration… if we're gunning for a standard VM, we'll want something like this (could likely just copy it from the VM server):
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp
Debian's package management system builds its database from repositories configured in /etc/apt/sources.list; we should be mindful to set the VM's sources.list to use any local services (such as our in-lab repository).
##################################################################### # # /etc/apt/sources.list # deb http://mirror/debian squeeze main contrib non-free deb-src http://mirror/debian squeeze main contrib non-free #deb http://mirror/security squeeze/updates main contrib non-free #deb-src http://mirror/security squeeze/updates main contrib non-free deb http://mirror/lair squeeze main
In many cases this could also be straight copied from the VM server (but remember to change the distro to “squeeze”.. the VM server is likely running “lenny”).
Now we'll need to do some editing on the VM itself, so we're going to trick it into thinking it is running. We do this by using chroot to make the VM's filesystem the root of our shell session's filesystem:
vmserver:~# chroot /mnt root@vmserver:/#
At this point, an “ls /” will show the base of the VM's filesystem, and not the VM server. The prompt still says “vmserver”, but this is a lie. We will actually be changing some files to alter that.
The /proc filesystem will need to be mounted in order to allow some facilities to work properly:
root@vmserver:/# mount -t proc proc /proc root@vmserver:/#
Now we are to change the hostname that the VM reports:
root@vmserver:/# echo "vmname" > /etc/hostname root@vmserver:/#
And set the root password:
root@vmserver:/# passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@vmserver:/#
Read from /etc/apt/sources.list and establish our package database (ends up being in /var/lib/dpkg):
root@vmserver:/# aptitude update Get:1 http://mirror squeeze Release.gpg [835 B] ... Current status: 584 new [+584]. root@vmserver:/#
There should not be any updates to apply, since we just recently installed, but it never hurts to check:
root@vmserver:/# aptitude upgrade No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B of archives. After unpacking 0 B will be used. ... root@vmserver:/#
If we're running a fairly standard VM (ie nothing experimental that needs some special kernel), here are the default packages we'd likely want to install:
root@vmserver:/# aptitude install ssh linux-image-2.6.32-5-xen-amd64 locales console-data The following NEW packages will be installed: busybox{a} console-common{a} console-data firmware-linux-free{a} initramfs-tools{a} kbd{a} klibc-utils{a} libbsd0{a} libedit2{a} libgssapi-krb5-2{a} libk5crypto3{a} libkeyutils1{a} libklibc{a} libkrb5-3{a} libkrb5support0{a} libuuid-perl{a} libwrap0{a} libx11-6{a} libx11-data{a} libxau6{a} libxcb1{a} libxdmcp6{a} libxext6{a} libxmuu1{a} linux-base{a} linux-image-2.6.32-5-xen-amd64 locales openssh-blacklist{a} openssh-blacklist-extra{a} openssh-client{a} openssh-server{a} ssh tcpd{a} xauth{a} 0 packages upgraded, 34 newly installed, 0 to remove and 0 not upgraded. Need to get 43.7 MB of archives. After unpacking 143 MB will be used. Do you want to continue? [Y/n/?] y Get:1 http://mirror/debian/ squeeze/main console-data all 2:1.10-5 [1180 kB] Get:2 http://mirror/debian/ squeeze/main kbd amd64 1.15.2-1 [404 kB] Get:3 http://mirror/debian/ squeeze/main console-common all 0.7.85 [128 kB] ...
You've probably been seeing these messages appear:
locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory
What is happening is that the locale environment variables are not properly set… time to get that taken care of:
root@vmserver:/# dpkg-reconfigure locales console-data
And be sure to check:
[*] en_US.UTF-8 UTF-8
And make the “Default locale for the system environment”: en_US
Usually there's no need to touch the keymap, so when it asks: “Don't touch keymap”
Also important is the timezone, which can be configured as follows:
root@vmserver:/# ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime root@vmserver:/#
Before we wrap up, we should ensure we will be able to access the VM's console; instead of /dev/tty1, Xen has us using /dev/hvc0, so be sure to change that in /etc/inittab. Specifically, we want to look for this block:
1:2345:respawn:/sbin/getty 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 3:23:respawn:/sbin/getty 38400 tty3 4:23:respawn:/sbin/getty 38400 tty4 5:23:respawn:/sbin/getty 38400 tty5 6:23:respawn:/sbin/getty 38400 tty6
And change it to this:
1:2345:respawn:/sbin/getty 38400 hvc0 #2:23:respawn:/sbin/getty 38400 tty2 #3:23:respawn:/sbin/getty 38400 tty3 #4:23:respawn:/sbin/getty 38400 tty4 #5:23:respawn:/sbin/getty 38400 tty5 #6:23:respawn:/sbin/getty 38400 tty6
Hey now, it looks like we're on set on VM configuration, so let's umount and exit from our chroot environment:
root@vmserver:/# umount /proc root@vmserver:/# exit exit vmserver:/xen/images# umount /mnt vmserver:/xen/images#
Now it is time to create our Xen VM configuration file in /xen/conf… each config has unique characteristics in it, here is a sample file that can be altered:
########################################################################## # LAIR Xen VM configuration file ########################################################################## ################################################# # Kernel + memory size # kernel = '/xen/boot/vmlinuz-2.6.32-5-xen-amd64' ramdisk = '/xen/boot/initrd.img-2.6.32-5-xen-amd64' memory = '192' vcpus = '1' #extra = 'clocksource=jiffies' ################################################# # Disk device(s). # root = '/dev/xvda1 ro' disk = [ 'file:/xen/images/newvm.disk,xvda1,w', 'file:/xen/images/newvm.swap,xvda2,w' ] ################################################# # Hostname # name = 'newvm' ################################################# # Networking # dhcp = 'dhcp' vif = [ 'mac=00:16:3E:AA:BB:CC' ] ################################################# # Behaviour # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart'
Look through the file and make the pertinent changes (memory, disk names/location, VM name, MAC address).
NOTE: with the MAC address and desired system name, appropriate updates should be made on the subnet's router in /etc/dhcpd.conf and the DNS zone files for the domain. Instructions for that are beyond the scope of this document.
If this is to be a regular service provided (or even if it is just an experiment), efforts should be documented so others know the purpose of the VM, and the originator has a record to recall when they've forgotten some of the specifics of their activities.
If desired, you can:
If all our ducks are in a row, let's fire up our VM:
vmserver:~# xm create -c /xen/conf/newvm.cfg Using config file "/xen/conf/newvm.cfg". ...