Skip to content

Instantly share code, notes, and snippets.

@baylisscg
Created September 8, 2011 08:36
Show Gist options
  • Save baylisscg/1202934 to your computer and use it in GitHub Desktop.
Save baylisscg/1202934 to your computer and use it in GitHub Desktop.
Setup script for NECTAR research cloud VM.
#!/bin/bash
# Fix up config files
cat <<EOF > /etc/resolv.conf
search rc.melbourne.nectar.org.au
nameserver 115.146.82.4
nameserver 115.146.80.4
EOF
sed -i "s_archive.ubuntu.com/ubuntu/_mirror.aarnet.edu.au/pub/ubuntu/archive/_" /etc/apt/sources.list
sed -i "s_security.ubuntu.com/ubuntu_mirror.aarnet.edu.au/pub/ubuntu/archive/_" /etc/apt/sources.list
# Reinitalise apt and install needed tools
apt-get clean
apt-get update
apt-get install -y debootstrap qemu-kvm emacs23-nox emacs-goodies-el uuid
SERVER_IMG="/dev/shm/server.img"
WORKING_DIR="/mnt/server"
IMAGE_SIZE="5G"
EXTRA_OPTS="--include=cloud-init,ssh,openjdk-6-jdk,emacs23-nox,emacs-goodies-el,acpid,language-pack-en,linux-image-virtual"
UUID=`uuidgen`
MIRROR_URL="http://mirror.aarnet.edu.au/pub/ubuntu/archive/"
kvm-img create -f raw $SERVER_IMG $IMAGE_SIZE
# Create a disk image usinf a specified UUID
mkfs.ext4 -U $UUID $SERVER_IMG
# Turn off disk error checking
tune2fs -c 0 -i 0 $SERVER_IMG
mkdir $WORKING_DIR
mount -t ext4 -o loop,defaults,noatime $SERVER_IMG $WORKING_DIR
# Geberate a base system
debootstrap --arch amd64 $EXTRA_OPTS natty $WORKING_DIR ${MIRROR_URL}
CHROOT="chroot $WORKING_DIR"
echo "Copying config files"
echo -n "APT sources"
cp /etc/apt/sources.list $WORKING_DIR/etc/apt/sources.list
# Fixup file
$CHROOT sed -i "s/maverick/natty/" /etc/apt/sources.list
echo -e "\t[DONE]"
echo -n "fstab"
cat <<FSTAB > $WORKING_DIR/etc/fstab
#
UUID=$UUID / ext4 defaults,remount-ro 0 0
proc /proc proc nodev,noexec,nosuid 0 0
tmpfs /tmp tmpfs defaults,noexec,nosuid 0 0
FSTAB
echo -e "\t[DONE]"
echo "Timezone"
echo "Australia/Melbourne" > $WORKING_DIR/etc/timezone
$CHROOT dpkg-reconfigure --frontend noninteractive tzdata
echo "Enable serial console"
cat <<TTY > $WORKING_DIR/etc/init/ttyS0
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -L 115200 ttyS0 vt102
TTY
echo -n "Set up pv-grub"
mkdir $WORKING_DIR/boot/grub/
cat <<GRUB > $WORKING_DIR/boot/grub/menu.lst
default=0
timeout=5
title=DISTRO-NAME "KERNEL VERSION STRING"
root (hd0)
kernel /boot/vmlinuz-2.6.38-8-virtual ro console=hvc0 root=UUID=
initrd /boot/initrd-2.6.38-8-virtual
GRUB
echo -e "\t[DONE]"
@baylisscg
Copy link
Author

This is supposed to be able to take a basic NECTAR VM and use it to create a new VM image of Ubuntu Natty suitable for use on the NECTAR VM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment