From 98d05b1131be6e650b4da931929fa0c08d3a8723 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 26 Nov 2023 20:12:29 +0100 Subject: Makefile: T2640: add helper to convert ISO to OCI image to start a container Use either "make oci" or call the script manually: $ scripts/iso-to-oci build/live-image-amd64.hybrid.iso I: mount ISO build/live-image-amd64.hybrid.iso I: extracting squashfs content I: generate OCI container image vyos-1.5-strongswan-202311241125.tar I: to import the previously generated OCI image to your local images run: docker import vyos-1.5-strongswan-202311241125.tar vyos:1.5-strongswan-202311241125 --change 'CMD [/sbin/init]' (cherry picked from commit 499e8e1cbb90e24acf80d383a69e138cd745807c) --- scripts/iso-to-oci | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 scripts/iso-to-oci (limited to 'scripts') diff --git a/scripts/iso-to-oci b/scripts/iso-to-oci new file mode 100755 index 00000000..c9396290 --- /dev/null +++ b/scripts/iso-to-oci @@ -0,0 +1,63 @@ +#!/bin/bash + +function cleanup() { + if [[ -d $ROOTFS ]]; then + rm -rf $ROOTFS + fi + if [[ -d $UNSQUASHFS ]]; then + rm -rf $UNSQUASHFS + fi +} + +if [[ $(/usr/bin/id -u) -ne 0 ]]; then + echo "Not running as root" + exit +fi + +if [ "$#" -ne 1 ]; then + echo "Illegal number of parameters" +fi + +ISO=$1 +ROOTFS=rootfs +UNSQUASHFS=unsquashfs + +# ensure clean working directory +cleanup + +mkdir $ROOTFS $UNSQUASHFS +echo "I: mount ISO $ISO" +mount -t iso9660 -o loop $ISO $ROOTFS/ >/dev/null 2>&1 + +# create directory, unpack squashfs filesystem, get ISO version +# and unmount ISO +echo "I: extracting squashfs content" +unsquashfs -follow -dest $UNSQUASHFS/ $ROOTFS/live/filesystem.squashfs >/dev/null 2>&1 +VERSION=$(jq --raw-output .version $ROOTFS/version.json) +umount $ROOTFS/ + +# fix locales for correct system configuration loading +sed -i 's/^LANG=.*$/LANG=C.UTF-8/' $UNSQUASHFS/etc/default/locale + +# optional step: Decrease docker image size by deleting not necessary files for container +rm -rf $UNSQUASHFS/boot/*.img +rm -rf $UNSQUASHFS/boot/*vyos* +rm -rf $UNSQUASHFS/boot/vmlinuz +rm -rf $UNSQUASHFS/lib/firmware/ +rm -rf $UNSQUASHFS/usr/lib/x86_64-linux-gnu/libwireshark.so* +rm -rf $UNSQUASHFS/lib/modules/*amd64-vyos +rm -rf $UNSQUASHFS/root/.gnupg + +# create a symbolic link to the configuration +ln -s /opt/vyatta/etc/config $UNSQUASHFS/config + +# create docker image +echo "I: generate OCI container image vyos-$VERSION.tar" +tar -C unsquashfs -c . -f vyos-$VERSION.tar + +echo "I: to import the previously generated OCI image to your local images run:" +echo "" +echo " docker import vyos-$VERSION.tar vyos:$VERSION --change 'CMD ["/sbin/init"]'" +echo "" + +cleanup -- cgit v1.2.3 From 553fe4fb0116d3d4a867f07ca3bdef65f6c6dbc0 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 19 Nov 2023 10:18:49 +0100 Subject: Makefile: add new target qemu-live Simply boot a live qemu version from the latest ISO build (10:18) cpo lnx01:~/vyos-build [current] # sudo make qemu-live if [ ! -f build/live-image-amd64.hybrid.iso ]; then echo "Could not find build/live-image-amd64.hybrid.iso" exit 1 fi scripts/check-qemu-install --qemu-cmd build/live-image-amd64.hybrid.iso INFO - Creating Disk image testinstall-20231119-101823-4483.img SeaBIOS (version 1.16.2-debian-1.16.2-1) Machine UUID f48b60b2-e6ad-49ef-9d09-4245d0585e52 Booting from DVD/CD... ISOLINUX 6.04 20200816 ETCD Copyright (C) 1994-2015 H. Peter Anvin et al (cherry picked from commit b3d0ebaf1d7d5b5a54be284e553defb8ed4a7a6f) --- Makefile | 5 +++++ scripts/check-qemu-install | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/Makefile b/Makefile index f4c3b61d..ebb37075 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,11 @@ testc: checkiso testraid: checkiso scripts/check-qemu-install --debug --configd --raid --configtest build/live-image-amd64.hybrid.iso +.PHONY: qemu-live +.ONESHELL: +qemu-live: checkiso + scripts/check-qemu-install --qemu-cmd build/live-image-amd64.hybrid.iso + .PHONE: oci .ONESHELL: oci: checkiso diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index 1095c7ee..7c89327d 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -271,7 +271,7 @@ gen_disk(args.disk) if args.qemu_cmd: tmp = get_qemu_cmd('TESTVM', kvm, args.uefi, args.disk, diskname_raid, args.iso) - print(tmp) + os.system(tmp) exit(0) test_timeout = 3 *3600 # 3 hours (in seconds) -- cgit v1.2.3