From 787fecd81c79e592228b04c85fb78f61b1b01b19 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Fri, 26 Feb 2016 23:56:38 +0100 Subject: [PATCH] Setup babelbox partitioning and cleanup --- .gitignore | 3 +- debian-babelbox.json | 86 +++++++++++++++----------- http/preseed.cfg | 106 ++++++++++++++++++++++----------- scripts/babelbox-partitions.sh | 18 ++++++ scripts/cleanup.sh | 10 ++++ scripts/minimize.sh | 29 +++++++++ scripts/setup-babelbox.sh | 14 +++++ scripts/virtualbox.sh | 33 ++++++++++ setup-babelbox.sh | 8 --- 9 files changed, 228 insertions(+), 79 deletions(-) create mode 100644 scripts/babelbox-partitions.sh create mode 100755 scripts/cleanup.sh create mode 100644 scripts/minimize.sh create mode 100644 scripts/setup-babelbox.sh create mode 100755 scripts/virtualbox.sh delete mode 100755 setup-babelbox.sh diff --git a/.gitignore b/.gitignore index 2813ce1..b15f3fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /packer_cache/ +/babelbox/ /build/ -/http/*.iso +*.iso .*.swp diff --git a/debian-babelbox.json b/debian-babelbox.json index 5f0f841..02c6e0a 100644 --- a/debian-babelbox.json +++ b/debian-babelbox.json @@ -1,37 +1,53 @@ { - "builders": [{ - "type": "virtualbox-iso", - "guest_os_type": "Debian", - "iso_url": "http://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-8.3.0-i386-netinst.iso", - "iso_checksum": "f270d1ffa0f9472464bfc0fffa7ac3ddc89abb5786eb02454f26e49f143b01d6", - "iso_checksum_type": "sha256", - "ssh_username": "demo", - "ssh_password": "babelbox", - "ssh_wait_timeout": "1800s", - "shutdown_command": "echo 'packer' | sudo -S shutdown -P now", - "disk_size": 10240, - "headless": false, - "http_directory": "http", - "boot_command": [ - "", - "install ", - "debian-installer=en_US ", - "auto ", - "locale=en_US ", - "kbd-chooser/method=us ", - "netcfg/get_hostname={{ .Name }} ", - "netcfg/get_domain=demo.local ", - "fb=false ", - "console-setup/ask_detect=false ", - "console-keymaps-at/keymap=us ", - "keyboard-configuration/xkb-keymap=us ", - "" - ], - "boot_wait": "5s", - "vm_name": "babelbox-jessie", - "vboxmanage": [ - ["modifyvm", "{{.Name}}", "--memory", "512"], - ["modifyvm", "{{.Name}}", "--cpus", "1"] - ] - }] + "description": "Debian Babelbox", + "builders": [{ + "boot_command": [ + "", + "install ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", + "debian-installer=en_US ", + "auto ", + "locale=en_US ", + "kbd-chooser/method=de ", + "netcfg/get_hostname={{ .Name }} ", + "netcfg/get_domain=demo.local ", + "fb=false ", + "debconf/frontend=noninteractive ", + "console-setup/ask_detect=false ", + "console-keymaps-at/keymap=de ", + "keyboard-configuration/xkb-keymap=de ", + "" + ], + "disk_size": 10240, + "guest_os_type": "Debian", + "hard_drive_interface": "sata", + "headless": false, + "http_directory": "http", + "iso_checksum": "f270d1ffa0f9472464bfc0fffa7ac3ddc89abb5786eb02454f26e49f143b01d6", + "iso_checksum_type": "sha256", + "iso_url": "http://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-8.3.0-i386-netinst.iso", + "shutdown_command": "sudo /sbin/halt -p", + "ssh_username": "demo", + "ssh_password": "babelbox", + "ssh_port": "22", + "ssh_wait_timeout": "1800s", + "type": "virtualbox-iso", + "vm_name": "babelbox-jessie", + "vboxmanage": [ + ["modifyvm", "{{.Name}}", "--memory", "512"], + ["modifyvm", "{{.Name}}", "--cpus", "1"] + ], + "output_directory": "babelbox" + }], + "provisioners": [{ + "type": "shell", + "execute_command": "{{ .Vars }} sudo -E /bin/sh '{{ .Path }}'", + "scripts": [ + "scripts/babelbox-partitions.sh", + "scripts/setup-babelbox.sh", + "scripts/virtualbox.sh", + "scripts/cleanup.sh", + "scripts/minimize.sh" + ] + }] } diff --git a/http/preseed.cfg b/http/preseed.cfg index 1a85a8b..5cb9556 100644 --- a/http/preseed.cfg +++ b/http/preseed.cfg @@ -1,59 +1,95 @@ +### Localization +d-i debian-installer/locale string en_US +d-i debian-installer/language string en +d-i debian-installer/country string US d-i debian-installer/locale string en_US.UTF-8 d-i localechooser/supported-locales multiselect en_US.UTF-8, de_DE.UTF-8 -d-i keyboard-configuration/xkb-keymap select us + +# Keyboard selection. +d-i console-tools/archs select at +d-i console-keymaps-at/keymap select de + +d-i keyboard-configuration/xkb-keymap select de + +### Network configuration d-i netcfg/choose_interface select auto + +### Mirror settings d-i mirror/country string manual -d-i mirror/http/hostname string http.debian.net +d-i mirror/http/hostname string httpredir.debian.org d-i mirror/http/directory string /debian d-i mirror/http/proxy string + +### Account setup d-i passwd/root-login boolean false d-i passwd/user-fullname string Babelbox Demo User d-i passwd/username string demo d-i passwd/user-password-crypted password $6$M0jXQ0qT0W$4aZR9JeivSUot1WpUv5elFOEz2lZ6D4a67NMu40OR3ocHeDQIN.bkBV/JAGINgZ9tp.yLQL7wGGhLM2ZJZ9Mp/ -d-i clock-setup/utc boolean true -d-i clock-setup/ntp boolean false -d-i time/zone string Europe/Berlin -debconf debconf/frontend string Noninteractive -d-i partman-auto/disk string /dev/sda +### Clock and time zone setup +d-i clock-setup/utc boolean true +d-i time/zone string GMT+0 +d-i clock-setup/ntp boolean false + +### Partitioning +#d-i partman-auto/disk string /dev/sda d-i partman-lvm/purge_lvm_from_device boolean true d-i partman-lvm/device_remove_lvm boolean true -d-i partman-md/device_remove_md boolean true d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true + +d-i partman-md/device_remove_md boolean true + +d-i partman-auto/disk string /dev/sda +d-i partman-auto/method string regular +d-i partman-auto/expert_recipe string \ + root :: \ + 4608 50 4608 ext4 \ + $primary{ } $bootable{ } \ + method{ format } format{ } \ + use_filesystem{ } filesystem{ ext4 } \ + mountpoint{ / } \ + . \ + 512 90 512 linux-swap \ + $primary{ } \ + method{ swap } \ + format{ } \ + . \ + 1 1000 -1 ext4 \ + $primary{ } \ + method{ keep } \ + . +d-i partman-auto/choose_recipe select root +d-i partman-basicmethods/method_only boolean false d-i partman-partitioning/confirm_write_new_label boolean true -#d-i partman-auto/method string regular -d-i partman-auto/expert_recipe string \ - root :: \ - 5000 50 5000 ext4 \ - $primary{ } \ - $bootable{ } \ - method{ format } \ - format{ } \ - use_filesystem{ } \ - filesystem{ ext4 } \ - mountpoint { / } \ - label { root } \ - . \ - 250 50 100% linux-swap \ - $primary{ } \ - method{ swap } \ - format{ } \ - . d-i partman/choose_partition select finish d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true + +### Apt setup +d-i apt-setup/non-free boolean false +d-i apt-setup/contrib boolean false d-i base-installer/install-recommends boolean false -d-i apt-setup/use_mirror boolean true d-i apt-setup/services-select multiselect security, updates d-i apt-setup/security_host string security.debian.org -d-i pkgsel/include string parted openssh-server acpid sudo -d-i pkgsel/upgrade select none -popularity-contest popularity-contest/participate boolean false + +### Package selection tasksel tasksel/first multiselect standard -grub-pc grub-pc/install_devices multiselect /dev/sda -grub-installer grub-installer/choose_bootdev select /dev/sda + +d-i pkgsel/include string parted openssh-server acpid sudo ca-certificates curl +d-i pkgsel/upgrade select safe-upgrade + +popularity-contest popularity-contest/participate boolean false + +### GRUB +d-i grub-installer/only_debian boolean true +d-i grub-installer/bootdev string default + +### Finishing up the installation +d-i finish-install/keep-consoles boolean true d-i finish-install/reboot_in_progress note -d-i preseed/early_command string sed -i \ - '/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}' \ - /usr/lib/pre-pkgsel.d/20install-hwpackages +# Setup passwordless sudo for demo +d-i preseed/late_command string \ + echo "demo ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/demo ; \ + in-target chmod 0440 /etc/sudoers.d/demo diff --git a/scripts/babelbox-partitions.sh b/scripts/babelbox-partitions.sh new file mode 100644 index 0000000..7233bdd --- /dev/null +++ b/scripts/babelbox-partitions.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +echo " +d +3 +n +e +3 + ++4G +n +p + + +w" | /sbin/fdisk /dev/sda || true +/sbin/partprobe diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100755 index 0000000..5510152 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,10 @@ +# Clean up +apt-get --yes autoremove +apt-get --yes clean + +# Removing leftover leases and persistent rules +echo "cleaning up dhcp leases" +rm /var/lib/dhcp/* + +echo "Adding a 2 sec delay to the interface up, to make the dhclient happy" +echo "pre-up sleep 2" >> /etc/network/interfaces diff --git a/scripts/minimize.sh b/scripts/minimize.sh new file mode 100644 index 0000000..65ed37c --- /dev/null +++ b/scripts/minimize.sh @@ -0,0 +1,29 @@ +#!/bin/sh -eux +#Copyright 2012-2014, Chef Software, Inc. () +#Copyright 2011-2012, Tim Dysinger () + +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + +echo "Fill with 0 the swap partition to reduce box size" +readonly swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap) +readonly swappart=$(readlink -f /dev/disk/by-uuid/"$swapuuid") +/sbin/swapoff "$swappart" +dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed" +/sbin/mkswap -U "$swapuuid" "$swappart" + +echo "Fill filesystem with 0 to reduce box size" +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY +# Block until the empty file has been removed, otherwise, Packer +# will try to kill the box while the disk is still full and that's bad +sync diff --git a/scripts/setup-babelbox.sh b/scripts/setup-babelbox.sh new file mode 100644 index 0000000..ca7cf7f --- /dev/null +++ b/scripts/setup-babelbox.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +apt-get install -y git wget +cd /srv +wget http://ftp.debian.org/debian/dists/stable/main/installer-i386/current/images/hd-media/gtk/initrd.gz http://ftp.debian.org/debian/dists/stable/main/installer-i386/current/images/hd-media/gtk/vmlinuz +git clone https://anonscm.debian.org/git/d-i/babelbox.git +cd babelbox +cat babelbox-grub >> /etc/grub.d/40_custom +update-grub +./cronscript + +echo "You need to download a Debian i386 DVD ISO into /srv" diff --git a/scripts/virtualbox.sh b/scripts/virtualbox.sh new file mode 100755 index 0000000..1d413ce --- /dev/null +++ b/scripts/virtualbox.sh @@ -0,0 +1,33 @@ +echo "installing virtualbox guest additions" + +# install virtualbox additions build dependancies +apt-get --yes install linux-headers-$(uname -r) build-essential dkms + + +# If libdbus is not installed, virtualbox will not autostart +apt-get -y install --no-install-recommends libdbus-1-3 + +# deprecated: this remove virtualbox additions installed +# from the debian installer pre-wheezy release + +#if test -f .vbox_version ; then + # The netboot installs the VirtualBox support (old) so we have to remove it +# if test -f /etc/init.d/virtualbox-ose-guest-utils ; then +# /etc/init.d/virtualbox-ose-guest-utils stop +# fi + +# rmmod vboxguest +# aptitude -y purge virtualbox-ose-guest-x11 virtualbox-ose-guest-dkms virtualbox-ose-guest-utils +#fi + +# Install the VirtualBox guest additions +mount -o loop VBoxGuestAdditions.iso /mnt +yes|sh /mnt/VBoxLinuxAdditions.run +umount /mnt +rm -f VBoxGuestAdditions.iso + +# Start the newly build driver +service vboxadd start + +# cleanup virtualbox stuff +apt-get --yes remove linux-headers-$(uname -r) build-essential dkms diff --git a/setup-babelbox.sh b/setup-babelbox.sh deleted file mode 100755 index d12cb3e..0000000 --- a/setup-babelbox.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -e - -cd http -wget -c -N http://cdimage.debian.org/debian-cd/current/i386/iso-dvd/debian-8.3.0-i386-DVD-1.iso -cd .. - -packer build debian-babelbox.json