From 9c4ced8ce95068466f6c46efce222f1c58063a5d Mon Sep 17 00:00:00 2001 From: Dreamcat4 Date: Tue, 9 Nov 2010 06:35:29 +0800 Subject: [PATCH 01/22] Build the Ubuntu 10.10 Maverick vagrant box - minus the devstructure dependencies --- build-iso | 2 +- build-vagrant | 2 +- config.sh | 3 ++- devstructure.seed.m4 | 6 +++--- devstructure.sh.m4 | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/build-iso b/build-iso index a4660d1..63feefc 100755 --- a/build-iso +++ b/build-iso @@ -37,7 +37,7 @@ do -D __USERNAME__="$USERNAME" \ -D __PASSWORD__="$PASSWORD" \ "devstructure.seed.m4" >"$COPY/preseed/devstructure.seed" - cp "$PUBLIC_KEY" "setup.sh" "$COPY/" + # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" cp "$PUBLIC_KEY" "sudoers" "$COPY/" m4 \ -D __USERNAME__="$USERNAME" \ diff --git a/build-vagrant b/build-vagrant index a8f415e..92d5f07 100755 --- a/build-vagrant +++ b/build-vagrant @@ -34,7 +34,7 @@ do # Now build the Vagrant box file. vagrant package --base "$VBOX" mv "package.box" \ - "devstructure$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + "maverick$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" done diff --git a/config.sh b/config.sh index 735085d..5cd7b6d 100644 --- a/config.sh +++ b/config.sh @@ -9,7 +9,8 @@ : ${ARCHS:="i386 amd64"} # Hardcoded host information. -: ${HOST:="devstructure"} +# : ${HOST:="devstructure"} +: ${HOST:="vagrant-ubuntu-maverick"} : ${DOMAIN:="vagrantup.com"} : ${ROOT_PASSWORD:="vagrant"} : ${USERNAME:="vagrant"} diff --git a/devstructure.seed.m4 b/devstructure.seed.m4 index 10d2729..5b29d03 100644 --- a/devstructure.seed.m4 +++ b/devstructure.seed.m4 @@ -37,9 +37,9 @@ d-i user-setup/encrypt-home boolean false # Packages and repositories. d-i mirror/http/proxy string -d-i apt-setup/local0/repository string http://packages.devstructure.com maverick main -d-i apt-setup/local0/source boolean false -d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i apt-setup/local0/repository string http://packages.devstructure.com maverick main +# d-i apt-setup/local0/source boolean false +# d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg tasksel tasksel/first multiselect d-i pkgsel/include string curl openssh-server #d-i pkgsel/include string openssh-server sandbox blueprint diff --git a/devstructure.sh.m4 b/devstructure.sh.m4 index cdb2c91..dc105b8 100644 --- a/devstructure.sh.m4 +++ b/devstructure.sh.m4 @@ -7,9 +7,9 @@ chown 1000:1000 \ /target/home/__USERNAME__/.ssh \ /target/home/__USERNAME__/.ssh/authorized_keys -cp /cdrom/setup.sh /target/etc/profile.d/ -chmod 644 /target/etc/profile.d/setup.sh -chown 0:0 /target/etc/profile.d/setup.sh +# cp /cdrom/setup.sh /target/etc/profile.d/ +# chmod 644 /target/etc/profile.d/setup.sh +# chown 0:0 /target/etc/profile.d/setup.sh cp /cdrom/sudoers /target/etc/ chmod 440 /target/etc/sudoers @@ -19,5 +19,5 @@ chroot /target sh -c ' set -e unset DEBCONF_REDIR DEBCONF_FRONTEND DEBIAN_HAS_FRONTEND DEBIAN_FRONTEND apt-get update - apt-get -y install sandbox blueprint + # apt-get -y install sandbox blueprint ' From 27cd0a09a21ceb638b7b7e2b745522f55c6b4e07 Mon Sep 17 00:00:00 2001 From: Dreamcat4 Date: Sun, 21 Nov 2010 03:30:34 +0800 Subject: [PATCH 02/22] Add 'ruby' metapackage to base dependencies --- build-vagrant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-vagrant b/build-vagrant index 92d5f07..e2f032e 100755 --- a/build-vagrant +++ b/build-vagrant @@ -19,7 +19,7 @@ do # Install Ruby, RubyGems, and Chef as Vagrant requires. eval "$SSH \" set -e - sudo apt-get -y install build-essential ruby-dev rubygems + sudo apt-get -y install build-essential ruby ruby-dev rubygems sudo gem install --no-rdoc --no-ri chef echo 'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/gems/1.8/bin\"' | sudo tee /etc/environment >/dev/null \"" From 86d5b192614cd1f89e5c1891dcf29d648a0383a2 Mon Sep 17 00:00:00 2001 From: Dreamcat4 Date: Sun, 21 Nov 2010 04:05:17 +0800 Subject: [PATCH 03/22] Shorten hostname --- config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.sh b/config.sh index 5cd7b6d..126dcb7 100644 --- a/config.sh +++ b/config.sh @@ -10,7 +10,7 @@ # Hardcoded host information. # : ${HOST:="devstructure"} -: ${HOST:="vagrant-ubuntu-maverick"} +: ${HOST:="maverick"} : ${DOMAIN:="vagrantup.com"} : ${ROOT_PASSWORD:="vagrant"} : ${USERNAME:="vagrant"} From 3077759a9e8735a3127be15b0b429bfb5f978722 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Tue, 30 Nov 2010 18:42:37 +0000 Subject: [PATCH 04/22] Remove hdiutil call and use builtin mount commands. This should add linux compat [WIP] --- build-iso | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build-iso b/build-iso index 63feefc..c3e1243 100755 --- a/build-iso +++ b/build-iso @@ -19,9 +19,10 @@ do # Make a writable copy of the original ISO. This uses the `hdiutil` # command that is specific to Mac OS X. - hdiutil attach -mountpoint "mount" "$ORIG" + mkdir -p isomount + mount isomount "${ORIG}" rsync -a "mount/" "$COPY" - hdiutil detach "mount" + umount isomount chmod -R +w "$COPY" # Customize the writable copy. From 54902676e815b036d04ba6ca06364552856248b8 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 1 Dec 2010 13:39:49 +0000 Subject: [PATCH 05/22] Remove devstructure branding on files. --- build-iso | 23 +++++++++++++---------- build-vagrant | 4 ++-- build-vbox | 4 ++-- clean-iso | 2 +- clean-vagrant | 2 +- clean-vbox | 4 ++-- config.sh | 8 +++++++- devstructure.seed.m4 => default.seed.m4 | 6 +++--- devstructure.sh.m4 => default.sh.m4 | 0 isolinux.cfg | 6 ------ isolinux.cfg.m4 | 6 ++++++ 11 files changed, 37 insertions(+), 28 deletions(-) rename devstructure.seed.m4 => default.seed.m4 (92%) rename devstructure.sh.m4 => default.sh.m4 (100%) delete mode 100644 isolinux.cfg create mode 100644 isolinux.cfg.m4 diff --git a/build-iso b/build-iso index c3e1243..2fb8301 100755 --- a/build-iso +++ b/build-iso @@ -8,7 +8,7 @@ for ARCH in $ARCHS do ORIG="ubuntu-$VERSION-$DISTRO-$ARCH.iso" COPY="ubuntu-$VERSION-$DISTRO-$ARCH" - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" # Download the original ISO if it isn't present already. [ -f "$ORIG" ] || curl -L -o "$ORIG" \ @@ -20,13 +20,15 @@ do # Make a writable copy of the original ISO. This uses the `hdiutil` # command that is specific to Mac OS X. mkdir -p isomount - mount isomount "${ORIG}" - rsync -a "mount/" "$COPY" - umount isomount + sudo mount -o loop,user "${ORIG}" isomount + rsync -a "isomount/" "$COPY" + sudo umount isomount chmod -R +w "$COPY" # Customize the writable copy. - cp "isolinux.cfg" "$COPY/isolinux/" + m4 \ + -D __LABEL__="${LABEL}" \ + "isolinux.cfg.m4" > "$COPY/isolinux/isolinux.cfg" m4 \ -D __HOST__="$HOST" \ -D __DOMAIN__="$DOMAIN" \ @@ -37,20 +39,21 @@ do -D __ROOT_PASSWORD__="$ROOT_PASSWORD" \ -D __USERNAME__="$USERNAME" \ -D __PASSWORD__="$PASSWORD" \ - "devstructure.seed.m4" >"$COPY/preseed/devstructure.seed" + -D __LABEL__="${LABEL}" \ + "default.seed.m4" >"$COPY/preseed/${LABEL}.seed" + # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" cp "$PUBLIC_KEY" "sudoers" "$COPY/" m4 \ -D __USERNAME__="$USERNAME" \ -D __PUBLIC_KEY__="$PUBLIC_KEY" \ - "devstructure.sh.m4" >"$COPY/devstructure.sh" - + "default.sh.m4" >"$COPY/${LABEL}.sh" # Build a custom ISO. - mkisofs -r -V "Ubuntu $VERSION for DevStructure" \ + mkisofs -r -V "Ubuntu $VERSION for ${LABEL}" \ -cache-inodes -J -l -no-emul-boot \ -b isolinux/isolinux.bin \ -c isolinux/boot.cat \ -boot-load-size 4 -boot-info-table \ -o "$ISO" "$COPY" - + echo "Completed building custom is for ${LABEL} [${ARCH}]" done diff --git a/build-vagrant b/build-vagrant index e2f032e..ede0812 100755 --- a/build-vagrant +++ b/build-vagrant @@ -6,7 +6,7 @@ set -e for ARCH in $ARCHS do - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" # Start the virtual machine. Spin slowly until SSH is usable. VBoxManage startvm "$VBOX" --type gui @@ -34,7 +34,7 @@ do # Now build the Vagrant box file. vagrant package --base "$VBOX" mv "package.box" \ - "maverick$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" done diff --git a/build-vbox b/build-vbox index e581b8e..b048169 100755 --- a/build-vbox +++ b/build-vbox @@ -6,8 +6,8 @@ set -e for ARCH in $ARCHS do - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" # Create and configure a virtual machine through VirtualBox. VBoxManage createvm \ diff --git a/clean-iso b/clean-iso index f57cfaa..8c05724 100755 --- a/clean-iso +++ b/clean-iso @@ -6,5 +6,5 @@ for ARCH in $ARCHS do - rm -f "devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + rm -f "${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" done diff --git a/clean-vagrant b/clean-vagrant index 0c87065..aedaccf 100755 --- a/clean-vagrant +++ b/clean-vagrant @@ -6,5 +6,5 @@ for ARCH in $ARCHS do - rm -f "devstructure$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + rm -f "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" done diff --git a/clean-vbox b/clean-vbox index d9b4fd3..9dffeb9 100755 --- a/clean-vbox +++ b/clean-vbox @@ -6,8 +6,8 @@ for ARCH in $ARCHS do - ISO="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH.iso" - VBOX="devstructure-ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" VBoxManage controlvm "$VBOX" poweroff VBoxManage storagectl "$VBOX" --name IDE --remove diff --git a/config.sh b/config.sh index 126dcb7..1d515de 100644 --- a/config.sh +++ b/config.sh @@ -5,6 +5,11 @@ : ${DISTRO:="server"} : ${RELEASE:="latest"} +# Generated ISO Prefix +: ${ISOPREFIX:="vagrant"} +: ${LABEL:="vagrant"} + + # Architectures being built. : ${ARCHS:="i386 amd64"} @@ -29,4 +34,5 @@ "} # Fully-qualified pathname of VBoxGuestAdditions.iso. -: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} +#: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} +: ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} diff --git a/devstructure.seed.m4 b/default.seed.m4 similarity index 92% rename from devstructure.seed.m4 rename to default.seed.m4 index 5b29d03..b7e3316 100644 --- a/devstructure.seed.m4 +++ b/default.seed.m4 @@ -1,4 +1,4 @@ -# Preseed Ubuntu for DevStructure. +# Preseed Ubuntu for vagrant. # Network. d-i netcfg/get_hostname string __HOST__ @@ -28,7 +28,7 @@ d-i base-installer/kernel/override-image string __KERNEL__ d-i passwd/root-password password __ROOT_PASSWORD__ d-i passwd/root-password-again password __ROOT_PASSWORD__ d-i passwd/user-uid string 1000 -d-i passwd/user-fullname string DevStructure +d-i passwd/user-fullname string VagrantUser d-i passwd/username string __USERNAME__ d-i passwd/user-password password __PASSWORD__ d-i passwd/user-password-again password __PASSWORD__ @@ -54,4 +54,4 @@ d-i cdrom-detect/eject boolean true d-i debian-installer/splash boolean false # Everything else. -d-i preseed/late_command string sh /cdrom/devstructure.sh +d-i preseed/late_command string sh /cdrom/__LABEL__.sh diff --git a/devstructure.sh.m4 b/default.sh.m4 similarity index 100% rename from devstructure.sh.m4 rename to default.sh.m4 diff --git a/isolinux.cfg b/isolinux.cfg deleted file mode 100644 index c3df7ca..0000000 --- a/isolinux.cfg +++ /dev/null @@ -1,6 +0,0 @@ -default devstructure -timeout 1 -label devstructure - menu label ^Install Ubuntu Server for DevStructure - kernel /install/vmlinuz - append file=/cdrom/preseed/devstructure.seed debian-installer/locale=en_US console-setup/layoutcode=us localechooser/translation/warn-light=true localechooser/translation/warn-severe=true initrd=/install/initrd.gz quiet -- diff --git a/isolinux.cfg.m4 b/isolinux.cfg.m4 new file mode 100644 index 0000000..4ff617b --- /dev/null +++ b/isolinux.cfg.m4 @@ -0,0 +1,6 @@ +default __LABEL__ +timeout 1 +label __LABEL__ + menu label ^Install Ubuntu Server for __LABEL__ + kernel /install/vmlinuz + append file=/cdrom/preseed/__LABEL__.seed debian-installer/locale=en_US console-setup/layoutcode=us localechooser/translation/warn-light=true localechooser/translation/warn-severe=true initrd=/install/initrd.gz quiet -- From 7fa67932e3371a02609afa1a1aead0902f38fdb3 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 1 Dec 2010 16:10:02 +0000 Subject: [PATCH 06/22] Ensure private ssh key has correct permissions --- build-vbox | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-vbox b/build-vbox index b048169..007238b 100755 --- a/build-vbox +++ b/build-vbox @@ -61,6 +61,8 @@ do # Start the virtual machine and the OS installation. This will take # a while so this time it gets a GUI. Spin slowly until SSH is usable. VBoxManage startvm "$VBOX" --type gui + ## Set better perms on the private key to avoid ssh abort + chmod 600 ${PRIVATE_KEY} until eval "$SSH exit" do sleep 60 From 03e55a1889caf3d8fee8a513cb2184dc126ca6b6 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Sun, 5 Dec 2010 01:43:53 +0000 Subject: [PATCH 07/22] Add an rvmrc to be able to use this with different versions of ruby easily --- .rvmrc | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .rvmrc diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..5cc9b05 --- /dev/null +++ b/.rvmrc @@ -0,0 +1,8 @@ +ruby_ver=ruby-1.9.2 +#gemset_name=vagrant +gemset_name=${gemset_name:-$(basename $(pwd))} + + +## The rest is auto... + +rvm_install_on_use_flag=1 rvm --create use ${ruby_ver}@${gemset_name:-$(basename $(pwd))} > /dev/null From 98c0b9a82341e18d7aaf8e9450679623d8b6f195 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Sun, 5 Dec 2010 01:46:43 +0000 Subject: [PATCH 08/22] Add a Gemfile and dep for vagrant gem so it is easy to ensure all deps are available for this project (useful if you use rvmrc for segragation) --- Gemfile | 6 ++++++ Gemfile.lock | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..96fb53b --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +# A sample Gemfile +source "http://rubygems.org" + +# gem "rails" + +gem "vagrant" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c031d7d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,35 @@ +GEM + remote: http://rubygems.org/ + specs: + abstract (1.0.0) + archive-tar-minitar (0.5.2) + erubis (2.6.6) + abstract (>= 1.0.0) + ffi (0.6.3) + rake (>= 0.8.7) + i18n (0.4.2) + json (1.4.6) + mario (0.0.6) + net-scp (1.0.4) + net-ssh (>= 1.99.1) + net-ssh (2.0.23) + rake (0.8.7) + thor (0.14.6) + vagrant (0.6.8) + archive-tar-minitar (= 0.5.2) + erubis (~> 2.6.6) + i18n (~> 0.4.1) + json (~> 1.4.6) + mario (~> 0.0.6) + net-scp (~> 1.0.3) + net-ssh (~> 2.0.23) + thor (~> 0.14.2) + virtualbox (~> 0.7.6) + virtualbox (0.7.6) + ffi (~> 0.6.3) + +PLATFORMS + ruby + +DEPENDENCIES + vagrant From c81f88a82615f2966c1c90a3b87c39a45862003f Mon Sep 17 00:00:00 2001 From: Pritesh Date: Sun, 5 Dec 2010 01:45:44 +0000 Subject: [PATCH 09/22] Add snapshot after initial install and after install of vagrant deps so we can rerun without having to start from scratch completely --- build-vagrant | 7 ++++++- build-vbox | 2 +- clean-vbox | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build-vagrant b/build-vagrant index ede0812..d80c755 100755 --- a/build-vagrant +++ b/build-vagrant @@ -8,6 +8,9 @@ for ARCH in $ARCHS do VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + # Reset to snapshot at time of initial build + VBoxManage snapshot "${VBOX}" restore "AUTO_${LABEL}_base_build #000001" + # Start the virtual machine. Spin slowly until SSH is usable. VBoxManage startvm "$VBOX" --type gui #VBoxHeadless --startvm "$VBOX" --vrdp config @@ -36,7 +39,9 @@ do mv "package.box" \ "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" + # Snapshot after vagrant dep install.... + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_vagrant_base #000002" --description "Snapshot taken after installing vagrant dependencies" done # Creating Vagrant boxes ruins the normal VM setup so get rid of them. -eval "$(dirname $0)/clean-vbox" +#eval "$(dirname $0)/clean-vbox" diff --git a/build-vbox b/build-vbox index 007238b..1ac5121 100755 --- a/build-vbox +++ b/build-vbox @@ -99,5 +99,5 @@ do do sleep 1 done - + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_base_build #000001" --description "Snapshot taken after initial build to be able to restore back when recreating vagrant boxes" done diff --git a/clean-vbox b/clean-vbox index 9dffeb9..d14bd8f 100755 --- a/clean-vbox +++ b/clean-vbox @@ -10,6 +10,8 @@ do VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" VBoxManage controlvm "$VBOX" poweroff + VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_base_build #000001" + VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_build #000002" VBoxManage storagectl "$VBOX" --name IDE --remove VBoxManage storagectl "$VBOX" --name SATA --remove VBoxManage unregistervm "$VBOX" From 38074b6c988fd55d1b105d865a3c78687fc4ca5f Mon Sep 17 00:00:00 2001 From: Pritesh Date: Sun, 5 Dec 2010 19:41:22 +0000 Subject: [PATCH 10/22] Remove the generated udev rule for net device before box generation so network isn't locked to the wrong mac addr --- build-vagrant | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build-vagrant b/build-vagrant index d80c755..cb0b30a 100755 --- a/build-vagrant +++ b/build-vagrant @@ -26,7 +26,10 @@ do sudo gem install --no-rdoc --no-ri chef echo 'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/gems/1.8/bin\"' | sudo tee /etc/environment >/dev/null \"" - + # Remove generated udev rule for network device as the mac address on the next instantiation is not going to match + eval "$SSH \" + rm /etc/udev/rules.d/70-persistent-net.rules + \"" # Shutdown the virtual machine. eval "$SSH \"sudo shutdown -h now\"" until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off" From 7f3a34a079d6cfd8ffc729de7ba08407d4a18e5b Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 15 Dec 2010 17:10:21 +0000 Subject: [PATCH 11/22] rename the "username" variable to user_name so it doesn't use the environment variable username from the current user. This meant the specified username wasn't created on the VM, only your current username was used --- build-iso | 6 +++--- config.sh | 4 ++-- default.seed.m4 | 2 +- default.sh.m4 | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-iso b/build-iso index 2fb8301..b2d8c48 100755 --- a/build-iso +++ b/build-iso @@ -37,7 +37,7 @@ do || echo server )" \ -D __ROOT_PASSWORD__="$ROOT_PASSWORD" \ - -D __USERNAME__="$USERNAME" \ + -D __USER_NAME__="$USER_NAME" \ -D __PASSWORD__="$PASSWORD" \ -D __LABEL__="${LABEL}" \ "default.seed.m4" >"$COPY/preseed/${LABEL}.seed" @@ -45,7 +45,7 @@ do # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" cp "$PUBLIC_KEY" "sudoers" "$COPY/" m4 \ - -D __USERNAME__="$USERNAME" \ + -D __USER_NAME__="$USER_NAME" \ -D __PUBLIC_KEY__="$PUBLIC_KEY" \ "default.sh.m4" >"$COPY/${LABEL}.sh" # Build a custom ISO. @@ -55,5 +55,5 @@ do -c isolinux/boot.cat \ -boot-load-size 4 -boot-info-table \ -o "$ISO" "$COPY" - echo "Completed building custom is for ${LABEL} [${ARCH}]" + echo "Completed building custom iso for ${LABEL} [${ARCH}]" done diff --git a/config.sh b/config.sh index 1d515de..dc73a30 100644 --- a/config.sh +++ b/config.sh @@ -18,7 +18,7 @@ : ${HOST:="maverick"} : ${DOMAIN:="vagrantup.com"} : ${ROOT_PASSWORD:="vagrant"} -: ${USERNAME:="vagrant"} +: ${USER_NAME:="vagrant"} : ${PASSWORD:="vagrant"} # SSH key to be authorized in virtual machines. @@ -30,7 +30,7 @@ : ${SSH:="ssh \ -o UserKnownHostsFile=/dev/null \ -o StrictHostKeyChecking=no \ - -l \"$USERNAME\" -i \"$PRIVATE_KEY\" -p 2222 localhost \ + -l \"$USER_NAME\" -i \"$PRIVATE_KEY\" -p 2222 localhost \ "} # Fully-qualified pathname of VBoxGuestAdditions.iso. diff --git a/default.seed.m4 b/default.seed.m4 index b7e3316..b07678e 100644 --- a/default.seed.m4 +++ b/default.seed.m4 @@ -29,7 +29,7 @@ d-i passwd/root-password password __ROOT_PASSWORD__ d-i passwd/root-password-again password __ROOT_PASSWORD__ d-i passwd/user-uid string 1000 d-i passwd/user-fullname string VagrantUser -d-i passwd/username string __USERNAME__ +d-i passwd/username string __USER_NAME__ d-i passwd/user-password password __PASSWORD__ d-i passwd/user-password-again password __PASSWORD__ d-i user-setup/allow-password-weak boolean true diff --git a/default.sh.m4 b/default.sh.m4 index dc105b8..4e6baba 100644 --- a/default.sh.m4 +++ b/default.sh.m4 @@ -1,11 +1,11 @@ set -e -mkdir /target/home/__USERNAME__/.ssh -cat /cdrom/__PUBLIC_KEY__ >/target/home/__USERNAME__/.ssh/authorized_keys -chmod 700 /target/home/__USERNAME__/.ssh +mkdir /target/home/__USER_NAME__/.ssh +cat /cdrom/__PUBLIC_KEY__ >/target/home/__USER_NAME__/.ssh/authorized_keys +chmod 700 /target/home/__USER_NAME__/.ssh chown 1000:1000 \ - /target/home/__USERNAME__/.ssh \ - /target/home/__USERNAME__/.ssh/authorized_keys + /target/home/__USER_NAME__/.ssh \ + /target/home/__USER_NAME__/.ssh/authorized_keys # cp /cdrom/setup.sh /target/etc/profile.d/ # chmod 644 /target/etc/profile.d/setup.sh From d49da7f9e8e5ab08ebaed2904edab06b015196ca Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 15 Dec 2010 17:15:13 +0000 Subject: [PATCH 12/22] Remove the persistent-net udev rule file before packaging the box. On vagrant up, a new mac addr is assigned to the box which makes the OS barf on network name assignment --- build-vagrant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-vagrant b/build-vagrant index cb0b30a..478c9f5 100755 --- a/build-vagrant +++ b/build-vagrant @@ -28,7 +28,7 @@ do \"" # Remove generated udev rule for network device as the mac address on the next instantiation is not going to match eval "$SSH \" - rm /etc/udev/rules.d/70-persistent-net.rules + sudo rm /etc/udev/rules.d/70-persistent-net.rules \"" # Shutdown the virtual machine. eval "$SSH \"sudo shutdown -h now\"" From 698da0940afd666b5732adb6703a0ab990fe2fce Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 15 Dec 2010 17:17:13 +0000 Subject: [PATCH 13/22] Fix order of deleting snapshots and also the name of the second snapshot --- clean-vbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean-vbox b/clean-vbox index d14bd8f..5024d21 100755 --- a/clean-vbox +++ b/clean-vbox @@ -10,8 +10,8 @@ do VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" VBoxManage controlvm "$VBOX" poweroff + VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_base #000002" VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_base_build #000001" - VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_build #000002" VBoxManage storagectl "$VBOX" --name IDE --remove VBoxManage storagectl "$VBOX" --name SATA --remove VBoxManage unregistervm "$VBOX" From 09c3ec56a532a4382e3f326c0598b394a3220c1a Mon Sep 17 00:00:00 2001 From: Pritesh Date: Wed, 15 Dec 2010 17:37:33 +0000 Subject: [PATCH 14/22] Add support for hostiocache enabling on ext4 filesystems --- build-vagrant | 17 +++++++++++++++++ build-vbox | 18 +++++++++++++++++- config.sh | 6 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/build-vagrant b/build-vagrant index 478c9f5..b00e3dc 100755 --- a/build-vagrant +++ b/build-vagrant @@ -37,6 +37,23 @@ do sleep 1 done + ## Check if vagrant box dir for vagrant drives is hosted on an ext4 fs. If so, ensure hostiocache is enabled to avoid corruption + [ ${HOSTIOCACHE} ] || { + vbox_hd_dir="$HOME/.vagrant/boxes" + HOSTIOCACHE=""; + for dir in ${vbox_hd_dir}; do + vbox_hd_dir_disk=$(df ${dir} | tail -n 1 | cut -d" " -f1); + vbox_hd_dir_fs="$(grep ${vbox_hd_dir_disk} /proc/mounts | awk '{ print $3 }')" + [ "$vbox_hd_dir_fs" = "ext4" ] && { + echo "Auto enabling HOSTIOCACHE due ext4 fs [${dir}]"; + HOSTIOCACHE=" --hostiocache on "; + VBoxManage storagectl "$VBOX" \ + --name SATA ${HOSTIOCACHE} \ + break; + } + done + } + # Now build the Vagrant box file. vagrant package --base "$VBOX" mv "package.box" \ diff --git a/build-vbox b/build-vbox index 1ac5121..cb5457b 100755 --- a/build-vbox +++ b/build-vbox @@ -50,8 +50,24 @@ do --size 40000 \ --format VMDK \ || true + + ## Check if the current dir for vagrant drives is hosted on an ext4 fs. If so, ensure hostiocache is enabled to avoid corruption + [ ${HOSTIOCACHE} ] || { + vbox_hd_dir="$PWD/$VBOX/"; + HOSTIOCACHE=""; + for dir in ${vbox_hd_dir}; do + vbox_hd_dir_disk=$(df ${dir} | tail -n 1 | cut -d" " -f1); + vbox_hd_dir_fs="$(grep ${vbox_hd_dir_disk} /proc/mounts | awk '{ print $3 }')" + [ "$vbox_hd_dir_fs" = "ext4" ] && { + echo "Auto enabling HOSTIOCACHE due ext4 [${dir}]"; + HOSTIOCACHE=" --hostiocache on "; + break; + } + done + } + VBoxManage storagectl "$VBOX" \ - --name SATA \ + --name SATA ${HOSTIOCACHE} \ --add sata VBoxManage storageattach "$VBOX" \ --storagectl SATA \ diff --git a/config.sh b/config.sh index dc73a30..cf4d406 100644 --- a/config.sh +++ b/config.sh @@ -36,3 +36,9 @@ # Fully-qualified pathname of VBoxGuestAdditions.iso. #: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} : ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} + +# Enable Host IO cache on ext4 filesystems. Unless explicitly specified here, build-vbox will check both current build dir and home dir (home of vagrant box cache) to see if they are ext4 filesystems +# Enable hostiocache var +#: ${HOSTIOCACHE:=" --hostiocache on"} +# Disable hostiocache var +#: ${HOSTIOCACHE:=""} \ No newline at end of file From f3ecd319ec8ea0509fff6b2fd9364ec179033040 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 20:31:35 +0000 Subject: [PATCH 15/22] Upgrade vagrant to 0.7.1 for VirtualBox 4.0.2 support --- Gemfile.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c031d7d..06cb2f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,25 +7,25 @@ GEM abstract (>= 1.0.0) ffi (0.6.3) rake (>= 0.8.7) - i18n (0.4.2) + i18n (0.5.0) json (1.4.6) mario (0.0.6) net-scp (1.0.4) net-ssh (>= 1.99.1) - net-ssh (2.0.23) + net-ssh (2.1.0) rake (0.8.7) thor (0.14.6) - vagrant (0.6.8) + vagrant (0.7.1) archive-tar-minitar (= 0.5.2) erubis (~> 2.6.6) - i18n (~> 0.4.1) + i18n (~> 0.5.0) json (~> 1.4.6) mario (~> 0.0.6) - net-scp (~> 1.0.3) - net-ssh (~> 2.0.23) - thor (~> 0.14.2) - virtualbox (~> 0.7.6) - virtualbox (0.7.6) + net-scp (~> 1.0.4) + net-ssh (~> 2.1.0) + thor (~> 0.14.6) + virtualbox (~> 0.8.3) + virtualbox (0.8.3) ffi (~> 0.6.3) PLATFORMS From 0a0e0fdbd64f9ae8235b5b30ca65bd3dc339f14b Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 21:17:55 +0000 Subject: [PATCH 16/22] Update memory requirement and VBoxManage commands to support VirtualBox 4 --- build-vbox | 22 ++++++++++++++-------- clean-vbox | 16 ++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/build-vbox b/build-vbox index cb5457b..2235a4a 100755 --- a/build-vbox +++ b/build-vbox @@ -17,7 +17,7 @@ do || true VBoxManage modifyvm "$VBOX" \ --ostype "Ubuntu$([ "$ARCH" = "i386" ] || echo _64)" \ - --memory 360 \ + --memory 448 \ --vram 12 \ --acpi on --ioapic on \ --cpus 1 \ @@ -31,11 +31,12 @@ do --audio none \ --clipboard disabled \ --usb off --usbehci off \ - --vrdp off \ + --vrde off \ --teleporter off # Mount the custom installation ISO. - VBoxManage openmedium dvd "$PWD/$ISO" || true +# VBoxManage openmedium dvd "$PWD/$ISO" || true + VBoxManage storagectl "$VBOX" \ --name IDE \ --add ide @@ -93,15 +94,20 @@ do --type dvddrive --medium "$VBOX_GUEST_ADDITIONS" eval "$SSH \" set -e + export DEBCONF_FRONTEND=noninteractive sudo apt-get -y install linux-headers-\\\$(uname -r) build-essential until sudo mount /dev/cdrom /media/cdrom do sleep 1 done - sudo /media/cdrom/VBoxLinuxAdditions-$([ "$ARCH" = "i386" ] \ - && echo x86 \ - || echo amd64 - ).run + [[ -e /media/cdrom/VBoxLinuxAdditions.run ]] && { + sudo /media/cdrom/VBoxLinuxAdditions.run + } || { + sudo /media/cdrom/VBoxLinuxAdditions-$([ "$ARCH" = "i386" ] \ + && echo x86 \ + || echo amd64 + ).run + } sudo umount /media/cdrom \"" VBoxManage storageattach "$VBOX" \ @@ -115,5 +121,5 @@ do do sleep 1 done - VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_base_build #000001" --description "Snapshot taken after initial build to be able to restore back when recreating vagrant boxes" + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_base_build__000001" --description "Snapshot taken after initial build to be able to restore back when recreating vagrant boxes" done diff --git a/clean-vbox b/clean-vbox index 5024d21..e33b364 100755 --- a/clean-vbox +++ b/clean-vbox @@ -9,14 +9,14 @@ do ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" - VBoxManage controlvm "$VBOX" poweroff - VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_base #000002" - VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_base_build #000001" - VBoxManage storagectl "$VBOX" --name IDE --remove - VBoxManage storagectl "$VBOX" --name SATA --remove - VBoxManage unregistervm "$VBOX" - VBoxManage closemedium dvd "$PWD/$ISO" - VBoxManage closemedium disk "$PWD/$VBOX/$VBOX.vmdk" + [ $(VBoxManage list runningvms | grep -c "${VBOX}") -gt 0 ] && VBoxManage controlvm "$VBOX" poweroff +# VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_base #000002" +# VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_base_build #000001" +# VBoxManage storagectl "$VBOX" --name IDE --remove +# VBoxManage storagectl "$VBOX" --name SATA --remove + VBoxManage unregistervm "$VBOX" --delete +# VBoxManage closemedium dvd "$PWD/$ISO" +# VBoxManage closemedium disk "$PWD/$VBOX/$VBOX.vmdk" rm -rf "$VBOX" done From 6b93946254340a7b8887d105fe2e6929559fcfeb Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 21:20:24 +0000 Subject: [PATCH 17/22] Change snapshot names. The '#' may not be entirely safe and can't be guaranteed to be safe in the future --- build-vagrant | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-vagrant b/build-vagrant index b00e3dc..0e6e43c 100755 --- a/build-vagrant +++ b/build-vagrant @@ -9,7 +9,7 @@ do VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" # Reset to snapshot at time of initial build - VBoxManage snapshot "${VBOX}" restore "AUTO_${LABEL}_base_build #000001" + VBoxManage snapshot "${VBOX}" restore "AUTO_${LABEL}_base_build__000001" # Start the virtual machine. Spin slowly until SSH is usable. VBoxManage startvm "$VBOX" --type gui @@ -60,7 +60,7 @@ do "${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box" # Snapshot after vagrant dep install.... - VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_vagrant_base #000002" --description "Snapshot taken after installing vagrant dependencies" + VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_vagrant_base__000002" --description "Snapshot taken after installing vagrant dependencies" done # Creating Vagrant boxes ruins the normal VM setup so get rid of them. From 16ecbdd628887efd4174b77d65fe2a7d06010a1c Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 21:24:38 +0000 Subject: [PATCH 18/22] Add support for nfs. nfs_compat var is filled with the name of nfs-common package by default. Empty string should be used to prevent the package from being installed. This allows you to keep the base box smaller if nfs is not required --- build-iso | 1 + config.sh | 3 +++ default.seed.m4 | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build-iso b/build-iso index b2d8c48..4da2a81 100755 --- a/build-iso +++ b/build-iso @@ -40,6 +40,7 @@ do -D __USER_NAME__="$USER_NAME" \ -D __PASSWORD__="$PASSWORD" \ -D __LABEL__="${LABEL}" \ + -D __NFS_COMPAT__="${NFS_COMPAT}" \ "default.seed.m4" >"$COPY/preseed/${LABEL}.seed" # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" diff --git a/config.sh b/config.sh index cf4d406..0e000ba 100644 --- a/config.sh +++ b/config.sh @@ -37,6 +37,9 @@ #: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} : ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} +# Add nfs_common packages to vbox for nfs compat with vagrant. Empty string to remove nfs compat. This should make the base image (a bit) smaller, if you don't need nfs support +: ${NFS_COMPAT:="nfs-common"} + # Enable Host IO cache on ext4 filesystems. Unless explicitly specified here, build-vbox will check both current build dir and home dir (home of vagrant box cache) to see if they are ext4 filesystems # Enable hostiocache var #: ${HOSTIOCACHE:=" --hostiocache on"} diff --git a/default.seed.m4 b/default.seed.m4 index b07678e..3c875d8 100644 --- a/default.seed.m4 +++ b/default.seed.m4 @@ -41,7 +41,7 @@ d-i mirror/http/proxy string # d-i apt-setup/local0/source boolean false # d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg tasksel tasksel/first multiselect -d-i pkgsel/include string curl openssh-server +d-i pkgsel/include string curl openssh-server acpi-support __NFS_COMPAT__ #d-i pkgsel/include string openssh-server sandbox blueprint d-i pkgsel/update-policy select none d-i pkgsel/install-language-support boolean false From 43ee28489f62d7e96b5ee9ae632171f24000310d Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 21:31:41 +0000 Subject: [PATCH 19/22] Add support for apt proxy (apt-cacher-ng tested). This is disabled by default, but configured to use the host machines IP address ( in nat mode ) for the proxy address. You can configure this as needed. As it is configured for use during the OS installation the proxy settings are used for APT even after install. This means you should either disable the proxy config for the box before packaging or ensure the vagrant host is running a proxy. --- build-iso | 1 + config.sh | 2 ++ default.seed.m4 | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build-iso b/build-iso index 4da2a81..e694e15 100755 --- a/build-iso +++ b/build-iso @@ -41,6 +41,7 @@ do -D __PASSWORD__="$PASSWORD" \ -D __LABEL__="${LABEL}" \ -D __NFS_COMPAT__="${NFS_COMPAT}" \ + -D __PROXY_URL__="${PROXY_URL}" \ "default.seed.m4" >"$COPY/preseed/${LABEL}.seed" # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" diff --git a/config.sh b/config.sh index 0e000ba..ce40cfd 100644 --- a/config.sh +++ b/config.sh @@ -37,6 +37,8 @@ #: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} : ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} +# apt-cacher-ng support. If you have a proxy running locally set the ip address here for apt to proxy requests. (10.0.2.2 is the default gateway ip which should be your host) +#: ${PROXY_URL:="http://10.0.2.2:3142"} # Add nfs_common packages to vbox for nfs compat with vagrant. Empty string to remove nfs compat. This should make the base image (a bit) smaller, if you don't need nfs support : ${NFS_COMPAT:="nfs-common"} diff --git a/default.seed.m4 b/default.seed.m4 index 3c875d8..cdae2c9 100644 --- a/default.seed.m4 +++ b/default.seed.m4 @@ -36,10 +36,12 @@ d-i user-setup/allow-password-weak boolean true d-i user-setup/encrypt-home boolean false # Packages and repositories. -d-i mirror/http/proxy string # d-i apt-setup/local0/repository string http://packages.devstructure.com maverick main # d-i apt-setup/local0/source boolean false # d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i mirror/protocol string http +# d-i mirror/http/hostname string +d-i mirror/http/proxy string __PROXY_URL__ tasksel tasksel/first multiselect d-i pkgsel/include string curl openssh-server acpi-support __NFS_COMPAT__ #d-i pkgsel/include string openssh-server sandbox blueprint From 254f54d0f31186d7b302a1d44c443a6197588ce9 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 21:40:31 +0000 Subject: [PATCH 20/22] Minor tweaks Try and remove debconf errors for tty-required and make dev process a little smoother --- build-vagrant | 3 ++- build-vbox | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build-vagrant b/build-vagrant index 0e6e43c..94c11ab 100755 --- a/build-vagrant +++ b/build-vagrant @@ -22,7 +22,8 @@ do # Install Ruby, RubyGems, and Chef as Vagrant requires. eval "$SSH \" set -e - sudo apt-get -y install build-essential ruby ruby-dev rubygems + export DEBCONF_FRONTEND=noninteractive + sudo -E apt-get -y install build-essential ruby ruby-dev rubygems sudo gem install --no-rdoc --no-ri chef echo 'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/gems/1.8/bin\"' | sudo tee /etc/environment >/dev/null \"" diff --git a/build-vbox b/build-vbox index 2235a4a..a16e641 100755 --- a/build-vbox +++ b/build-vbox @@ -6,9 +6,15 @@ set -e for ARCH in $ARCHS do - ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" - VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + # Check if the vm already exists + set +e + VM_EXISTS=$(VBoxManage list vms | grep -c "${VBOX}") + set -e + + if [ ${VM_EXISTS} -lt 1 ]; then # Create and configure a virtual machine through VirtualBox. VBoxManage createvm \ --name "$VBOX" \ @@ -84,7 +90,7 @@ do do sleep 60 done - + fi # Attach the VBoxGuestAdditions ISO, implicitly detaching the custom # installation ISO in the process. Install the additions and empty # the drive. @@ -95,7 +101,7 @@ do eval "$SSH \" set -e export DEBCONF_FRONTEND=noninteractive - sudo apt-get -y install linux-headers-\\\$(uname -r) build-essential + sudo -E apt-get -y install linux-headers-\\\$(uname -r) build-essential until sudo mount /dev/cdrom /media/cdrom do sleep 1 From c406c809ea6085d9a9837694fab50d1130ed28f8 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Mon, 31 Jan 2011 22:14:51 +0000 Subject: [PATCH 21/22] Remove the apt proxy setting before packaging the box. By default, remove the proxy settings before packaging the box. If you are packaging for your team which has an apt proxy enabled on their host machines, and have enabled the proxy setting for the initial os install, you may want to disable this option. --- build-vagrant | 7 +++++++ config.sh | 3 +++ 2 files changed, 10 insertions(+) diff --git a/build-vagrant b/build-vagrant index 94c11ab..de3106c 100755 --- a/build-vagrant +++ b/build-vagrant @@ -55,6 +55,13 @@ do done } + # Remove the Proxy configuration before packaging a box. Not all vagrant users will be running an apt proxy server on their machines. + [ ${BOX_DISABLE_APT_PROXY} -eq 1 ] && { + eval "$SSH \" + sudo sed -i '/^Acquire::http::Proxy/ d' /etc/apt/apt.conf + \"" + } + # Now build the Vagrant box file. vagrant package --base "$VBOX" mv "package.box" \ diff --git a/config.sh b/config.sh index ce40cfd..4c71b07 100644 --- a/config.sh +++ b/config.sh @@ -39,6 +39,9 @@ # apt-cacher-ng support. If you have a proxy running locally set the ip address here for apt to proxy requests. (10.0.2.2 is the default gateway ip which should be your host) #: ${PROXY_URL:="http://10.0.2.2:3142"} +# remove apt-proxy config for boxification? To remove the apt config for proxy settings from the box itself +# (i.e. only use it for the OS install not for subsequent vagrant vms afterwards. Do your colleagues run apt-proxy on their host machines?) +: ${BOX_DISABLE_APT_PROXY:=1} # Add nfs_common packages to vbox for nfs compat with vagrant. Empty string to remove nfs compat. This should make the base image (a bit) smaller, if you don't need nfs support : ${NFS_COMPAT:="nfs-common"} From d3a93ac283c095b5b9119a7f31934defaae50064 Mon Sep 17 00:00:00 2001 From: Pritesh Date: Tue, 1 Mar 2011 22:23:06 +0000 Subject: [PATCH 22/22] Add a script to build vbox and vagrant boxes from pxe and netboot files. [Disabled by default] You NEED a webserver... atleast until the debian-installer/preseed tools allow you to get the seed file via tftp (And thereby allow us to use the built in tftp server in VirtualBox) TODO: Write up README for this process and attach example webserver config. --- build-pxe | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ build-vbox | 71 ++++++++++++++++++++++++++++++++++++------- clean-pxe | 23 ++++++++++++++ clean-vbox | 26 +++++++++------- config.sh | 27 +++++++++++++---- perm_setup.sh.m4 | 26 ++++++++++++++++ pxe.seed.m4 | 74 +++++++++++++++++++++++++++++++++++++++++++++ pxelinux.cfg.m4 | 6 ++++ 8 files changed, 304 insertions(+), 27 deletions(-) create mode 100755 build-pxe create mode 100755 clean-pxe create mode 100644 perm_setup.sh.m4 create mode 100644 pxe.seed.m4 create mode 100644 pxelinux.cfg.m4 diff --git a/build-pxe b/build-pxe new file mode 100755 index 0000000..1a56cb9 --- /dev/null +++ b/build-pxe @@ -0,0 +1,78 @@ +#!/bin/sh + +# PXE BOOT [WVVVVMIP] (Work Very Very Very Very Much in Progress!) +# New script to take the iso image and use it and the parameters defined in the config.sh to setup and use pxe boot for setting up vagrant boxes +# + +set -e + +. "$(dirname $0)/config.sh" + +[ ${VBOX_PXE_BUILD} -eq 1 ] || { + echo "PXE Building is DISABLED. Please enable in config.sh" + exit 2 +} + +for ARCH in $ARCHS +do + ORIG="ubuntu-$VERSION-$DISTRO-$ARCH.iso" + COPY="ubuntu-$VERSION-$DISTRO-$ARCH" + ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" + VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + NETBOOT="ubuntu-$VERSION_NAME-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + +# echo $NETBOOT_URI + # Download the original netboot files if it isn't present already. +# echo "${NETBOOT_DIR}" + [ -f "$NETBOOT_FILE" ] || { + curl -L -o "${NETBOOT_FILE}" "${NETBOOT_URI}" + } + [ -d ${NETBOOT_DIR} ] || mkdir -p ${NETBOOT_DIR} + [ -d ${PRESEED_PATH} ] || mkdir -p ${PRESEED_PATH} + + (cd ${NETBOOT_DIR} && tar xzf ${CURR_DIR}/${NETBOOT}.tar.gz) + # Make a e copy of the original ISO. This uses the `hdiutil` + # command that is specific to Mac OS X. + + # Customize the writable copy. + mv "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg" "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg_ORIG" + m4 \ + -D __LABEL__="${LABEL}" \ + -D __ARCH__="$ARCH" \ + -D __HOST__="$HOST" \ + -D __PRESEED_URI__="${PRESEED_HOST}/${LABEL}.seed" \ + "pxelinux.cfg.m4" > "${NETBOOT_DIR}/ubuntu-installer/${ARCH}/boot-screens/syslinux.cfg" + ln -nfs ${NETBOOT_DIR}/pxelinux.0 ${NETBOOT_DIR}/${VBOX}.pxe + m4 \ + -D __HOST__="$HOST" \ + -D __DOMAIN__="$DOMAIN" \ + -D __KERNEL__="linux-$([ "$ARCH" = "i386" ] \ + && echo generic-pae \ + || echo server + )" \ + -D __ROOT_PASSWORD__="$ROOT_PASSWORD" \ + -D __USER_NAME__="$USER_NAME" \ + -D __PASSWORD__="$PASSWORD" \ + -D __LABEL__="${LABEL}" \ + -D __NFS_COMPAT__="${NFS_COMPAT}" \ + -D __VERSION_NAME__="${VERSION_NAME}" \ + -D __PROXY_URL__="${PROXY_URL}" \ + -D __LOCALE__="en_US" \ + -D __PRESEED_HOST__="${PRESEED_HOST}" \ + "pxe.seed.m4" >"${PRESEED_PATH}/${LABEL}.seed" + + # cp "$PUBLIC_KEY" "setup.sh" "$COPY/" + cp "$PUBLIC_KEY" "sudoers" "${NETBOOT_DIR}/" + tar -czf ${PRESEED_PATH}/setup.tgz "${PUBLIC_KEY}" "sudoers" + m4 \ + -D __LABEL__="$LABEL" \ + -D __PRESEED_HOST__="$PRESEED_HOST" \ + -D __USER_NAME__="$USER_NAME" \ + -D __PUBLIC_KEY__="$PUBLIC_KEY" \ + "perm_setup.sh.m4" >"${PRESEED_PATH}/${LABEL}.sh" + echo "** Completed building custom pxe for ${LABEL} [${ARCH}]" +done diff --git a/build-vbox b/build-vbox index a16e641..6f3f8da 100755 --- a/build-vbox +++ b/build-vbox @@ -8,6 +8,14 @@ for ARCH in $ARCHS do ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" + NETBOOT="ubuntu-$VERSION-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + + ## Set TFTP Folder based on ARCH + ln -nfs ${NETBOOT_DIR} ${VBOX_CONF_HOME}/TFTP # Check if the vm already exists set +e @@ -15,6 +23,9 @@ do set -e if [ ${VM_EXISTS} -lt 1 ]; then + + [ ${VBOX_PXE_BUILD} -eq 1 ] && { pxe_boot_order="--boot1 disk --boot2 net"; } || pxe_boot_order="" + # Create and configure a virtual machine through VirtualBox. VBoxManage createvm \ --name "$VBOX" \ @@ -38,18 +49,12 @@ do --clipboard disabled \ --usb off --usbehci off \ --vrde off \ + ${pxe_boot_order} \ --teleporter off - # Mount the custom installation ISO. -# VBoxManage openmedium dvd "$PWD/$ISO" || true - VBoxManage storagectl "$VBOX" \ --name IDE \ --add ide - VBoxManage storageattach "$VBOX" \ - --storagectl IDE \ - --port 1 --device 0 \ - --type dvddrive --medium "$PWD/$ISO" # Mount a virtual hard disk. VBoxManage createhd \ @@ -83,9 +88,43 @@ do # Start the virtual machine and the OS installation. This will take # a while so this time it gets a GUI. Spin slowly until SSH is usable. + fi + + if [ ${VBOX_PXE_BUILD} -lt 1 ]; then + # Mount the custom installation ISO. + # VBoxManage openmedium dvd "$PWD/$ISO" || true + + VBoxManage storageattach "$VBOX" \ + --storagectl IDE \ + --port 1 --device 0 \ + --type dvddrive --medium "$PWD/$ISO" + else + VBoxManage storageattach "$VBOX" \ + --storagectl IDE \ + --port 1 --device 0 \ + --type dvddrive --medium "$VBOX_GUEST_ADDITIONS" + + fi + + set +e + VM_RUNS=$(VBoxManage list runningvms | grep -c "${VBOX}") + set -e + + if [ ${VM_RUNS} -lt 1 ]; then + + ## Start a webserver for the preseed files. + [ ${VBOX_PXE_BUILD} -eq 1 -a ${PRESEED_WEBSERVER} -eq 1 ] && { + echo -n "Starting webserver for preseed files..." + cd $PRESEED_PATH && python -m SimpleHTTPServer & + webserver_PID=$! + echo "done" + } + VBoxManage startvm "$VBOX" --type gui ## Set better perms on the private key to avoid ssh abort chmod 600 ${PRIVATE_KEY} +# VBoxManage modifyvm "${VBOX}" \ +# --boot1 disk until eval "$SSH exit" do sleep 60 @@ -94,25 +133,30 @@ do # Attach the VBoxGuestAdditions ISO, implicitly detaching the custom # installation ISO in the process. Install the additions and empty # the drive. - VBoxManage storageattach "$VBOX" \ + if [ ${VBOX_PXE_BUILD} -lt 1 ]; then + VBoxManage storageattach "$VBOX" \ --storagectl IDE \ --port 1 --device 0 \ --type dvddrive --medium "$VBOX_GUEST_ADDITIONS" + fi + eval "$SSH \" set -e + [ $(lsmod | grep -c vboxguest) -eq 1 ] && exit 0; export DEBCONF_FRONTEND=noninteractive sudo -E apt-get -y install linux-headers-\\\$(uname -r) build-essential + [ -d /media/cdrom ] || sudo mkdir -p /media/cdrom until sudo mount /dev/cdrom /media/cdrom do sleep 1 done [[ -e /media/cdrom/VBoxLinuxAdditions.run ]] && { - sudo /media/cdrom/VBoxLinuxAdditions.run + sudo /media/cdrom/VBoxLinuxAdditions.run force } || { sudo /media/cdrom/VBoxLinuxAdditions-$([ "$ARCH" = "i386" ] \ && echo x86 \ || echo amd64 - ).run + ).run force --nox11 } sudo umount /media/cdrom \"" @@ -120,7 +164,12 @@ do --storagectl IDE \ --port 1 --device 0 \ --type dvddrive --medium emptydrive - + + [ ${VBOX_PXE_BUILD} -eq 1 -a ${PRESEED_WEBSERVER} -eq 1 ] && { + echo -n "Stopping webserver for preseed files..." + kill ${webserver_PID} + wait && echo "done" + } # Shutdown the virtual machine. eval "$SSH \"sudo shutdown -h now\"" until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off" diff --git a/clean-pxe b/clean-pxe new file mode 100755 index 0000000..d06b9fa --- /dev/null +++ b/clean-pxe @@ -0,0 +1,23 @@ +#!/bin/sh + +# set -e # Try our best to finish here. + +. "$(dirname $0)/config.sh" + +for ARCH in $ARCHS +do + NETBOOT="ubuntu-$VERSION_NAME-$ARCH-netboot" + NETBOOT_FILE="${NETBOOT}.tar.gz" + NETBOOT_DIR="${VBOX_CONF_HOME}/ubuntu-$VERSION_NAME-netboot" + NETBOOT_URI="http://archive.ubuntu.com/ubuntu/dists/$VERSION_NAME/main/installer-$ARCH/current/images/netboot/netboot.tar.gz" + CURR_DIR=$(pwd) + + # Remove extracted netboot files + custom configs + rm -rf "${NETBOOT_DIR}" + # Remove the preseed file. + rm -f "${PRESEED_PATH}/${LABEL}.seed" + # Remove the initial user setup script. + rm -f "${PRESEED_PATH}/${LABEL}.sh" + + echo "** Cleaned custom pxe for ${LABEL} [${ARCH}]" +done diff --git a/clean-vbox b/clean-vbox index e33b364..e5abde1 100755 --- a/clean-vbox +++ b/clean-vbox @@ -8,15 +8,21 @@ for ARCH in $ARCHS do ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso" VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH" - - [ $(VBoxManage list runningvms | grep -c "${VBOX}") -gt 0 ] && VBoxManage controlvm "$VBOX" poweroff -# VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_vagrant_base #000002" -# VBoxManage snapshot "${VBOX}" delete "AUTO_${LABEL}_base_build #000001" -# VBoxManage storagectl "$VBOX" --name IDE --remove -# VBoxManage storagectl "$VBOX" --name SATA --remove - VBoxManage unregistervm "$VBOX" --delete -# VBoxManage closemedium dvd "$PWD/$ISO" -# VBoxManage closemedium disk "$PWD/$VBOX/$VBOX.vmdk" + VMLIST=$(VBoxManage list vms) + RUNNING_VMLIST=$(VBoxManage list runningvms) + + ## Power off running vms + [ $(echo "${RUNNING_VMLIST}" | grep -c "${VBOX}") -gt 0 ] && { + echo -n "VBox ${VBOX} is running... Powering off" + VBoxManage controlvm "$VBOX" poweroff + sleep 1 # Lets give the vm to shutdown properly. + [ $? -eq 0 ] && { echo "... done"; } || { echo "... Failed!"; } + } + ## Remove vms if they exist + [ $(echo "${VMLIST}" | grep -c "${VBOX}") -gt 0 ] && { + echo -n "Removing VBox [${VBOX}]..." + VBoxManage unregistervm "$VBOX" --delete + [ $? -eq 0 ] && { echo "... done"; } || { echo "... Failed!"; } + } rm -rf "$VBOX" - done diff --git a/config.sh b/config.sh index 4c71b07..60ee5ac 100644 --- a/config.sh +++ b/config.sh @@ -1,21 +1,22 @@ # # Arguments given to the download router. -: ${VERSION:="10.10"} : ${DISTRO:="server"} +: ${VERSION:="11.04"} +: ${VERSION_NAME:="natty"} : ${RELEASE:="latest"} # Generated ISO Prefix -: ${ISOPREFIX:="vagrant"} -: ${LABEL:="vagrant"} - +: ${ISOPREFIX:="phatforge"} +: ${LABEL:="phatforge"} # Architectures being built. : ${ARCHS:="i386 amd64"} +#: ${ARCHS:="amd64"} # Hardcoded host information. # : ${HOST:="devstructure"} -: ${HOST:="maverick"} +: ${HOST:="${VERSION_NAME}"} : ${DOMAIN:="vagrantup.com"} : ${ROOT_PASSWORD:="vagrant"} : ${USER_NAME:="vagrant"} @@ -37,6 +38,20 @@ #: ${VBOX_GUEST_ADDITIONS:="/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"} : ${VBOX_GUEST_ADDITIONS:="/usr/share/virtualbox/VBoxGuestAdditions.iso"} +#### PXE BUILD SETTINGS +## You need a webserver to serve the preseed file. We currently use python's simpleHTTPServer module, but you can change the path to a full webserver if you want. +## A proxy is recommended! +### +## Enable build via pxe +: ${VBOX_PXE_BUILD:=0} +## VirtualBox config home (Location of the VirtualBox.xml file), for pxe boot support +: ${VBOX_CONF_HOME:="${HOME}/.VirtualBox"} +# Enable a python webserver for the preseed files.(Default on. Disable if you are hosting your preseed files on your own webserver +: ${PRESEED_WEBSERVER:=1} +## Preseed URI address. Default is set to the Host machine ip. This address can be set to a remote url (assuming your VM can access it.) Please see README.PXE +: ${PRESEED_HOST:="http://10.0.2.2:8000"} +: ${PRESEED_PATH:="web-root"} + # apt-cacher-ng support. If you have a proxy running locally set the ip address here for apt to proxy requests. (10.0.2.2 is the default gateway ip which should be your host) #: ${PROXY_URL:="http://10.0.2.2:3142"} # remove apt-proxy config for boxification? To remove the apt config for proxy settings from the box itself @@ -49,4 +64,4 @@ # Enable hostiocache var #: ${HOSTIOCACHE:=" --hostiocache on"} # Disable hostiocache var -#: ${HOSTIOCACHE:=""} \ No newline at end of file +#: ${HOSTIOCACHE:=""} diff --git a/perm_setup.sh.m4 b/perm_setup.sh.m4 new file mode 100644 index 0000000..5248097 --- /dev/null +++ b/perm_setup.sh.m4 @@ -0,0 +1,26 @@ +set -e + +mkdir -p /opt/__LABEL__-setup/ +cd /opt/__LABEL__-setup/ +curl -L --noproxy * -o "/opt/__LABEL__-setup/setup.tgz" "__PRESEED_HOST__/setup.tgz" +tar xzvf /opt/__LABEL__-setup/setup.tgz + +mkdir /home/__USER_NAME__/.ssh +cat /opt/__LABEL__-setup/__PUBLIC_KEY__ >/home/__USER_NAME__/.ssh/authorized_keys +chmod 700 /home/__USER_NAME__/.ssh +chown 1000:1000 \ + /home/__USER_NAME__/.ssh \ + /home/__USER_NAME__/.ssh/authorized_keys + +# cp /cdrom/setup.sh /etc/profile.d/ +# chmod 644 /etc/profile.d/setup.sh +# chown 0:0 /etc/profile.d/setup.sh + +cp /opt/__LABEL__-setup/sudoers /etc/ +chmod 440 /etc/sudoers +chown 0:0 /etc/sudoers + +unset DEBCONF_REDIR DEBCONF_FRONTEND DEBIAN_HAS_FRONTEND DEBIAN_FRONTEND +apt-get update + +rm -rf /opt/__LABEL__-setup/ diff --git a/pxe.seed.m4 b/pxe.seed.m4 new file mode 100644 index 0000000..cbfd96d --- /dev/null +++ b/pxe.seed.m4 @@ -0,0 +1,74 @@ +# Preseed Ubuntu for vagrant. + +## Add pxe required settings. These shouldn't interfere with iso build versions. +d-i debian-installer/locale string __LOCALE__ +d-i netcfg/choose_interface select auto +# Keyboard selection. +# Disable automatic (interactive) keymap detection. +d-i console-setup/ask_detect boolean false +#d-i console-setup/modelcode string pc105 +d-i console-setup/layoutcode string us +# To select a variant of the selected layout (if you leave this out, the +# basic form of the layout will be used): +#d-i console-setup/variantcode string dvorak + +# Network. +d-i netcfg/get_hostname string __HOST__ +d-i netcfg/get_domain string __DOMAIN__ +d-i netcfg/wireless_wep string + +# Clock. +d-i clock-setup/utc boolean true +d-i time/zone string UTC + +# Partitions. +d-i partman-auto/disk string /dev/sda +d-i partman-auto/method string regular +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md boolean true +d-i partman-auto/choose_recipe select atomic +d-i partman/default_filesystem string ext4 +d-i partman/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +# Kernel. +d-i base-installer/kernel/override-image string __KERNEL__ + +# Users. +d-i passwd/root-password password __ROOT_PASSWORD__ +d-i passwd/root-password-again password __ROOT_PASSWORD__ +d-i passwd/user-uid string 1000 +d-i passwd/user-fullname string VagrantUser +d-i passwd/username string __USER_NAME__ +d-i passwd/user-password password __PASSWORD__ +d-i passwd/user-password-again password __PASSWORD__ +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false + +# Packages and repositories. +# d-i apt-setup/local0/repository string http://packages.devstructure.com __VERSION_NAME__ main +# d-i apt-setup/local0/source boolean false +# d-i apt-setup/local0/key string http://packages.devstructure.com/keyring.gpg +# d-i mirror/protocol string http +# d-i mirror/http/hostname string +d-i mirror/http/proxy string __PROXY_URL__ +tasksel tasksel/first multiselect +d-i pkgsel/include string curl openssh-server acpi-support __NFS_COMPAT__ +#d-i pkgsel/include string openssh-server sandbox blueprint +d-i pkgsel/update-policy select none +d-i pkgsel/install-language-support boolean false + +# Grub and reboot. +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note +d-i cdrom-detect/eject boolean true +d-i debian-installer/splash boolean false + +# Everything else. +d-i preseed/late_command string \ + in-target wget --no-proxy __PRESEED_HOST__/__LABEL__.sh -O /opt/__LABEL__.sh ; \ + in-target sh /opt/__LABEL__.sh ; + diff --git a/pxelinux.cfg.m4 b/pxelinux.cfg.m4 new file mode 100644 index 0000000..e64527d --- /dev/null +++ b/pxelinux.cfg.m4 @@ -0,0 +1,6 @@ +default __LABEL__ +timeout 1 +label __LABEL__ + menu label ^Install Ubuntu Server for __LABEL__ + kernel ubuntu-installer/__ARCH__/linux + append auto=true priority=critical url=__PRESEED_URI__ hostname=__HOST__ initrd=ubuntu-installer/__ARCH__/initrd.gz quiet --