I was faced with the task of installing a paravirtualized Debian OS on a Xen server. My Xen version is 4.0.1, and the Debian version is 5 (Lenny) - doesn't matter whether it's 32 or 64-bit. I found several articles online about doing this, but none of the approaches worked - either the installer just wouldn't start, or it would crash during kernel installation, or something else would go wrong. In short, you can safely throw the "install straight into a paravirtualized environment" options into the trash - they don't work, they just waste your time. The "mount this via loop here, mkfs that there, rebuild this, unmount and turn it inside out through here" options can also safely go in the same trash bin - for the same reasons.
So, here's a guaranteed working "how-to" for installing, and moreover, converting an already-running HVM Debian Lenny system into PV (paravirtualized) mode.
Note: all these steps also apply to Debian 6 Squeeze, with the caveat that package names and kernel versions differ.
Let's begin. If you already have Debian installed in an HVM DomU - skip straight to the "after installation" section.
1) Create the HVM domain.
# cd /etc/xen
# mkdir vm_debian
# cd vm_debian
Create a disk for the system, say, 10GB
# dd if=/dev/zero of=hdd0 bs=1M count=10240
Create the HVM domain config for the Debian system. Let's call the file vm.cfg. Contents of the file:
kernel = 'hvmloader'
builder = 'hvm'
memory = '256'
device_model = '/usr/lib/xen/bin/qemu-dm'
disk = [ 'tap:aio:/etc/xen/vm_debian/hdd0,hda,w', 'tap:aio:/etc/xen/iso/debian-505-netinst-686.iso,hdc:cdrom,r' ]
vif = [ 'bridge=eth0, mac=fe:16:3e:68:fc:99' ]
name = 'vm_debian'
boot = 'd'
vnc = 1
sdl = 0
apic = 1
acpi = 1
localtime = 0
vcpus = 1
pae = 1
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
vncconsole = 0
stdvga = 0
videoram = 16
shadow_memory = 8
It's assumed that the installation disk image is located at /etc/xen/iso/debian-505-netinst-686.iso; otherwise specify your own path.
Start the domain:
# xm create vm_debian/vm.cfg
2) Connect to the newly created domain via VNC Viewer to Xen. It's assumed you've already worked with Xen and have an idea of what VNC Viewer is and how to hook up to it. If not - this same site has an article about Xen explaining what it is and how it works.
Now install Debian as usual, just as you would on bare metal.
3) After the installation finishes and the system reboots, the installer will start up again from the disc. But we need to get into the installed system, not the installer. So we stop the machine manually from the Xen server and change the config:
# xm destroy vm_debian
And in the vm.cfg file, change the value "boot = 'd'" to "boot = 'c'":
boot = 'c'
Start the machine and reconnect to it via VNC.
# xm create vm_debian/vm.cfg
4) After installation
After installation, or if you want to convert the Debian HVM machine into a paravirtualized environment, continue as follows.
So, we're connected via VNC to the machine and can see its console. Log in as root.
5) We need SSH.
Since we're going to install a paravirtualized kernel inside the Debian HVM and then copy it out to the Xen server, we need a configured SSH server on the guest machine. If it's already configured — great. If not, let's set it up:
# aptitude install openssh-server
# /etc/init.d/ssh start
The default settings, of course, aren't very secure, but we'll always have time to change that later.
6) Install a Xen-compatible kernel.
For Xen to be able to work with our machine, we need a Xen-compatible kernel. The simplest way is to install this kernel on the virtual machine itself, and then copy it to the Xen server.
# aptitude install linux-image-2.6.26-2-xen-686
This assumes the use of kernel 2.6.26-2, the default kernel for Lenny, and a 32-bit guest. For a 64-bit guest, use amd64 instead of 686. If your kernel is different, specify accordingly.
7) Now let's edit a couple of files:
/etc/inittab:
in the line "1:2345:respawn:/sbin/getty 38400 tty1", change the value tty1 to hvc0:
1:2345:respawn:/sbin/getty 38400 hvc0
/etc/securetab:
Make sure this file contains the entry hvc0:
# cat /etc/securetab | grep hvc0
hvc0
If not, add it.
This lets the OS direct console output to the HVC0 device, which is the Xen console. Otherwise the OS will boot up to the "Starting local scripts" message and hang there, since Xen doesn't see tty1.
8) Copy the kernel from the guest domain to the Xen server.
On the Xen server:
# cd /etc/xen/vm_debian
# scp root@192.168.0.2:/boot/initrd.img-2.6.26-2-xen-686 ./
# scp root@192.168.0.2:/boot/vmlinuz-2.6.26-2-xen-686 ./
If root access via ssh is disabled for you, use another user. Instead of 192.168.0.2, substitute the IP address of the guest machine.
9) Shut down the guest machine and create a PV config for it on the server.
On the guest:
# shutdown -Ph now
On the server:
# xm list | grep vm_debian
Run this until you see that the machine has shut down.
Let's save the HVM config just in case:
# mv vm.cfg vm.hvm
And put the following config into the vm.cfg file:
kernel = "/etc/xen/vm_debian/vmlinuz-2.6.26-2-xen-686"
ramdisk = "/etc/xen/vm_debian/initrd.img-2.6.26-2-xen-686"
root = "root=/dev/xvda1 ro console=hvc0"
memory = '256'
disk = [ 'file:/etc/xen/vm_debian/hdd0,xvda,w' ]
vif = [ 'bridge=eth0, mac=fe:16:3e:68:fc:99' ]
name = 'vm_debian'
#boot = 'c'
vnc = 1
sdl = 0
apic = 1
acpi = 1
localtime = 0
vcpus = 1
pae = 1
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
vncconsole = 1
stdvga = 0
videoram = 16
shadow_memory = 8
timer_mode = 1
Here we see that instead of the sda device, the xvda device will be passed to the guest Debian domain. We also see that instead of the "tap:aio:" TAP interface, the LOOP interface "file:" is used. Unfortunately, I wasn't able to get Debian working with the TAP interface on either kernel 2.6.26 or 2.6.32, so we use the LOOP interface (given paravirtualization, the speed there is decent).
10) Start the paravirtualized guest
# xm create -c vm_debian/vm.cfg
The -c flag tells Xen to attach to the machine's console immediately, letting you watch the OS boot process in real time.
You can detach from the console with the key combination Ctrl+]
At any other time you can connect to the console using the xm console command:
# xm console vm_debian
That's it, the machine has booted and is happily running.
Comments