From ca56d08da5985b779e8e888cb5db97c9824d85b7 Mon Sep 17 00:00:00 2001 From: Stefan Davis Date: Wed, 16 Nov 2016 00:42:26 +0000 Subject: [PATCH 1/2] Added bt-vhd/vhd-bundle and azure patch --- bin/vhd-bundle | 144 +++++++++++++++++++++++++++++++++++++++++++++ bt-vhd | 122 ++++++++++++++++++++++++++++++++++++++ patches/azure/conf | 30 ++++++++++ 3 files changed, 296 insertions(+) create mode 100755 bin/vhd-bundle create mode 100755 bt-vhd create mode 100755 patches/azure/conf diff --git a/bin/vhd-bundle b/bin/vhd-bundle new file mode 100755 index 0000000..a9a9bed --- /dev/null +++ b/bin/vhd-bundle @@ -0,0 +1,144 @@ +#!/bin/bash -e +# depends: qemu grub2 parted kpartx zip ovftool +# Copyright (c) 2011-2015 TurnKey GNU/Linux - http://www.turnkeylinux.org +# +# This file is part of buildtasks. +# +# Buildtasks is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. + + +fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; } +info() { echo "INFO [$(basename $0)]: $@"; } + +usage() { +cat< $devicemap < $fstab +echo -e "UUID=$UUID\t/\text4\tdefaults\t0\t2" >> $fstab + +#tklpatch-apply $rootfs $BT/patches/azure + +info "umounting the jumble..." +umount $rootfs.fs/proc +grep $rootfs.fs/sys /proc/mounts | cut -f2 -d" " | sort -r | xargs umount -n +umount $rootfs.fs/dev +umount $rootfs.fs/ +rmdir $rootfs.fs + +info "converting raw image to vhd" +#qemu-img convert -f raw $rootfs.raw -O vmdk -o compat6 $name.vmdk +qemu-img convert -f raw $rootfs.raw -O vpc -o subformat=fixed $name.vhd + +info "cleaning up" +kpartx -d /dev/mapper/`basename $loopdev`p1 +losetup -d $loopdev + +info "setting up image directory" +mkdir $name +mv $name.vhd $name/ + +cat > $name/README.txt <&2; exit 1; } +warning() { echo "WARNING [$(basename $0)]: $@"; } +info() { echo "INFO [$(basename $0)]: $@"; } + +usage() { +cat<> /etc/apt/sources.list.d/azure.list +deb http://debian-archive.trafficmanager.net/debian jessie-backports main +deb-src http://debian-archive.trafficmanager.net/debian jessie-backports main +deb http://debian-archive.trafficmanager.net/debian-azure jessie main +deb-src http://debian-archive.trafficmanager.net/debian-azure jessie main +EOF + +gpg --keyserver pgpkeys.mit.edu --recv-key 06EA49E9A86CAD7F +gpg -a --export 06EA49E9A86CAD7F | apt-key add - + +apt-key update + +install waagent +waagent -force -deprovision +export HISTSIZE=0 From b21f87ffd422db21fcb25792ab1fe13401a8487b Mon Sep 17 00:00:00 2001 From: Stefan Davis Date: Tue, 20 Dec 2016 00:32:00 +0000 Subject: [PATCH 2/2] cleaning up azure branch --- bin/vhd-bundle | 42 ++++++++++++++++++++++++++---------------- bt-vhd | 3 +-- patches/azure/conf | 6 +++++- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/bin/vhd-bundle b/bin/vhd-bundle index a9a9bed..b2befac 100755 --- a/bin/vhd-bundle +++ b/bin/vhd-bundle @@ -47,8 +47,10 @@ name=$(basename $rootfs .rootfs) # image size consts. +# made default size smaller for testing +# azure docs recommend disabling LVM info "creating raw image ($VM_SIZE sparse) and partitions" -qemu-img create -f raw $rootfs.raw 4G +qemu-img create -f raw $rootfs.raw 4G # made default size smaller for testing parted --script $rootfs.raw mklabel msdos parted --script -- $rootfs.raw mkpart primary 512M 3512M parted --script -- $rootfs.raw set 1 boot on @@ -75,10 +77,6 @@ mount --rbind --make-rslave /proc $rootfs.fs/proc info "installing and configuring grub" grubcfg=$rootfs.fs/boot/grub/grub.cfg -# remove / add executable perm to os-prober to stop duplicate grub entries -chroot $rootfs.fs chmod -x /etc/grub.d/30_os-prober -chroot $rootfs.fs grub-mkconfig -o /boot/grub/grub.cfg -chroot $rootfs.fs chmod +x /etc/grub.d/30_os-prober devicemap=$rootfs.fs/boot/grub/device.map @@ -86,23 +84,27 @@ cat > $devicemap < $fstab echo -e "UUID=$UUID\t/\text4\tdefaults\t0\t2" >> $fstab -#tklpatch-apply $rootfs $BT/patches/azure +tklpatch-apply $rootfs $BT/patches/azure + +grub-install --force --modules='part_msdos ext2 search_fs_uuid' --root-directory=$rootfs.fs $loopdev + +# remove / add executable perm to os-prober to stop duplicate grub entries +chroot $rootfs.fs chmod -x /etc/grub.d/30_os-prober +chroot $rootfs.fs grub-mkconfig -o /boot/grub/grub.cfg +chroot $rootfs.fs chmod +x /etc/grub.d/30_os-prober + +info "tweaking grub settings" +sed -i "/loopback/d; /set root=(loop/d; s|\(root=\).* ro|\1UUID=$UUID ro dolvm|" $grubcfg +#remove temp grub/device.map +rm -f $devicemap info "umounting the jumble..." umount $rootfs.fs/proc @@ -111,9 +113,17 @@ umount $rootfs.fs/dev umount $rootfs.fs/ rmdir $rootfs.fs -info "converting raw image to vhd" +info "resizing raw image (to align to 1MB)" #qemu-img convert -f raw $rootfs.raw -O vmdk -o compat6 $name.vmdk -qemu-img convert -f raw $rootfs.raw -O vpc -o subformat=fixed $name.vhd +MB=$((1024*1024)) +old_size=$(qemu-img info -f raw $rootfs.raw | sed -r -n "/virtual/{s/.*\(([0-9]+) bytes.*/\1/p}") +new_size=$((($old_size/$MB+1)*$MB)) +qemu-img resize -f raw $rootfs.raw $new_size + +info "converting raw image to vhd" +qemu-img convert -f raw $rootfs.raw -O vpc -o subformat=fixed,force_size $name.vhd -p + + info "cleaning up" kpartx -d /dev/mapper/`basename $loopdev`p1 diff --git a/bt-vhd b/bt-vhd index b70a0eb..047ef12 100755 --- a/bt-vhd +++ b/bt-vhd @@ -93,12 +93,11 @@ $BT/bin/iso-verify $BT_ISOS $BT_VERSION $appname cd $O tklpatch-extract-iso $BT_ISOS/$isofile tklpatch-apply $rootfs $BT/patches/headless -tklpatch-apply $rootfs $BT/patches/azure $BT/bin/rootfs-cleanup $rootfs $BT/bin/aptconf-tag $rootfs vm -bash -exv $BT/bin/vhd-bundle $O/$rootfs +$BT/bin/vhd-bundle $O/$rootfs $BT/bin/generate-signature $O/$name.vhd diff --git a/patches/azure/conf b/patches/azure/conf index 1c1f1cb..35d7f5b 100755 --- a/patches/azure/conf +++ b/patches/azure/conf @@ -10,9 +10,11 @@ install() { +# Added recommended default grub settings DEFAULT=/etc/default/grub sed -i 's/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 rootdelay=30"/' $DEFAULT +# Should we be adding these repos or replacing the normal debian repos? cat <> /etc/apt/sources.list.d/azure.list deb http://debian-archive.trafficmanager.net/debian jessie-backports main deb-src http://debian-archive.trafficmanager.net/debian jessie-backports main @@ -26,5 +28,7 @@ gpg -a --export 06EA49E9A86CAD7F | apt-key add - apt-key update install waagent -waagent -force -deprovision + +waagent -force -deprovision -verbose + export HISTSIZE=0