[neon/ubuntu-core] /: Move the ISO creation in an LXD VM

Kevin Ottens null at kde.org
Tue Aug 13 10:09:42 BST 2024


Git commit 9011fc1a7802791a4e8ef7f77c4200f72ad92b08 by Kevin Ottens.
Committed on 12/08/2024 at 15:44.
Pushed by ervin into branch 'master'.

Move the ISO creation in an LXD VM

This makes it easier to use and make sure it's not doing anything wrong
in the host system.

M  +3    -10   Makefile
R  +22   -8    create-iso-impl.sh [from: create_iso.sh - 081% similarity]
A  +50   -0    create-iso.sh
M  +1    -1    image/core-desktop.yaml.in

https://invent.kde.org/neon/ubuntu-core/-/commit/9011fc1a7802791a4e8ef7f77c4200f72ad92b08

diff --git a/Makefile b/Makefile
index 160dfaa..660c8e0 100644
--- a/Makefile
+++ b/Makefile
@@ -37,18 +37,11 @@ kde-neon-core-dangerous-amd64.model: kde-neon-core-amd64.json
 	echo "generate xz file"
 	xz --force --threads=0 -vv $<
 
-%.installer.img: %.img.xz
-	-rm -rf output/
-	cat image/install-sources.yaml.in |sed "s/@SIZE@/$(shell stat -c%s $<)/g" > image/install-sources.yaml
-	cat image/core-desktop.yaml.in |sed "s/@PATH@/$</g" > image/core-desktop.yaml
-	sudo ubuntu-image classic --debug -O output/ image/core-desktop.yaml
-	mv output/plasma-core-desktop-22-amd64.img $@
-
-%.iso: %.installer.img
-	sudo ./create_iso.sh $<
+%.iso: %.img.xz
+	./create-iso.sh $<
 
 clean:
 	rm -rf *.model.build image2
-	rm -f *.snap-list *.img *.tar.gz *-signed-*.json *-dangerous-*.json
+	rm -f *.snap-list *.img *.img.xz *.tar.gz *.iso *-signed-*.json *-dangerous-*.json
 
 .PHONY: all clean dangerous signed
diff --git a/create_iso.sh b/create-iso-impl.sh
similarity index 81%
rename from create_iso.sh
rename to create-iso-impl.sh
index 737d379..3484f80 100755
--- a/create_iso.sh
+++ b/create-iso-impl.sh
@@ -1,20 +1,35 @@
 #!/bin/sh
 
-# Process obtained from https://itnext.io/how-to-create-a-custom-ubuntu-live-from-scratch-dd3b3f213f81
+set -ex
+
+SCRIPT_PATH=`readlink -f $0`
+SCRIPT_DIR=`dirname $SCRIPT_PATH`
 
-DISK_IMAGE=$PWD/ubuntu-core-desktop-22-amd64.img
-if [ -e "$1" ]; then
-  DISK_IMAGE=$PWD/$1
+cd $SCRIPT_DIR
+
+if [ -f "$1" ]; then
+  CORE_IMAGE=$1
 else
-   echo "Provide classic img file as first parameter"
+   echo "Provide Ubuntu Core compressed img file as first parameter"
+   exit 1
 fi
 
+IMAGE_SIZE=`stat -c%s $CORE_IMAGE`
+
+cat image/install-sources.yaml.in |sed "s, at SIZE@,$IMAGE_SIZE,g" > image/install-sources.yaml
+cat image/core-desktop.yaml.in |sed "s, at PATH@,$CORE_IMAGE,g" > image/core-desktop.yaml
+ubuntu-image classic --debug -O output/ image/core-desktop.yaml
+
+INSTALLER_IMAGE=$PWD/output/plasma-core-desktop-installer-amd64.img
+
+# Process obtained from https://itnext.io/how-to-create-a-custom-ubuntu-live-from-scratch-dd3b3f213f81
+
 # where to mount the disk image
 CHROOT=$PWD/output/mnt
 
 mkdir -p $CHROOT
 # since we know that the partition with the data is the third one, we use awk to extract the start sector
-sudo mount -o loop,offset=$(expr 512 \* $(fdisk -l ${DISK_IMAGE} |grep img3 | awk '{print $2}')) ${DISK_IMAGE} $CHROOT
+sudo mount -o loop,offset=$(expr 512 \* $(fdisk -l ${INSTALLER_IMAGE} |grep img3 | awk '{print $2}')) ${INSTALLER_IMAGE} $CHROOT
 
 # we prepare the chroot environment to ensure that everything works inside..
 sudo mount -o bind /dev ${CHROOT}/dev
@@ -103,7 +118,7 @@ sudo xorriso \
    -iso-level 3 \
    -full-iso9660-filenames \
    -volid "Ubuntu Core Desktop" \
-   -output ${DISK_IMAGE%.*}.iso \
+   -output "${CORE_IMAGE%.*.*}.iso" \
    -eltorito-boot boot/grub/bios.img \
       -no-emul-boot \
       -boot-load-size 4 \
@@ -122,4 +137,3 @@ sudo xorriso \
       "/boot/grub/bios.img=isolinux/bios.img" \
       "."
 
-cd ..
diff --git a/create-iso.sh b/create-iso.sh
new file mode 100755
index 0000000..5607dd8
--- /dev/null
+++ b/create-iso.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+set -ex
+
+SCRIPT_PATH=`readlink -f $0`
+SCRIPT_DIR=`dirname $SCRIPT_PATH`
+
+if [ -f "$SCRIPT_DIR/$1" ]; then
+  CORE_IMAGE=$1
+else
+   echo "Provide Ubuntu Core compressed img file as first parameter"
+   exit 1
+fi
+
+LXC_INSTANCE=kde-neon-core-iso-builder
+LXC_PROJECT_ROOT=/root/kde-neon-core
+
+cleanup() {
+   lxc delete -f $LXC_INSTANCE
+}
+trap cleanup EXIT
+
+lxc_exec() {
+   lxc exec $LXC_INSTANCE -- $*
+}
+
+lxc init --vm ubuntu:24.04 $LXC_INSTANCE \
+   -c limits.cpu=4 \
+   -c limits.memory=8GiB \
+   -d root,size=32GiB
+lxc start $LXC_INSTANCE
+
+# Give a chance to the VM to finish booting
+sleep 30
+
+for i in "create-iso-impl.sh" "image" $1 ; do
+   lxc file push -p -r $SCRIPT_DIR/$i $LXC_INSTANCE$LXC_PROJECT_ROOT
+done
+
+lxc_exec snap install --classic ubuntu-image
+lxc_exec apt-get install -y \
+   mtools \
+   xorriso
+
+lxc_exec $LXC_PROJECT_ROOT/create-iso-impl.sh $CORE_IMAGE
+
+CORE_ISO_IMAGE="${CORE_IMAGE%.*.*}.iso"
+lxc file pull $LXC_INSTANCE$LXC_PROJECT_ROOT/image2/$CORE_ISO_IMAGE $SCRIPT_DIR
+
+
diff --git a/image/core-desktop.yaml.in b/image/core-desktop.yaml.in
index a228775..65dc99c 100644
--- a/image/core-desktop.yaml.in
+++ b/image/core-desktop.yaml.in
@@ -78,6 +78,6 @@ customization:
 artifacts:
   img:
     -
-      name: plasma-core-desktop-22-amd64.img
+      name: plasma-core-desktop-installer-amd64.img
   manifest:
     name: plasma-core-desktop-pc-amd64.manifest



More information about the Neon-commits mailing list