diff options
author | Kim Hagen <kim.sidney@gmail.com> | 2018-10-29 21:43:09 +0100 |
---|---|---|
committer | Kim Hagen <kim.sidney@gmail.com> | 2018-10-29 21:43:09 +0100 |
commit | 7a19a16233edce226791fea64ee8db7e4400e4bd (patch) | |
tree | 153785450772fe409965f9a5847da3642225486f | |
parent | 4d16dbead89c44aca5bcc91981a98572b9c15f16 (diff) | |
download | vyos-build-7a19a16233edce226791fea64ee8db7e4400e4bd.tar.gz vyos-build-7a19a16233edce226791fea64ee8db7e4400e4bd.zip |
Add part of oracle cloud build
-rw-r--r-- | Makefile | 11 | ||||
-rwxr-xr-x | scripts/build-oracle-image | 154 | ||||
-rw-r--r-- | tools/cloud-init/OCI/90_dpkg.cfg | 2 | ||||
-rw-r--r-- | tools/cloud-init/OCI/config.boot.default | 30 |
4 files changed, 197 insertions, 0 deletions
@@ -114,6 +114,16 @@ AWS: clean prepare cd .. @scripts/copy-image +.PHONY: oracle +.ONESHELL: +oracle: 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/OCI/90_dpkg.cfg build/config/includes.chroot/etc/cloud/cloud.cfg.d/ + cd $(build_dir) + @../scripts/build-oracle-image + .PHONY: clean .ONESHELL: clean: @@ -129,6 +139,7 @@ clean: rm -f *.vhd rm -f *.raw rm -f *.tar.gz + rm -f *.qcow2 .PHONY: purge purge: diff --git a/scripts/build-oracle-image b/scripts/build-oracle-image new file mode 100755 index 00000000..61f8ddee --- /dev/null +++ b/scripts/build-oracle-image @@ -0,0 +1,154 @@ +#!/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 <http://www.gnu.org/licenses/>. +# +# File: build-oracle-image +# Purpose: +# Build VyOS image for Oracle 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 +OUTPUTQCOW2=VyOS-"$dateymd".qcow2 +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 + +qemu-img convert -f raw -O qcow2 ${OUTPUT} ${OUTPUTQCOW2} +rm $OUTPUT diff --git a/tools/cloud-init/OCI/90_dpkg.cfg b/tools/cloud-init/OCI/90_dpkg.cfg new file mode 100644 index 00000000..0575be1e --- /dev/null +++ b/tools/cloud-init/OCI/90_dpkg.cfg @@ -0,0 +1,2 @@ +# to update this file, run dpkg-reconfigure cloud-init +datasource_list: [ Oracle ] diff --git a/tools/cloud-init/OCI/config.boot.default b/tools/cloud-init/OCI/config.boot.default new file mode 100644 index 00000000..18f6ef09 --- /dev/null +++ b/tools/cloud-init/OCI/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 { + } +} |