From 3f7170025d5b27193e83fb84d9e53f5e381d80db Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 27 Sep 2011 17:53:11 -0500 Subject: [PATCH 01/10] Build tftpboot dir --- make_pxe.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 make_pxe.sh diff --git a/make_pxe.sh b/make_pxe.sh new file mode 100755 index 0000000..c544076 --- /dev/null +++ b/make_pxe.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# make_pxe.sh - Create a PXE boot environment +# +# make_pxe.sh destdir +# +# Assumes syslinux is installed +# Configues PXE for Ubuntu Natty and FreeDOS + +UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64 + +DEST_DIR=${1:-/tmp/tftpboot} +OPWD=`pwd` + +DEFAULT=$DEST_DIR/pxelinux.cfg/default +cat >$DEFAULT <$MENU <>$DEFAULT <>$MENU <>$DEFAULT <>$MENU < Date: Tue, 27 Sep 2011 22:19:32 -0500 Subject: [PATCH 02/10] Add memtest, local boot --- make_pxe.sh | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/make_pxe.sh b/make_pxe.sh index c544076..33a2405 100755 --- a/make_pxe.sh +++ b/make_pxe.sh @@ -8,9 +8,19 @@ UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64 -DEST_DIR=${1:-/tmp/tftpboot} +MEMTEST_VER=4.10 +MEMTEST_BIN=memtest86+-${MEMTEST_VER}.bin +MEMTEST_URL=http://www.memtest.org/download/${MEMTEST_VER}/ + +DEST_DIR=${1:-/tmp}/tftpboot OPWD=`pwd` +mkdir -p $DEST_DIR/pxelinux.cfg +cd $DEST_DIR +for i in memdisk menu.c32 pxelinux.0; do + cp -p /usr/lib/syslinux/$i $DEST_DIR +done + DEFAULT=$DEST_DIR/pxelinux.cfg/default cat >$DEFAULT <>$MENU <>$DEFAULT <>$MENU <>$MENU <>$DEFAULT <>$MENU < Date: Wed, 28 Sep 2011 14:14:33 -0500 Subject: [PATCH 03/10] Rename to build_pxe_boot.sh --- make_pxe.sh => build_pxe_boot.sh | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) rename make_pxe.sh => build_pxe_boot.sh (78%) diff --git a/make_pxe.sh b/build_pxe_boot.sh similarity index 78% rename from make_pxe.sh rename to build_pxe_boot.sh index 33a2405..16fa02c 100755 --- a/make_pxe.sh +++ b/build_pxe_boot.sh @@ -1,10 +1,10 @@ #!/bin/bash -# make_pxe.sh - Create a PXE boot environment +# build_pxe_boot.sh - Create a PXE boot environment # -# make_pxe.sh destdir +# build_pxe_boot.sh destdir # # Assumes syslinux is installed -# Configues PXE for Ubuntu Natty and FreeDOS +# Only needs to run as root if the destdir permissions require it UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64 @@ -24,20 +24,13 @@ done DEFAULT=$DEST_DIR/pxelinux.cfg/default cat >$DEFAULT <$MENU <>$MENU <>$MENU <>$MENU <>$DEFAULT <>$MENU < Date: Thu, 29 Sep 2011 10:48:49 -0700 Subject: [PATCH 04/10] autocreate a stack user if you are root instead of failing --- stack.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/stack.sh b/stack.sh index 4daa95d..29394ab 100755 --- a/stack.sh +++ b/stack.sh @@ -26,10 +26,6 @@ if ! grep -q natty /etc/lsb-release; then fi fi -#The following makes fresh mininmal installs (i.e. LXCs) happy -apt-get update -apt-get install -y sudo - # stack.sh keeps the list of **apt** and **pip** dependencies in external # files, along with config templates and other useful files. You can find these # in the ``files`` directory (next to this script). We will reference this @@ -40,12 +36,26 @@ if [ ! -d $FILES ]; then exit 1 fi -# you need to run this as a regular user with sudo priviledges +# If stack.sh is run as root, it automatically creates a stack user with +# sudo privileges and runs as that user. if [[ $EUID -eq 0 ]]; then - echo "This script cannot be run as root." 1>&2 - echo "You should run this script as the user you wish openstack to run as" 1>&2 - echo "The user will need to be a sudoer (without password)" 1>&2 - exit 1 + echo "You are running this script as root." + apt-get update + apt-get install -y sudo + if ! getent passwd | grep -q stack; then + echo "Creating a user called stack" + useradd -g sudo -s /bin/bash -m stack + fi + echo "Making sure stack has passwordless sudo" + sed -i "/^%sudo/ { / ALL/ { s/ ALL/ NOPASSWD:ALL/ }}" /etc/sudoers + echo "Copying files to stack user" + cp -r -f `pwd` /home/stack/ + THIS_DIR=$(basename $(dirname $(readlink -f $0))) + chown -R stack:sudo /home/stack/$THIS_DIR + echo "Running the script as stack in 3 seconds..." + sleep 3 + exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack + exit 0 fi From c945bf8dbf013ca947232311e5255b8fc21f2981 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 29 Sep 2011 16:15:23 -0500 Subject: [PATCH 05/10] Build devstack images --- build_pxe_boot.sh | 53 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/build_pxe_boot.sh b/build_pxe_boot.sh index 16fa02c..c5ef276 100755 --- a/build_pxe_boot.sh +++ b/build_pxe_boot.sh @@ -1,9 +1,10 @@ #!/bin/bash # build_pxe_boot.sh - Create a PXE boot environment # -# build_pxe_boot.sh destdir +# build_pxe_boot.sh [-k kernel-version] destdir # # Assumes syslinux is installed +# Assumes devstack files are in `pwd`/pxe # Only needs to run as root if the destdir permissions require it UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64 @@ -12,8 +13,15 @@ MEMTEST_VER=4.10 MEMTEST_BIN=memtest86+-${MEMTEST_VER}.bin MEMTEST_URL=http://www.memtest.org/download/${MEMTEST_VER}/ +KVER=`uname -r` +if [ "$1" = "-k" ]; then + KVER=$2 + shift;shift +fi + DEST_DIR=${1:-/tmp}/tftpboot OPWD=`pwd` +PROGDIR=`dirname $0` mkdir -p $DEST_DIR/pxelinux.cfg cd $DEST_DIR @@ -31,17 +39,42 @@ MENU TITLE PXE Boot Menu EOF -# Get Ubuntu netboot +# Setup devstack boot mkdir -p $DEST_DIR/ubuntu -cd $DEST_DIR/ubuntu -wget -N --quiet $UBUNTU_MIRROR/linux -wget -N --quiet $UBUNTU_MIRROR/initrd.gz +if [ ! -d $OPWD/pxe ]; then + mkdir -p $OPWD/pxe +fi +if [ ! -r $OPWD/pxe/vmlinuz-${KVER}-generic ]; then + if [ ! -r /boot/vmlinuz-${KVER}-generic ]; then + echo "No kernel found" + else + cp -p /boot/vmlinuz-${KVER}-generic $OPWD/pxe + fi +fi +cp -p $OPWD/pxe/vmlinuz-${KVER}-generic $DEST_DIR/ubuntu +if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then + $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz +fi +cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu +cat >>$DEFAULT <>$DEFAULT <>$DEFAULT <>$DEFAULT < Date: Thu, 29 Sep 2011 16:35:43 -0500 Subject: [PATCH 06/10] optionally only create the chroot --- make_image.sh | 103 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/make_image.sh b/make_image.sh index 3bfa683..cfef136 100755 --- a/make_image.sh +++ b/make_image.sh @@ -1,27 +1,40 @@ #!/bin/bash # make_image.sh - Create Ubuntu images in various formats # -# make_image.sh release format -# # Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw # # Requires sudo to root ROOTSIZE=${ROOTSIZE:-8192} SWAPSIZE=${SWAPSIZE:-1024} +MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"} usage() { - echo "$0 - Create Ubuntu images" + echo "Usage: $0 - Create Ubuntu images" echo "" - echo "$0 [-r rootsize] [-s swapsize] release format" + echo "$0 [-m] [-r rootsize] [-s swapsize] release format" + echo "$0 -C [-m] release chrootdir" + echo "$0 -I [-r rootsize] [-s swapsize] chrootdir format" + echo "" + echo "-C - Create the initial chroot dir" + echo "-I - Create the final image from a chroot" + echo "-m - minimal installation" + echo "-r size - root fs size in MB" + echo "-s size - swap fs size in MB" + echo "release - Ubuntu release: jaunty - oneric" + echo "format - image format: qcow2, vmdk, vdi, vhd, xen, raw, fs" exit 1 } -while getopts hm:r:s: c; do +while getopts CIhmr:s: c; do case $c in + C) CHROOTONLY=1 + ;; + I) IMAGEONLY=1 + ;; h) usage ;; - m) MIRROR=$OPTARG + m) MINIMAL=1 ;; r) ROOTSIZE=$OPTARG ;; @@ -31,8 +44,26 @@ while getopts hm:r:s: c; do done shift `expr $OPTIND - 1` +if [ ! "$#" -eq "2" -o -n $CHROOTONLY -a -n $IMAGEONLY ]; then + usage +fi + +# Default args RELEASE=$1 FORMAT=$2 +CHROOTDIR="" + +if [ -n "$CHROOTONLY" ]; then + RELEASE=$1 + CHROOTDIR=$2 + FORMAT="pass" +fi + +if [ -n "$IMAGEONLY" ]; then + CHROOTDIR=$1 + FORMAT=$2 + RELEASE="pass" +fi case $FORMAT in kvm|qcow2) FORMAT=qcow2 @@ -60,6 +91,7 @@ case $FORMAT in QFORMAT=raw HYPER=kvm ;; + pass) ;; *) echo "Unknown format: $FORMAT" usage esac @@ -70,6 +102,7 @@ case $RELEASE in lucid) ;; karmic) ;; jaunty) ;; + pass) ;; *) echo "Unknown release: $RELEASE" usage ;; @@ -80,17 +113,59 @@ if [ -z `which vmbuilder` ]; then sudo apt-get install ubuntu-vm-builder fi +if [ -n "$CHROOTONLY" ]; then + # Build a chroot directory + HYPER=kvm + if [ "$MINIMAL" = 1 ]; then + ARGS="--variant=minbase" + for i in $MIN_PKGS; do + ARGS="$ARGS --addpkg=$i" + done + fi + sudo vmbuilder $HYPER ubuntu $ARGS \ + --suite $RELEASE \ + --only-chroot \ + --chroot-dir=$CHROOTDIR \ + --overwrite \ + --addpkg=$MIN_PKGS \ + + sudo cp -p files/sources.list $CHROOTDIR/etc/apt/sources.list + sudo chroot $CHROOTDIR apt-get update + + exit 0 +fi + # Build the image +TMPDIR=tmp TMPDISK=`mktemp imgXXXXXXXX` SIZE=$[$ROOTSIZE+$SWAPSIZE+1] -dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE -sudo vmbuilder $HYPER ubuntu --suite $RELEASE \ - -o \ - --rootsize=$ROOTSIZE \ - --swapsize=$SWAPSIZE \ - --tmpfs - \ - --addpkg=openssh-server \ - --raw=$TMPDISK \ +dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1 + +if [ -n "$IMAGEONLY" ]; then + # Build image from chroot + sudo vmbuilder $HYPER ubuntu $ARGS \ + --existing-chroot=$CHR \ + --overwrite \ + --rootsize=$ROOTSIZE \ + --swapsize=$SWAPSIZE \ + --tmpfs - \ + --raw=$TMPDISK \ + +else + # Do the whole shebang in one pass + ARGS="--variant=minbase" + for i in $MIN_PKGS; do + ARGS="$ARGS --addpkg=$i" + done + sudo vmbuilder $HYPER ubuntu $ARGS \ + --suite $RELEASE \ + --overwrite \ + --rootsize=$ROOTSIZE \ + --swapsize=$SWAPSIZE \ + --tmpfs - \ + --raw=$TMPDISK \ + +fi if [ "$FORMAT" = "raw" ]; then # Get image From 407ee7ee5e279554afa1d91a6760156b57cbef10 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 29 Sep 2011 16:38:59 -0500 Subject: [PATCH 07/10] calls make_image.sh to build the base install --- build_pxe_ramdisk.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build_pxe_ramdisk.sh b/build_pxe_ramdisk.sh index 648fc3b..197bfc9 100755 --- a/build_pxe_ramdisk.sh +++ b/build_pxe_ramdisk.sh @@ -6,17 +6,19 @@ if [ ! "$#" -eq "1" ]; then exit 1 fi +PROGDIR=`dirname $0` + # Source params source ./stackrc # clean install of natty if [ ! -d natty-base ]; then - debootstrap natty natty-base + $PROGDIR/make_image.sh -C natty natty-base # copy kernel modules... # NOTE(ja): is there a better way to do this? cp -pr /lib/modules/`uname -r` natty-base/lib/modules - cp files/sources.list natty-base/etc/apt/sources.list - chroot natty-base apt-get update + # a simple password - pass + echo root:pass | chroot natty-base chpasswd fi # prime natty with as many apt/pips as we can From 783cc7774f6888a430a05749ce30908e621c52fd Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 29 Sep 2011 18:43:44 -0500 Subject: [PATCH 08/10] Fix kernel version issue --- build_pxe_boot.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build_pxe_boot.sh b/build_pxe_boot.sh index c5ef276..6d264bd 100755 --- a/build_pxe_boot.sh +++ b/build_pxe_boot.sh @@ -44,16 +44,17 @@ mkdir -p $DEST_DIR/ubuntu if [ ! -d $OPWD/pxe ]; then mkdir -p $OPWD/pxe fi -if [ ! -r $OPWD/pxe/vmlinuz-${KVER}-generic ]; then - if [ ! -r /boot/vmlinuz-${KVER}-generic ]; then +if [ ! -r $OPWD/pxe/vmlinuz-${KVER} ]; then + sudo chmod 644 /boot/vmlinuz-${KVER} + if [ ! -r /boot/vmlinuz-${KVER} ]; then echo "No kernel found" else - cp -p /boot/vmlinuz-${KVER}-generic $OPWD/pxe + cp -p /boot/vmlinuz-${KVER} $OPWD/pxe fi fi -cp -p $OPWD/pxe/vmlinuz-${KVER}-generic $DEST_DIR/ubuntu +cp -p $OPWD/pxe/vmlinuz-${KVER} $DEST_DIR/ubuntu if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then - $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz + sudo $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz fi cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu cat >>$DEFAULT < Date: Thu, 29 Sep 2011 21:30:27 -0500 Subject: [PATCH 09/10] Minor fixes --- build_pxe_boot.sh | 3 ++- make_image.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build_pxe_boot.sh b/build_pxe_boot.sh index 6d264bd..a93e3f0 100755 --- a/build_pxe_boot.sh +++ b/build_pxe_boot.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # build_pxe_boot.sh - Create a PXE boot environment # # build_pxe_boot.sh [-k kernel-version] destdir @@ -54,6 +54,7 @@ if [ ! -r $OPWD/pxe/vmlinuz-${KVER} ]; then fi cp -p $OPWD/pxe/vmlinuz-${KVER} $DEST_DIR/ubuntu if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then + cd $OPWD sudo $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz fi cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu diff --git a/make_image.sh b/make_image.sh index cfef136..81dd97c 100755 --- a/make_image.sh +++ b/make_image.sh @@ -44,7 +44,7 @@ while getopts CIhmr:s: c; do done shift `expr $OPTIND - 1` -if [ ! "$#" -eq "2" -o -n $CHROOTONLY -a -n $IMAGEONLY ]; then +if [ ! "$#" -eq "2" -o -n "$CHROOTONLY" -a -n "$IMAGEONLY" ]; then usage fi From 958fa3defa0da029b1a78f164f8f175d7ae80a15 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Fri, 30 Sep 2011 09:22:23 -0500 Subject: [PATCH 10/10] Fix up PXE boot filenames --- build_pxe_boot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_pxe_boot.sh b/build_pxe_boot.sh index a93e3f0..2c4cc0e 100755 --- a/build_pxe_boot.sh +++ b/build_pxe_boot.sh @@ -63,19 +63,19 @@ cat >>$DEFAULT <>$DEFAULT <