Create Ubuntu DomU on Centos Dom0

This post was tested by creating ubuntu 10.04 and 12.04 in both centos 5 and 6

First assign disk space to the new virtual machine

lvcreate vg00 -L 10G -n lv001 

create the configuration file “/etc/xen/ubuntu”

# nano  /etc/xen/ubuntu

and paste

#  -*- mode: python; -*-
#=======================================================================
memory = 1024
name = “ubuntu”
vcpus = 1
vif = ['mac=00:16:3e:e2:54:c3,bridge=xenbr0']
disk = ['phy:/dev/vg00/lv00,xvda,w']
#=======================================================================
# Debian Installer specific variablesdef check_bool(name, value):
value = str(value).lower()
if value in (‘t’, ‘tr’, ‘tru’, ‘true’):
return True
return Falseglobal var_check_with_default
def var_check_with_default(default, var, val):
if val:
return val
return defaultxm_vars.var(‘install’, use=’Install Debian, default: false’, check=check_bool)xm_vars.var(“install-arch”,
use=’Debian mirror to install from (default: amd64)’,
check=lambda var, val: var_check_with_default(‘amd64′, var, val))
xm_vars.var(“install-mirror”,
use=’Debian mirror to install from (default: http://archive.ubuntu.com/ubuntu)’,
check=lambda var, val: var_check_with_default(‘http://archive.ubuntu.com/ubuntu’, var, val))
xm_vars.var(“install-suite”,
use=’Debian suite to install (default: lucid)’,
check=lambda var, val: var_check_with_default(“lucid”, var, val))
xm_vars.var(“install-installer”,
use=’Debian installer to use (default: uses install-mirror)’,
check=lambda var, val: var_check_with_default(None, var, val))
xm_vars.var(“install-kernel”,
use=’Debian installer kernel to use (default: uses install-installer)’,
check=lambda var, val: var_check_with_default(None, var, val))
xm_vars.var(“install-ramdisk”,
use=’Debian installer ramdisk to use (default: uses install-installer)’,
check=lambda var, val: var_check_with_default(None, var, val))
xm_vars.var(“install-extra”,
use=’Extra command line options (default: None)’,
check=lambda var, val: var_check_with_default(None, var, val))
xm_vars.check()if not xm_vars.env.get(‘install’):
bootloader=”/usr/bin/pygrub”
else:
import os.path
print “Install Mirror: %s” % xm_vars.env['install-mirror']
print “Install Suite: %s” % xm_vars.env['install-suite']
if xm_vars.env['install-installer']:
installer = xm_vars.env['install-installer']
else:
installer = xm_vars.env['install-mirror']+”/dists/”+xm_vars.env['install-suite'] + \
“/main/installer-”+xm_vars.env['install-arch']+”/current/images”
print “Installer: %s” % installerprint
print “WARNING: Installer kernel and ramdisk are not authenticated.”
printif xm_vars.env.get(‘install-kernel’):
kernelurl = xm_vars.env['install-kernel']
else:
kernelurl = installer + “/netboot/xen/vmlinuz”if xm_vars.env.get(‘install-ramdisk’):
ramdiskurl = xm_vars.env['install-ramdisk']
else:
ramdiskurl = installer + “/netboot/xen/initrd.gz”import urllib
class MyUrlOpener(urllib.FancyURLopener):
def http_error_default(self, req, fp, code, msg, hdrs):
raise IOError(“%s %s” % (code, msg))
urlopener = MyUrlOpener()try:
print “Fetching %s” % kernelurl
kernel, _ = urlopener.retrieve(kernelurl)
print “Fetching %s” % ramdiskurl
ramdisk, _ = urlopener.retrieve(ramdiskurl)
except IOError, _:
raiseif xm_vars.env['install-extra']:
extras=[xm_vars.env['install-extra']]
else:
extras=[]# Reboot will just restart the installer since this file is not
# reparsed, so halt and restart that way.
extras.append(“debian-installer/exit/always_halt=true”)
extras.append(“–”)
extras.append(“quiet”)

console=”hvc0″
try:
if len(vfb) >= 1:
console=”tty0″
except NameError, e:
pass

extras.append(“console=”+ console)

extra = str.join(” “, extras)
print “command line is \”%s\”" % extra

!!!! bridge may change from centos 5 to centos 6 and you have to change the MAC for each installation

Create the virtual machine

For ubuntu 12.04 (Precise)

# xm create ubuntu -c install=true \
install-kernel=”http://us.archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz” \
install-ramdisk=”http://us.archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz” \
install-mirror=”http://us.archive.ubuntu.com/ubuntu”

and for ubuntu 10.04 (Lucid)

# xm create ubuntu -c install=true \
install-kernel=”http://us.archive.ubuntu.com/ubuntu/dists/lucid/main/installer-amd64/current/images/netboot/xen/vmlinuz” \
install-ramdisk=”http://us.archive.ubuntu.com/ubuntu/dists/lucid/main/installer-amd64/current/images/netboot/xen/initrd.gz” \
install-mirror=”http://us.archive.ubuntu.com/ubuntu”