packer: use latest VirtualBox Guest Additions ISO
authorMichael Prokop <mika@grml.org>
Tue, 21 Nov 2017 15:10:23 +0000 (16:10 +0100)
committerMichael Prokop <mika@grml.org>
Tue, 21 Nov 2017 15:10:23 +0000 (16:10 +0100)
Using the default local Virtualbox Guest Additions ISO will result
in different builds depending on the system being used.
My Debian jessie system with Virtualbox 5.1.8-dfsg-6~bpo8+2
from jessie-backports/contrib is actually too old to build
stretch and newer as the kernel module can't be compiled.
So instead use a specific VBoxGuestAdditions ISO, currently
being the one recommended by upstream on https://www.virtualbox.org/

While at it:

* increase VM memory size from 512MB to 1GB during build, otherwise
  we can't even use a temporary apt cache directory and will fail with OOM

* check for build errors in virtualbox logs

* /var/log/VBoxGuestAdditions.log doesn't necessarily exist,
  so instead display the last 10 lines of the according log files
  that actually exist

packer/debian64.json
packer/debian64_provision.sh

index 7c45eee..bac55c1 100644 (file)
     "boot_command": [
       "<tab> ssh=grml <enter>"
     ],
-    "shutdown_command": "shutdown -h now"
+    "shutdown_command": "shutdown -h now",
+    "guest_additions_url": "https://www.virtualbox.org/download/testcase/VBoxGuestAdditions_5.2.1-118918.iso",
+    "guest_additions_sha256": "5023b5b6314593c092d2680fbbfe37870977b1d7fa790af9bdd4a75944ca0603",
+    "vboxmanage": [
+      ["modifyvm", "{{.Name}}", "--memory", "1024"]
+    ]
   }
   ],
     "provisioners": [
index c7eed1f..2a416de 100644 (file)
@@ -67,7 +67,13 @@ virtualbox_setup() {
   mountpoint "${TARGET}/media/cdrom" >/dev/null && umount "${TARGET}/media/cdrom"
   mount -t iso9660 $isofile "${TARGET}/media/cdrom/"
   UTS_RELEASE=$KERNELVERSION LD_PRELOAD=/tmp/fake-uname.so grml-chroot "$TARGET" /media/cdrom/VBoxLinuxAdditions.run --nox11 || true
-  tail -10 "${TARGET}/var/log/VBoxGuestAdditions.log"
+  if grep -q "make: .*vboxguest.*Error 2" "${TARGET}/var/log/vboxadd-install.log" ; then
+    echo "Error: looks like a fatal error happened during installation of VirtualBox Guest Additions." >&2
+    exit 1
+  fi
+  [ -r "${TARGET}/var/log/VBoxGuestAdditions.log" ] && tail -10 "${TARGET}/var/log/VBoxGuestAdditions.log"
+  [ -r "${TARGET}/var/log/vboxadd-install.log" ]    && tail -10 "${TARGET}/var/log/vboxadd-install.log"
+  [ -r "${TARGET}/var/log/vboxadd-setup.log" ]      && tail -10 "${TARGET}/var/log/vboxadd-setup.log"
   umount "${TARGET}/media/cdrom/"
 
   # work around bug in VirtualBox 4.3.18 which leaves process behind,