From d7b7f5a0440da862db7701f5135b68c9a9ec75b4 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 22 Oct 2018 00:59:33 +0200 Subject: Add Azure creation script --- tools/cloud-init/99-walinuxagent.chroot | 17 +++++++++++++++++ tools/cloud-init/config.boot.default | 30 ++++++++++++++++++++++++++++++ tools/cloud-init/vyos-azure.list.chroot | 2 ++ 3 files changed, 49 insertions(+) create mode 100755 tools/cloud-init/99-walinuxagent.chroot create mode 100644 tools/cloud-init/config.boot.default create mode 100644 tools/cloud-init/vyos-azure.list.chroot (limited to 'tools') diff --git a/tools/cloud-init/99-walinuxagent.chroot b/tools/cloud-init/99-walinuxagent.chroot new file mode 100755 index 00000000..f8848a2c --- /dev/null +++ b/tools/cloud-init/99-walinuxagent.chroot @@ -0,0 +1,17 @@ +#!/bin/sh + +echo I: Waagent / Cloud init + +# debug info: +#echo ForwardToConsole=yes >> /etc/systemd/journald.conf + +# dhcp issue on azure +sed -ie 's,rfc3442-classless-static-routes,disabled-\0,' /etc/dhcp/dhclient.conf + +rm -f /etc/ssh/ssh_host_* +rm -f /var/log/waagent.log +rm -r /var/cache/apt/* +rm -r /var/lib/apt/lists/* + +# prevent systemd message flooding +echo ':msg, contains, "Time has been changed" ~' > /etc/rsyslog.d/time_msgs.conf diff --git a/tools/cloud-init/config.boot.default b/tools/cloud-init/config.boot.default new file mode 100644 index 00000000..18f6ef09 --- /dev/null +++ b/tools/cloud-init/config.boot.default @@ -0,0 +1,30 @@ +system { + syslog { + global { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "0.pool.ntp.org" + server "1.pool.ntp.org" + server "2.pool.ntp.org" + } + console { + device ttyS0 { + speed 9600 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} diff --git a/tools/cloud-init/vyos-azure.list.chroot b/tools/cloud-init/vyos-azure.list.chroot new file mode 100644 index 00000000..91320a59 --- /dev/null +++ b/tools/cloud-init/vyos-azure.list.chroot @@ -0,0 +1,2 @@ +cloud-init +walinuxagent -- cgit v1.2.3 From f6c147b9ae7d2d62cf765c0b91514a052209b591 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Mon, 22 Oct 2018 15:01:58 +0200 Subject: Create dir needed for live-build to crete symlinks --- tools/cloud-init/99-walinuxagent.chroot | 1 + 1 file changed, 1 insertion(+) (limited to 'tools') diff --git a/tools/cloud-init/99-walinuxagent.chroot b/tools/cloud-init/99-walinuxagent.chroot index f8848a2c..1de525cf 100755 --- a/tools/cloud-init/99-walinuxagent.chroot +++ b/tools/cloud-init/99-walinuxagent.chroot @@ -11,6 +11,7 @@ sed -ie 's,rfc3442-classless-static-routes,disabled-\0,' /etc/dhcp/dhclient.conf rm -f /etc/ssh/ssh_host_* rm -f /var/log/waagent.log rm -r /var/cache/apt/* +mkdir -p /var/cache/apt/archives rm -r /var/lib/apt/lists/* # prevent systemd message flooding -- cgit v1.2.3 From 16cc9be3ba331216392e988f20183ab8c4eda0ce Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Tue, 23 Oct 2018 23:58:42 +0200 Subject: Separate files needed for different cloud providers Fix serial console speed settings Add google cloud image generation --- Makefile | 20 +++- scripts/build-GCE-image | 153 ++++++++++++++++++++++++++ scripts/build-azure-image | 6 +- tools/cloud-init/99-walinuxagent.chroot | 18 --- tools/cloud-init/GCE/90_dpkg.cfg | 2 + tools/cloud-init/GCE/config.boot.default | 30 +++++ tools/cloud-init/azure/99-walinuxagent.chroot | 18 +++ tools/cloud-init/azure/config.boot.default | 30 +++++ tools/cloud-init/azure/vyos-azure.list.chroot | 2 + tools/cloud-init/cloud-init.list.chroot | 1 + tools/cloud-init/config.boot.default | 30 ----- tools/cloud-init/vyos-azure.list.chroot | 2 - 12 files changed, 256 insertions(+), 56 deletions(-) create mode 100755 scripts/build-GCE-image delete mode 100755 tools/cloud-init/99-walinuxagent.chroot create mode 100644 tools/cloud-init/GCE/90_dpkg.cfg create mode 100644 tools/cloud-init/GCE/config.boot.default create mode 100755 tools/cloud-init/azure/99-walinuxagent.chroot create mode 100644 tools/cloud-init/azure/config.boot.default create mode 100644 tools/cloud-init/azure/vyos-azure.list.chroot create mode 100644 tools/cloud-init/cloud-init.list.chroot delete mode 100644 tools/cloud-init/config.boot.default delete mode 100644 tools/cloud-init/vyos-azure.list.chroot (limited to 'tools') diff --git a/Makefile b/Makefile index f0af3ab3..f4a9ef29 100644 --- a/Makefile +++ b/Makefile @@ -82,12 +82,24 @@ clearfog: clean prepare azure: clean prepare @set -e @echo "It's not like I'm building this specially for you or anything!" - cp tools/cloud-init/99-walinuxagent.chroot build/config/hooks/ - cp tools/cloud-init/vyos-azure.list.chroot build/config/package-lists/ - cp -f tools/cloud-init/config.boot.default build/config/includes.chroot/opt/vyatta/etc/ + cp tools/cloud-init/azure/99-walinuxagent.chroot build/config/hooks/ + cp tools/cloud-init/azure/vyos-azure.list.chroot build/config/package-lists/ + cp -f tools/cloud-init/azure/config.boot.default build/config/includes.chroot/opt/vyatta/etc/ cd $(build_dir) @../scripts/build-azure-image +.PHONY: GCE +.ONESHELL: +GCE: clean prepare + @set -e + @echo "It's not like I'm building this specially for you or anything!" + mkdir -p build/config/includes.chroot/etc/cloud/cloud.cfg.d + cp tools/cloud-init/GCE/90_dpkg.cfg build/config/includes.chroot/etc/cloud/cloud.cfg.d/ + cp tools/cloud-init/cloud-init.list.chroot build/config/package-lists/ + cp -f tools/cloud-init/GCE/config.boot.default build/config/includes.chroot/opt/vyatta/etc/ + cd $(build_dir) + @../scripts/build-GCE-image + .PHONY: clean .ONESHELL: clean: @@ -101,6 +113,8 @@ clean: rm -f *.img rm -f *.xz rm -f *.vhd + rm -f *.raw + rm -f *.tar.gz .PHONY: purge purge: diff --git a/scripts/build-GCE-image b/scripts/build-GCE-image new file mode 100755 index 00000000..7684bd43 --- /dev/null +++ b/scripts/build-GCE-image @@ -0,0 +1,153 @@ +#!/bin/sh +# +# Copyright (C) 2018 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or later as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# File: build-GCE-image +# Purpose: +# Build VyOS image for Google cloud. + +lb bootstrap + +lb chroot +lb installer +lb binary_chroot +lb chroot_devpts install +lb chroot_proc install +lb chroot_selinuxfs install +lb chroot_sysfs install +lb chroot_hosts install +lb chroot_resolv install +lb chroot_hostname install +lb chroot_sysv-rc install +lb chroot_upstart install +lb chroot_apt install-binary +lb chroot_archives chroot install +lb binary_rootfs +lb binary_manifest +lb binary_package-lists +lb binary_linux-image +lb binary_memtest +lb binary_grub +lb binary_grub2 +lb binary_syslinux +lb binary_disk +lb binary_loadlin +lb binary_win32-loader +lb binary_includes +lb binary_hooks +lb binary_checksums + +# get vyos build version +version=$(cat version) +dateymd=$(date +%Y%m%d) + +###################################### +### Prepare the HDD (format, ext.) ### +###################################### +PARTED=/sbin/parted +OUTPUT=disk.raw +OUTPUTGZ=VyOS-"$dateymd".tar.gz +IMAGE_SIZE=2 +qemu-img create -f raw ${OUTPUT} ${IMAGE_SIZE}G + +${PARTED} -s ${OUTPUT} mktable msdos +${PARTED} -s -a optimal ${OUTPUT} mkpart primary ext4 1Mi 100% +${PARTED} -s ${OUTPUT} set 1 boot on +RESULT_KPARTX=`kpartx -asv ${OUTPUT} 2>&1` + +if echo "${RESULT_KPARTX}" | grep "^add map" ; then + LOOP_DEVICE=$(echo ${RESULT_KPARTX} | cut -d" " -f3) + LOOPRAW_DEVICE=${LOOP_DEVICE%p*} + echo "kpartx mounted using: ${LOOP_DEVICE} via ${LOOPRAW_DEVICE}" +else + echo "It seems kpartx didn't mount the image correctly: exiting." + exit 1 +fi + +cleanup(){ + error=$? + [ ! -d "${MOUNT_DIR}" ] && return + if [ "$error" -gt 0 ]; then + echo + echo "Error $error" + else + echo "Finished." + fi + + set +e + + sync + umount -l ${MOUNT_DIR} + rmdir ${MOUNT_DIR} + + umount devpts-live + umount proc-live + umount sysfs-live + + dmsetup remove --deferred ${LOOP_DEVICE} + losetup -d /dev/${LOOPRAW_DEVICE} + exit $error +} +trap "cleanup" EXIT TERM INT + +mkfs.ext4 /dev/mapper/${LOOP_DEVICE} -L persistence +UUID=$(blkid -o value -s UUID /dev/mapper/${LOOP_DEVICE}) + +# No fsck because of X days without checks +tune2fs -i 0 /dev/mapper/${LOOP_DEVICE} + +MOUNT_DIR=`mktemp -d -t build-debimg.XXXXXX` +mount /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR} + +######################## +### Setting-up files ### +######################## +mkdir -p ${MOUNT_DIR}/boot/grub +mkdir -p ${MOUNT_DIR}/boot/"$version"/rw + +echo "/ union" > ${MOUNT_DIR}/persistence.conf +cp binary/live/filesystem.squashfs ${MOUNT_DIR}/boot/"$version"/"$version.squashfs" +cp binary/live/initrd.img ${MOUNT_DIR}/boot/"$version"/initrd.img +cp binary/live/vmlinuz ${MOUNT_DIR}/boot/"$version"/vmlinuz + +######################## +### Create grub menu ### +######################## +cat > ${MOUNT_DIR}/boot/grub/grub.cfg << EOF +set timeout=5 +set default=0 + +menuentry "VyOS $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,38400n8d earlyprintk=ttyS0,38400 consoleblank=0 systemd.show_status=true + initrd /boot/"$version"/initrd.img +} + +menuentry "Lost password change $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live vyos-union=/boot/"$version" console=tty0 console=ttyS0,38400n8d earlyprintk=ttyS0,38400 consoleblank=0 systemd.show_status=true init=/opt/vyatta/sbin/standalone_root_pw_reset + initrd /boot/"$version"/initrd.img +} +EOF + + +############################# +### Setting-up bootloader ### +############################# +grub-install --boot-directory ${MOUNT_DIR}/boot --force --no-floppy --skip-fs-probe /dev/${LOOPRAW_DEVICE} + +################### +### HOOK SCRIPT ### +################### +fstrim ${MOUNT_DIR} +sync + +tar -Sczf ${OUTPUTGZ} ${OUTPUT} diff --git a/scripts/build-azure-image b/scripts/build-azure-image index d158fe89..d47b4351 100755 --- a/scripts/build-azure-image +++ b/scripts/build-azure-image @@ -12,7 +12,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# File: build-clearfog-image +# File: build-azure-image # Purpose: # Build VyOS image for Azure. @@ -127,12 +127,12 @@ set timeout=5 set default=0 menuentry "VyOS $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true + linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true initrd /boot/"$version"/initrd.img } menuentry "Lost password change $version (Serial console)" { - linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true init=/opt/vyatta/sbin/standalone_root_pw_reset + linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true init=/opt/vyatta/sbin/standalone_root_pw_reset initrd /boot/"$version"/initrd.img } EOF diff --git a/tools/cloud-init/99-walinuxagent.chroot b/tools/cloud-init/99-walinuxagent.chroot deleted file mode 100755 index 1de525cf..00000000 --- a/tools/cloud-init/99-walinuxagent.chroot +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -echo I: Waagent / Cloud init - -# debug info: -#echo ForwardToConsole=yes >> /etc/systemd/journald.conf - -# dhcp issue on azure -sed -ie 's,rfc3442-classless-static-routes,disabled-\0,' /etc/dhcp/dhclient.conf - -rm -f /etc/ssh/ssh_host_* -rm -f /var/log/waagent.log -rm -r /var/cache/apt/* -mkdir -p /var/cache/apt/archives -rm -r /var/lib/apt/lists/* - -# prevent systemd message flooding -echo ':msg, contains, "Time has been changed" ~' > /etc/rsyslog.d/time_msgs.conf diff --git a/tools/cloud-init/GCE/90_dpkg.cfg b/tools/cloud-init/GCE/90_dpkg.cfg new file mode 100644 index 00000000..ac4ffeae --- /dev/null +++ b/tools/cloud-init/GCE/90_dpkg.cfg @@ -0,0 +1,2 @@ +# to update this file, run dpkg-reconfigure cloud-init +datasource_list: [ GCE ] diff --git a/tools/cloud-init/GCE/config.boot.default b/tools/cloud-init/GCE/config.boot.default new file mode 100644 index 00000000..a0cc398f --- /dev/null +++ b/tools/cloud-init/GCE/config.boot.default @@ -0,0 +1,30 @@ +system { + syslog { + global { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "0.pool.ntp.org" + server "1.pool.ntp.org" + server "2.pool.ntp.org" + } + console { + device ttyS0 { + speed 38400 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} diff --git a/tools/cloud-init/azure/99-walinuxagent.chroot b/tools/cloud-init/azure/99-walinuxagent.chroot new file mode 100755 index 00000000..1de525cf --- /dev/null +++ b/tools/cloud-init/azure/99-walinuxagent.chroot @@ -0,0 +1,18 @@ +#!/bin/sh + +echo I: Waagent / Cloud init + +# debug info: +#echo ForwardToConsole=yes >> /etc/systemd/journald.conf + +# dhcp issue on azure +sed -ie 's,rfc3442-classless-static-routes,disabled-\0,' /etc/dhcp/dhclient.conf + +rm -f /etc/ssh/ssh_host_* +rm -f /var/log/waagent.log +rm -r /var/cache/apt/* +mkdir -p /var/cache/apt/archives +rm -r /var/lib/apt/lists/* + +# prevent systemd message flooding +echo ':msg, contains, "Time has been changed" ~' > /etc/rsyslog.d/time_msgs.conf diff --git a/tools/cloud-init/azure/config.boot.default b/tools/cloud-init/azure/config.boot.default new file mode 100644 index 00000000..296c690a --- /dev/null +++ b/tools/cloud-init/azure/config.boot.default @@ -0,0 +1,30 @@ +system { + syslog { + global { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "0.pool.ntp.org" + server "1.pool.ntp.org" + server "2.pool.ntp.org" + } + console { + device ttyS0 { + speed 115200 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} diff --git a/tools/cloud-init/azure/vyos-azure.list.chroot b/tools/cloud-init/azure/vyos-azure.list.chroot new file mode 100644 index 00000000..91320a59 --- /dev/null +++ b/tools/cloud-init/azure/vyos-azure.list.chroot @@ -0,0 +1,2 @@ +cloud-init +walinuxagent diff --git a/tools/cloud-init/cloud-init.list.chroot b/tools/cloud-init/cloud-init.list.chroot new file mode 100644 index 00000000..db064e62 --- /dev/null +++ b/tools/cloud-init/cloud-init.list.chroot @@ -0,0 +1 @@ +cloud-init diff --git a/tools/cloud-init/config.boot.default b/tools/cloud-init/config.boot.default deleted file mode 100644 index 18f6ef09..00000000 --- a/tools/cloud-init/config.boot.default +++ /dev/null @@ -1,30 +0,0 @@ -system { - syslog { - global { - facility all { - level info - } - facility protocols { - level debug - } - } - } - ntp { - server "0.pool.ntp.org" - server "1.pool.ntp.org" - server "2.pool.ntp.org" - } - console { - device ttyS0 { - speed 9600 - } - } - config-management { - commit-revisions 100 - } -} - -interfaces { - loopback lo { - } -} diff --git a/tools/cloud-init/vyos-azure.list.chroot b/tools/cloud-init/vyos-azure.list.chroot deleted file mode 100644 index 91320a59..00000000 --- a/tools/cloud-init/vyos-azure.list.chroot +++ /dev/null @@ -1,2 +0,0 @@ -cloud-init -walinuxagent -- cgit v1.2.3 From a0cdf15c5e65160cf2e56b1658cab11146109a11 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Thu, 25 Oct 2018 14:15:34 +0200 Subject: Add build command for AWS --- Makefile | 14 ++++++++++++++ tools/cloud-init/AWS/90_dpkg.cfg | 2 ++ tools/cloud-init/AWS/config.boot.default | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tools/cloud-init/AWS/90_dpkg.cfg create mode 100644 tools/cloud-init/AWS/config.boot.default (limited to 'tools') diff --git a/Makefile b/Makefile index f4a9ef29..b0904772 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,20 @@ GCE: clean prepare cd $(build_dir) @../scripts/build-GCE-image +.PHONY: AWS +.ONESHELL: +AWS: clean prepare + @set -e + @echo "It's not like I'm building this specially for you or anything!" + mkdir -p build/config/includes.chroot/etc/cloud/cloud.cfg.d + cp tools/cloud-init/AWS/90_dpkg.cfg build/config/includes.chroot/etc/cloud/cloud.cfg.d/ + cp tools/cloud-init/cloud-init.list.chroot build/config/package-lists/ + cp -f tools/cloud-init/AWS/config.boot.default build/config/includes.chroot/opt/vyatta/etc/ + cd $(build_dir) + lb build 2>&1 | tee build.log + cd .. + @scripts/copy-image + .PHONY: clean .ONESHELL: clean: diff --git a/tools/cloud-init/AWS/90_dpkg.cfg b/tools/cloud-init/AWS/90_dpkg.cfg new file mode 100644 index 00000000..1bf7d288 --- /dev/null +++ b/tools/cloud-init/AWS/90_dpkg.cfg @@ -0,0 +1,2 @@ +# to update this file, run dpkg-reconfigure cloud-init +datasource_list: [ Ec2 ] diff --git a/tools/cloud-init/AWS/config.boot.default b/tools/cloud-init/AWS/config.boot.default new file mode 100644 index 00000000..18f6ef09 --- /dev/null +++ b/tools/cloud-init/AWS/config.boot.default @@ -0,0 +1,30 @@ +system { + syslog { + global { + facility all { + level info + } + facility protocols { + level debug + } + } + } + ntp { + server "0.pool.ntp.org" + server "1.pool.ntp.org" + server "2.pool.ntp.org" + } + console { + device ttyS0 { + speed 9600 + } + } + config-management { + commit-revisions 100 + } +} + +interfaces { + loopback lo { + } +} -- cgit v1.2.3