Ubuntu Lucid domU under Debian Lenny Dom0

# configure domU
[ -z $DOMAIN_NAME ] && DOMAIN_NAME=lucid
[ -z $DOMAIN_MAC ] && DOMAIN_MAC=00:00:00:00:aa:bb
[ -z $DOMAIN_RAM ] && DOMAIN_RAM=1Gb
[ -z $DOMAIN_HDD ] && DOMAIN_HDD=8Gb

# create vm
xen-create-image --hostname=${DOMAIN_NAME} --dhcp --mac=${DOMAIN_MAC} \
--lvm=vg01 --dist=lucid --mirror=http://archive.ubuntu.com/ubuntu --size=${DOMAIN_HDD} --memory=${DOMAIN_RAM} --swap=${DOMAIN_RAM}

# rename vm config
mv /etc/xen/${DOMAIN_NAME}.cfg /etc/xen/${DOMAIN_NAME}

# post config domU
mount /dev/vg01/${DOMAIN_NAME}-disk /mnt/
# configure hvc0
cp /mnt/etc/init/tty1.conf /mnt/etc/init/hvc0.conf
sed -i 's|tty1|hvc0|g' /mnt/etc/init/hvc0.conf
# configure password
chroot /mnt/ sh -c "echo root:terceS | chpasswd"
# configure locale
chroot /mnt/ sh -c "locale-gen en_US.UTF-8"
echo LANG=en_US.UTF-8 >> /mnt/etc/environment
echo LC_ALL=C >> /mnt/etc/environment

# edit mounts
sed -i 's|sda|xvda|g' /mnt/etc/fstab

##mv /mnt/etc/fstab /mnt/etc/fstab.org
##cat < /mnt/etc/fstab
##proc /proc proc defaults 0 0
##/dev/xvda1 none swap sw 0 0
##/dev/xvda2 / ext3 noatime,nodiratime,errors=remount-ro 0 1
##EOF

mv /mnt/etc/init/tty1.conf /mnt/etc/init/tty1.conf.disabled
mv /mnt/etc/init/tty2.conf /mnt/etc/init/tty2.conf.disabled
mv /mnt/etc/init/tty3.conf /mnt/etc/init/tty3.conf.disabled
mv /mnt/etc/init/tty4.conf /mnt/etc/init/tty4.conf.disabled
mv /mnt/etc/init/tty5.conf /mnt/etc/init/tty5.conf.disabled
mv /mnt/etc/init/tty6.conf /mnt/etc/init/tty6.conf.disabled

# BROKEN ?!? run in chroot
debconf-set-selections <<\EOF
grub-pc grub2/linux_cmdline ""
grub-pc grub-pc/install_devices_empty true
EOF

## todo preseed 2 options (grup parameter)

chroot /mnt/ sh -c "apt-get install -y linux-image-virtual"

mkdir -p /boot/xen/

# on lucid
cp /mnt/boot/vmlinuz-2.6.32-21-generic-pae /boot/xen/
cp /mnt/boot/initrd.img-2.6.32-21-generic-pae /boot/xen/

# on maverick
cp /mnt/boot/vmlinuz-2.6.35-22-virtual /boot/xen/
cp /mnt/boot/initrd.img-2.6.35-22-virtual /boot/xen/

umount /mnt

# on lucid
sed -i 's|vmlinuz-2.6.26-2-xen-amd64|lucid/vmlinuz-2.6.32-21-generic-pae|g' /etc/xen/${DOMAIN_NAME}
sed -i 's|initrd.img-2.6.26-2-xen-amd64|lucid/initrd.img-2.6.32-21-generic-pae|g' /etc/xen/${DOMAIN_NAME}

# on maverick
sed -i 's|vmlinuz-2.6.26-2-xen-amd64|xen/vmlinuz-2.6.35-22-virtual|g' /etc/xen/${DOMAIN_NAME}
sed -i 's|initrd.img-2.6.26-2-xen-amd64|xen/initrd.img-2.6.35-22-virtual|g' /etc/xen/${DOMAIN_NAME}

sed -i 's|sda|xvda|g' /etc/xen/${DOMAIN_NAME}

## test 2
mkdir /boot/ubuntu10.04
cd /boot/ubuntu10.04

wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz

lvcreate --name u1004-disk --size 4G vg01

cat < /etc/xen/u1004inst
kernel = '/boot/ubuntu10.04/linux'
ramdisk = '/boot/ubuntu10.04/initrd.gz'
memory = '512'
disk = [ 'phy:/dev/vg01/u1004-disk,xvda,w' ]
name = 'u1004'
dhcp = 'dhcp'
vif = [ 'mac=00:00:00:00:ae:be' ]
on_poweroff = 'destroy'
on_reboot = 'destroy'
on_crash = 'destroy'
EOF