Booting Up an Ubuntu DomU (paravirtualized) on Xen 4.2

1. Get a Linux Kernel and build it

I used kernel version 3.2.40. Type:

$ wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.40.tar.bz2
$ tar -xvf linux-3.2.40.tar.bz2
$ cd linux-3.2.40
$ make menuconfig

Save and exit the menuconfig

Configure kernel for domU support

  1. If building 32 bit kernel make sure you have CONFIG_X86_PAE enabled (which is set by selecting CONFIG_HIGHMEM64G)
    • non-PAE mode doesn’t work in 2.6.25, and has been dropped altogether from 2.6.26 and newer kernel versions.
  2. Enable these core options (Processor type and features| Paravirtualized guest support]
    • CONFIG_PARAVIRT=y
    • CONFIG_XEN=y
    • CONFIG_PARAVIRT_GUEST=y
    • CONFIG_PARAVIRT_SPINLOCKS=y
  3. And Xen pv console device support (Device Drivers|Character devices
    • CONFIG_HVC_DRIVER=y
    • CONFIG_HVC_XEN=y
  4. And Xen disk and network support (Device Drivers|Block devices and Device Drivers|Network device support)
    • CONFIG_XEN_FBDEV_FRONTEND=y
    • CONFIG_XEN_BLKDEV_FRONTEND=y
    • CONFIG_XEN_NETDEV_FRONTEND=y
  5. And the rest (Device Drivers|Xen driver support)
    • CONFIG_XEN_PCIDEV_FRONTEND=y
    • CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
    • CONFIG_XEN_FBDEV_FRONTEND=y
    • CONFIG_XEN_XENBUS_FRONTEND=y
    • CONFIG_XEN_SAVE_RESTORE=y
    • CONFIG_XEN_GRANT_DEV_ALLOC=m
  6. And for tmem support:
    • CONFIG_XEN_TMEM=y
    • CONFIG_CLEANCACHE=y
    • CONFIG_FRONTSWAP=y
    • CONFIG_XEN_SELFBALLOONING=y

Now build the kernel.

$ make bzImage -j16 && make modules -j16 && make modules_install -j16 (j option for multiple core use in compilation)

And get initrd.img and vmlinuz.

$ mkdir /guest
$ cp (dom0 kernel directory)/.config /boot/config-3.2.40
$ mkinitramfs -o /guest/initrd.img-3.2.40-domU (target file) 3.2.40
$ cp -rf arch/x86/boot/bzImage /guest/vmlinuz-3.2.40-domU
$ cd /guest

2. Virtual disk setup

Make swap and disk for your new domain.

$ dd if=/dev/zero of=/guest/disk.img bs=1024k count=5000 (about 5GB)
$ dd if=/dev/zero of=/guest/swap.img bs=1024k count=512 (about 512MB)
$ mkfs.ext4 /guest/disk.img (format the disk with ext4 format)
$ mkswap /guest/swap.img (make it a swap)
$ mount /guest/disk.img /mnt -o loop (mount disk.img on /mnt directory)

3. Create a Debian system on the disk

Disk is empty now. So in order to use it as a system, you should create a system on the disk by using debootstrap tool.

$ apt-get install debootstrap
$ debootstrap –arch amd64 raring /mnt http://kr.archive.ubuntu.com/ubuntu/ (the repository you usually use)

It takes quite a long time.
‘raring’ is the name of Ubuntu system. But be careful, if it’s not compatible with the kernel version, it would not boot up.

And copy the modules from this system to the new system on disk.

$ cp -a /lib/modules/3.2.40 /mnt/lib/modules/ (module copy)

If you view /mnt/etc/fstab file, then it should be like this:
$ vi /mnt/etc/fstab

proc                      /proc    proc    defaults                                          0     0
/dev/xvda1      /              ext4    defaults,errors=remount-ro 0     1
/dev/xvda2      none      swap   sw                                                      0     0

4. Console setup

$ cp /mnt/etc/init/tty1.conf /mnt/etc/init/hvc0.conf
$ vi /mnt/etc/init/hvc0.conf

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -8 9600 hvc0

And lastly, set the root password and unmount the disk.

$ chroot /mnt /usr/bin/passwd
$ umount /mnt

5. VM Configuration

$ cd /guest
$ vi cacloud002.cfg

Configuration example is here: vm-1.cfg

#
# Configuration file for the Xen instance OneVM, created
# by xen-tools 4.2.1 on Tue Aug 2 16:49:05 2011.
#

#
# Kernel + memory size
#

kernel = “/boot/vmlinuz-3.2.40-xen” (the kernel you just made)
ramdisk = “/boot/initrd-3.2.40-xen” (the ramdisk you just made)

vcpus = ‘8’
memory = ‘4096’

#
# Disk device(s).
#
root = ‘/dev/xvda1 ro’
disk = [
‘file:/home/calab/vm-1/disk.img,xvda1,w’, (the disk you just made)
‘file:/home/calab/vm-1/swap.img,xvda2,w’, (the swap you just made)
]
#
# Physical volumes
#
#
# Hostname
#
name = ‘vm-1’

#
# Networking
#
vif = [ ‘ip=143.248.134.29,mac=00:26:B9:48:74:dc’ ] (you should define the ip address and mac address)

#
# Behaviour
#
on_poweroff = ‘destroy’
on_reboot = ‘restart’
on_crash = ‘restart’

Test this VM.

$ xl create vm-1.cfg

$ xl list

Name          ID Mem    VCPUs State Time(s)
Domain-0    0 14558              6 r—–       23.4
cacloud002 1 512                   1 -b—-          9.7

6. Locale Settings

$ apt-get install language-pack-en-base
$ export LANGUAGE=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ locale-gen en_US.UTF-8
$ dpkg-reconfigure locales

7. Additionally

$ apt-get install gfortran
$ apt-get install g++
$ apt-get install ssh

7 thoughts on “Booting Up an Ubuntu DomU (paravirtualized) on Xen 4.2

  1. In the vif of vm-1.cfg, add bridge=xenbr0

    after logging into the domU, by using
    dom0#xl console [name or id of vm]

    open /etc/network/interfaces

    add the following:
    auto eth0
    iface eth0 inet static
    address [ip address]
    netmask [netmask]
    dns-nameservers [dns server1] [dns server 2] …

  2. Hi.

    I was using the tutorial I found here:
    http://virt-tools.org/learning/install-with-command-line/

    And using the ftp link (at the end of the page: http://ftp.ubuntu.com/ubuntu/dists/maverick/main/installer-i386/) I installed Ubuntu using the option over the network in the virt-manager. I’d like to make paravirtualization. But, in that link, the versions of the Ubuntu 12.04 are only Desktop and I would like to install Ubuntu Server 12.04 LTS.
    Does anyone knows one server that has the Ubuntu Server 12.04 that function in the virt manager with the option over network to download and install?

    I’ll be very grateful if anyone can help me. Thanks.

  3. Pingback: 20140707 | gumdaeng

Leave a comment