Hi, Anyone else using vmbuilder with Ubuntu's 10.x Lucid Lynx (Alpha3, I know) and cursing the change in options that just happened recently? I've been playing around building VMs (based on Karmic) and tossing them away since it was so quick. Now that I've upgrade to a newer version of Lucid, it's all busted. Sigh... This would be a good talk too, about building and using VMs. Here's the script I whipped up to help automate things, which is now busted. Sigh... I realize I need to just look in the docs, but they a) suck and b) aren't easily found. Nor is any list of changes in the options listed nicely either. Grrr!!!! THanks, John #!/bin/sh # My own script for building and starting VMs more easily, based on # the instructions given at: # # http://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-9.10 # # Version 0.1 - 12/29/2009 # if [ $# -ne 3 ]; then echo "Usage: $0 hostname ip username" echo " IP is last octet of the 192.168.1/24 subnet" echo exit fi euid=`id -u` if [ $euid -ne 0 ]; then echo "Error! Script must run with root privs. Try sudo $0 ...." echo exit fi hostname=$1 ip=$2 username=$3 vmbase="/var/vm" subnet="192.168.1" suite="karmic" bridge="br0" mem=256 mirror="http://192.168.1.3:9999/ubuntu" # LVM stuff volgroup="virtmachs" #--------------------------------------------------------------------- # Make the directory where we store the VM config #--------------------------------------------------------------------- if [ -d ${vmbase}/${hostname} ]; then /bin/rm -rf ${vmbase}/${hostname} fi mkdir -p ${vmbase}/${hostname} cd ${vmbase}/${hostname} #--------------------------------------------------------------------- # Copy over the template, but use the fixed one instead in vm0 #--------------------------------------------------------------------- mkdir -p ${vmbase}/${hostname}/mytemplates/libvirt cp ${vmbase}/vm0/mytemplates/libvirt/* ${vmbase}/${hostname}/mytemplates/libvirt/ #--------------------------------------------------------------------- # Setup partitions file #--------------------------------------------------------------------- cat >vmbuilder.partition <<EOF root 8000 swap 2000 /var 10000 EOF #--------------------------------------------------------------------- # Setup the boot.sh file #--------------------------------------------------------------------- cat >boot.sh <<EOF # This script will run the first time the virtual machine boots # It is run as root. # Expire the user account /usr/bin/passwd -e ${username} # Set the root password /usr/sbin/usermod -p '$1$MbDcN3NU$ndC6TvQ1.a1VG0jbeW3hD.' root # Install openssh-server apt-get update apt-get install -qqy --force-yes openssh-server nfs-client nfs-common mkdir /local /staging /home echo "jfsnew:/home /home nfs soft,sec=sys,vers=3,tcp,rsize=32768,wsize=32768,nolock 0 0" >> /etc/fstab echo "jfsnew:/local /local nfs soft,sec=sys,vers=3,tcp,rsize=32768,wsize=32768,nolock 0 0" >> /etc/fstab echo "jfsnew:/staging /staging nfs soft,sec=sys,vers=3,tcp,rsize=32768,wsize=32768,nolock 0 0" >> /etc/fstab mount /home mount /local mount /staging echo "America/New_York" > /etc/timezone cp /usr/share/zoneinfo/America/New_York /etc/localtime EOF #--------------------------------------------------------------------- # Create LVM volume for VM #--------------------------------------------------------------------- if [ ! -e /dev/${volgroup}/${hostname} ] then lvcreate -L20G -n ${hostname} ${volgroup} else echo echo "Skipping lvcreate, Logical Volume ${hostname} already exists." echo fi #--------------------------------------------------------------------- # Run vmbuilder #--------------------------------------------------------------------- echo vmbuilder kvm ubuntu --suite=${suite} --flavour=virtual --arch=amd64 --mirror=${mirror} -o --libvirt=qemu:///system --tmpfs=- --ip="${subnet}.${ip}" --part=vmbuilder.partition --templates=mytemplates --user=${username} --name=${username} --pass=${username} --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --raw=/dev/virtmachs/${hostname} --firstboot=boot.sh --mem=${mem} --hostname=${hostname} --bridge=${bridge} vmbuilder kvm ubuntu --suite=${suite} --flavour=virtual --arch=amd64 --mirror=${mirror} -o --libvirt=qemu:///system --tmpfs=- --ip="${subnet}.${ip}" --gateway="${subnet}.254" --part=vmbuilder.partition --templates=mytemplates --user=${username} --name=${username} --pass=${username} --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --raw=/dev/virtmachs/${hostname} --firstboot=boot.sh --mem=${mem} --hostname=${hostname} --bridge=${bridge} #--------------------------------------------------------------------- # Startup the VM #--------------------------------------------------------------------- if [ -e /etc/libvirt/qemu/${hostname}.xml ] then virsh define /etc/libvirt/qemu/${hostname}.xml virsh start ${hostname} else echo "Error! VM ${hostname} not created properly." echo exit fi
participants (1)
-
John Stoffel