Saturday, January 19, 2019

How do I use Xen hypervisor?


I am interested in trying out Xen;



  • What packages do I need to install?

  • How do I set up a DomU instance?



Paravirtualized guest and Ubuntu 11.04


When installing a Xen virtual machine, you need to determine what kind of block devices you want to work with. There are three possibilities: installing directly on a dedicated partition (maximum performance) or by using an important disk image file or create your own disk image file with dd (resizable; You can use snapshots for making backups)


All commands assume root (ie. sudo su). I also assume using LVM but have also included an untested method where you use dd to use your own image. So skip 1 if you want to use a file (and not LVM) and skip 2 if you do use LVM.



  1. Create a new LVM volume for your virtual machine. Change the name (after -n) to suit your needs:


    lvcreate -L10G -n example.ubuntu.natty VolumeGroup

    lvcreate is part of lvm2 Install lvm2 but it is already installed when you are using lvms.


  2. You can also use a file (dd). I have not found a suitable method for this with Ubuntu but this should come close. If you go with this I have experience with it but all the next steps should be the same. Copied from the link the method to create one using dd (the link also includes other methods of getting a file):


    Create a 4Gb empty file with at /var/lib/xen/images/disk1 (change either size and location to fit your needs):


    dd if=/dev/zero of=/var/lib/xen/images/disk1 bs=1M count=4096

    Apart from creating empty image files using the dd utility, you can also use ISO files as an alternative for your physical optical drives. The usage is the same as the usage of a disk image file created with dd. Don't have an ISO file yet? Then we have good news for you; it's easy to create one. If the cd-rom of which you want to create an ISO file is in your optical drive, use the following to copy it to a file with the name cdrom.iso:


    dd if=/dev/cdrom of=/isos/cdrom.iso

    After creating either a disk image file or an ISO file, you need to include the disk image file in your virtual machine configuration using the file option in the disk definition:


    disk=[ 'file:/var/lib/xen/images/disk1,hda,w', 'file:/isos/cdrom.iso,hdc,r', ]

  3. Get the kernel, initrd, and xen config. wget versions for nl and installer-amd64 (so change the country code nl and also use installer-amd64 in the URL to fit your needs):


    wget http://nl.archive.ubuntu.com/ubuntu/dists/natty/main/installer-i386/current/images/netboot/xen/xm-debian.cfg
    wget http://nl.archive.ubuntu.com/ubuntu/dists/natty/main/installer-i386/current/images/netboot/xen/initrd.gz
    wget http://nl.archive.ubuntu.com/ubuntu/dists/natty/main/installer-i386/current/images/netboot/xen/vmlinuz

  4. Edit the config file


    Edit the config file to taste, paying attention to the memory, name, vcpus, vif, and disk options. Also, find the line that says bootloader=pygrub and change it to the absolute path bootloader=/usr/sbin/pygrub.


  5. Start the install (again pay attention to the command: change server country code and architecture to your needs):


    xm create -f xm-debian.cfg -c install=true install-kernel="vmlinuz" install-ramdisk="initrd.gz" install-mirror="http://nl.archive.ubuntu.com/ubuntu" install-arch=i386 install-method=network


    • select a language

    • select a location

    • configure your network card. If it fails you will need to configure it manually (choose back, drop to a shell and issue a modprobe xen-netfront && exit. Configure the network card again.

    • select detect network hardware and insert a hostname


    and it starts installing.


  6. Fix the install.


    The xen-blkfront module isn’t loaded at first so xen will fail to boot.


    (initframfs) modprobe xen-blkfront
    (initramfs) exit

    Once the host finishes booting, log in and sudo to root. Then enter the following:


    echo "xen-blkfront" >> /etc/initramfs-tools/modules
    update-initramfs -u
    update-initramfs: Generating /boot/initrd.img-2.6.38-11-generic


Untested and from memory + googling to fix my memory


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...