Logicalwebhost Cheatsheet

Linux & Open Source Cheatsheets & Howto's

Skip to: Content | Sidebar | Footer

xen howto

xen is a fast para-virtualization virtual machine technology that’s open source and used by lots of folks like Amazon, Rackspace, etc. Para-virtualization means it runs on non-specialized hardware, but at very fast speed. This howto is for Debian Squeeze specifically right now, if I get time I’ll backfill a Lenny version, it has some gotcha’s, well so does Squeeze.

Debian Squeeze Xen Install HowTo

some of this is compiled from the Debian xen wiki here if you want a reference. Get root (or use sudo) and do (for 64bit systems):

aptitude -P install xen-hypervisor-4.0-amd64 linux-image-xen-amd64 xen-tools

for 32-bit systems do:

aptitude -P install xen-hypervisor-4.0-i386 linux-image-xen-686 xen-tools

grub screws up the boot order of kernels by default, change that by doing:

mv -i /etc/grub.d/10_linux /etc/grub.d/50_linux
update-grub2

disable multi-OS boot now (unless you have more than one OS on a server for some reason) so it won’t try to boot into your VM’s:

echo "" >> /etc/default/grub
echo "# Disable OS prober to prevent virtual machines on logical volumes from appearing in the boot menu." >> /etc/default/grub
echo "GRUB_DISABLE_OS_PROBER=true" >> /etc/default/grub
update-grub2

xen by default tries to save the states of your VM’s on shutdown, which may break things, so disable it in /etc/default/xendomains by doing:

XENDOMAINS_RESTORE=false
XENDOMAINS_SAVE=""

edit the networking settings in /etc/xen/xend-config.sxp and enable bridge networking, so your VM’s will use the same network at your server:

(network-script 'network-bridge antispoof=yes')

this also prevents your VM’s from choosing insane network IP’s, like choosing the gateway for their IP. Now edit settings in the /etc/xen-tools/xen-tools.conf and change the default IP, gateway, Disk image size, swap, memory, distribution type and uncomment /home/xen line. Also, if you want to have the guest VM use its own grub (more horkproof), do:

# /home/xen (uncomment this)
pygrub=1 (add at end of file after last line)
# password=1 (uncomment this)

now you have to reboot into your new xen kernel for xen to work on your server. After rebooting, create a new vm by doing:

xen-create-image --hostname www.yourserver.com --ip 1.2.3.4 --netmask 255.255.255.x --size 10Gb --memory 1024Mb --vcpus 2 --pygrub --dist lenny|maverick|whatever

Migrate xen vm’s from Lenny to Squeeze

if you upgrade your server to Squeeze, you then have to update your guest VM’s too, luckily this is pretty simple unless you have more complex VM storage than a basic disk image emulating a standard /dev/sda1 drive or so. On the SERVER do:

vi /etc/xen/whatever.domain.com.cfg

you want to comment out the old /dev/sda2 and change it to /dev/xda2, like (adjust numbers to match your setup):

#root        = '/dev/sda2 ro'
root        = '/dev/xvda2 ro'

also you have to use the updated vmlinuz and initrd, add new lines and comment out the old ones with your versions like:

kernel      = '/boot/vmlinuz-2.6.32-5-xen-amd64'
ramdisk     = '/boot/initrd.img-2.6.32-5-xen-amd64'
#kernel      = '/boot/vmlinuz-2.6.26-1-xen-amd64'
#ramdisk     = '/boot/initrd.img-2.6.26-1-xen-amd64'

now start the VM like:

xm create whatever.domain.com.cfg

you can see if it’s running by doing:

xm list

you should see an entry for your whatever.domain.com VM. Now console into it by doing:

xm console whatever.domain.com

after you login to the VM, start the upgrade to Squeeze like:

vi /etc/apt/sources.list
:%s/lenny/squeeze/g

this updates your repositories, now start the upgrade:

apt-get update && apt-get upgrade
apt-get dist-upgrade

if all went well you should now be running Squeeze on the VM 🙂

Debian Lenny Xen Install HowTo

apt-get install xen-hypervisor-3.2-1-i386 xen-linux-system-2.6.26-2-xen-686 xen-utils-3.2-1 xenstore-utils xenwatch xen-shell xen-tools 
vi /etc/modules (add next line to end of file:)
    loop max_loop=64
vi /etc/xen/xend-config.sxp (uncomment the next 2 lines, comment out the third:)
    (network-script network-bridge)
    (vif-script vif-bridge)
    #(network-script network-dummy)
reboot

now you *should* have a xen kernel, which you can find out by doing:

uname -a

and seeing a xen somewhere in the kernel line. Now create a new vm by doing:

xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.101 --memory=128Mb --arch=amd64 --role=udev

and then start it up by doing:

cd /etc/xen
xm create xen1.example.com.cfg

and then login to it by doing:

xm console xen1.example.com

reset lost root password on guest DOMU

you have to shut down the machine, mount it in a loopback, then chroot into it. It sounds scary, but it works. If you’re paranoid, make a backup of your whatever.server.com.img in case something bad happens.

xm list <-- (shows your running machines)
xm destroy www.server.com <-- (shuts it down)
cd /path/to/where/your/domain/image/is/
mkdir vm_base
mount -o loop www.server.com.img vm_base
chroot vm_base
passwd root
exit
umount vm_base
xm create /etc/xen/www.server.com.cfg
xm list <-- (you should see your machine running now)

Write a comment

You need to login to post comments!