I was faced with the task of installing a paravirtualized Debian OS on a Xen server. My Xen version is 4.0.1-2, Debian version is 6 (Squeeze), it doesn't matter whether it's 32-bit or 64-bit. There are several articles online on this same topic that cover installing paravirtualized Debian directly, without using HVM. Those articles were completely useless for Lenny, because none of them let me actually install Debian 5 (no matter which method they suggested for the installation). Right now Squeeze is sweeping the planet, and I will definitely test its direct installation soon (there's good groundwork for getting a paravirtualized system installed right away).
So, this article can safely be used for:
A) Installing Debian 6 Squeeze from scratch by first installing into an HVM domain and then converting it to paravirtual,
B) Converting an already existing HVM version of Debian Squeeze into paravirtual mode.
Let's begin. If you already have Debian installed in an HVM DomU, skip straight to the "after installation" section.
1) Create an HVM domain.
# cd /etc/xen
# mkdir vm_debian
# cd vm_debian
Create a disk for the system, for example 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. File contents:
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-6.0.1a-amd64-i386-netinst.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
This assumes that your installation disc image is located at /etc/xen/iso/debian-6.0.1a-amd64-i386-netinst.iso; otherwise, specify your own path.
Start the domain:
# xm create vm_debian/vm.cfg
2) Connect to the newly created domain in Xen using VNC Viewer. This assumes you've already worked with Xen and have an idea of what VNC Viewer is and how to connect with it. If not, this same site has an article about Xen explaining what it is and how it works.
Now install Debian as usual, the same way you would on bare metal.
3) After the installation finishes and the system reboots, the installer will start up again from the disk. But we need to get into the installed system, not into 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 we change the value "boot = 'd'" to "boot = 'c'":
boot = 'c'
We start the machine and connect to it again via VNC.
# xm create vm_debian/vm.cfg
4) After installation
After the installation, or alternatively if you want to convert the HVM Debian machine to a paravirtualized environment, we proceed as follows.
So, we are connected via VNC to the machine and can see its console. We log in as root.
5) We need SSH.
Since we're going to install a paravirtual 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 proceed:
# aptitude install openssh-server
# /etc/init.d/ssh start
The default settings are of course not very secure, but we'll always have time to change them later.
6) Installing a Xen-compatible kernel.
For Xen to be able to work with our machine, we need a Xen-compatible kernel. The simplest approach is to install this kernel on the virtual machine itself, and then copy it to the Xen server.
# aptitude install linux-image-xen-686
This assumes the use of the meta-package that points to the latest kernel for the current OS by default. And a 32-bit guest. For a 64-bit guest, use amd64 instead of 686. If the kernel is different, specify it accordingly.
7) Now let's fix 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/securetty:
Make sure this file contains an entry for hvc0:
PS. In Lenny the file was called securetab, so pay attention!
# cat /etc/securetty | grep hvc0
hvc0
If not, add it.
This lets the OS redirect 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.32-5-xen-686 ./
# scp root@192.168.0.2:/boot/vmlinuz-2.6.32-5-xen-686 ./
If root access via ssh is closed for you, use another user. Replace 192.168.0.2 with 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 let's 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 Debian guest domain. We also see that instead of the "tap:aio:" TAP interface, a LOOP interface "file:" is used. Unfortunately, I couldn't get even Squeeze to work with the TAP interface, so we use the LOOP interface (given paravirtualization, the speed is decent there).
10) Start the paravirtualized guest
# xm create -c vm_debian/vm.cfg
The -c flag tells Xen to attach to the machine's console right away, which lets you watch the OS boot process in real time.
You can disconnect from the console with the Ctrl+] key combination
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 up and is happily running.
Comments