diff --git a/build.ubuntu.vmimg/.gitignore b/build.ubuntu.vmimg/.gitignore new file mode 100644 index 0000000..5a15171 --- /dev/null +++ b/build.ubuntu.vmimg/.gitignore @@ -0,0 +1,3 @@ +.vagrant +*.bz2 +*.qcow2 diff --git a/build.ubuntu.vmimg/Makefile b/build.ubuntu.vmimg/Makefile index c8b803e..3b59fab 100644 --- a/build.ubuntu.vmimg/Makefile +++ b/build.ubuntu.vmimg/Makefile @@ -1,8 +1,18 @@ +YYYYMMDD := $(shell date +%Y%m%d) + default: gen -gen: +clean: + rm -f *.bz2 *.qcow2 + +gen: clean vagrant destroy -f vagrant up + vagrant ssh -- cat saucy64.qcow2 | pv > .tmp.qcow2 + mv .tmp.qcow2 saucy64-$(YYYYMMDD).qcow2 + rsync -azvP saucy64-$(YYYYMMDD).qcow2 \ + root@nue1d0.datavibe.net:/storage/images/ sync: - rsync -avP ./make.sh root@nue1d0.datavibe.net:/storage/buildimage/make.sh + rsync -avP ./*.sh \ + root@nue1d0.datavibe.net:/storage/buildimage/ diff --git a/build.ubuntu.vmimg/buildimage.sh b/build.ubuntu.vmimg/buildimage.sh index 4f67149..a3ae675 100755 --- a/build.ubuntu.vmimg/buildimage.sh +++ b/build.ubuntu.vmimg/buildimage.sh @@ -1,10 +1,14 @@ #!/bin/bash +set -e +set -v +set -x + R="saucy" # release MR="./roottemp" # mounted root RI="./raw.img" # raw image VGN="vmvg0" # volume group name -DSIZE="8G" # disk size +DSIZE="25G" # disk size DATE="$(date +%Y%m%d)" LOOPDEV="/dev/loop5" @@ -20,7 +24,15 @@ function detect_local_mirror () { UM="http://${NAME}:${PORT}/ubuntu/" fi if [ -z "$UM" ]; then - echo "http://archive.ubuntu.com/ubuntu/" + # maybe try hetzner mirror? + UM="http://mirror.hetzner.de/ubuntu/packages/" + TF="${UM}/dists/${R}/Release" + MOK="$(curl --head ${TF} 2>&1 | grep '200 OK' | wc -l)" + if [ $MOK -gt 0 ]; then + echo "$UM" + else + echo "http://archive.ubuntu.com/ubuntu/" + fi else echo "$UM" fi @@ -28,7 +40,6 @@ function detect_local_mirror () { UM="$(detect_local_mirror)" -set -e dd if=/dev/zero of=$RI bs=1 count=0 seek=$DSIZE parted -s $RI mklabel msdos parted -a optimal $RI mkpart primary 0% 200MiB @@ -43,10 +54,12 @@ vgcreate $VGN /dev/mapper/${LDBASE}p2 lvcreate -l 100%FREE -n root $VGN mkfs.ext4 -L ROOT /dev/$VGN/root mkdir -p $MR +MR="$(readlink -f $MR)" mount /dev/$VGN/root $MR mkdir $MR/boot mount /dev/mapper/${LDBASE}p1 $MR/boot +echo "*** installing base $R system from $UM..." # install base: debootstrap --arch amd64 $R $MR $UM @@ -57,6 +70,11 @@ for P in updates backports security ; do echo "deb $UM $R-$P $RPS" >> $MR/etc/apt/sources.list done +cat > $MR/etc/apt/apt.conf.d/99-vm-no-extras-please < $MR/etc/environment < $MR/etc/fstab < $MR/etc/network/interfaces < $MR/etc/hostname +echo "localhost" > $MR/etc/hostname cat > $MR/etc/hosts < $MR/usr/sbin/policy-rc.d < $MR/etc/dhcp/dhclient-exit-hooks.d/hostname <> $MR/etc/ssh/sshd_config +echo "UseDNS no" >> $MR/etc/ssh/sshd_config + # clean apt cache rm $MR/var/cache/apt/archives/*.deb @@ -181,37 +250,43 @@ done # clear issue echo "clear > /etc/issue" | chroot $MR -# run firstboot on boot if exists -echo "if test -x /firstboot.sh ; then /firstboot.sh ; fi" \ - >> $MR/etc/rc.local +# remove instance ssh host keys +rm $MR/etc/ssh/*key* -# write firstboot file -cat > $MR/firstboot.sh < $MR/etc/rc.local <