[neon/neon/livecd-rootfs/Neon/release] live-build/ubuntu/hooks: Add the 099-ubuntu-image-customization.chroot hook for desktop-preinstalled similarly to what we have in groovy+ for the pi desktop, but improved for amd64 platforms. We use it to generate a valid grub.cfg on the rootfs (similar to ubuntu-cpc)

Łukasz 'sil2100' Zemczak null at kde.org
Tue Nov 16 12:01:06 GMT 2021


Git commit 498b83fe5922df70176937644650607687a828be by Łukasz 'sil2100' Zemczak.
Committed on 28/10/2021 at 15:21.
Pushed by jriddell into branch 'Neon/release'.

Add the 099-ubuntu-image-customization.chroot hook for desktop-preinstalled similarly to what we have in groovy+ for the pi desktop, but improved for amd64 platforms. We use it to generate a valid grub.cfg on the rootfs (similar to ubuntu-cpc)

A  +115  -0    live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot

https://invent.kde.org/neon/neon/livecd-rootfs/commit/498b83fe5922df70176937644650607687a828be

diff --git a/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot b/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot
new file mode 100644
index 00000000..ca826f48
--- /dev/null
+++ b/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot
@@ -0,0 +1,115 @@
+#!/bin/bash -ex
+
+. /root/config/chroot
+
+# Specific ubuntu-image chroot configuration goes here.
+if [ "$IMAGEFORMAT" == "none" ]; then
+    if [ "$SUBPROJECT" == "desktop-preinstalled" ]; then
+        # Create files/dirs Ubiquity requires
+        mkdir -p /var/log/installer
+        touch /var/log/installer/debug
+        touch /var/log/syslog
+        chown syslog:adm /var/log/syslog
+
+        # Create the oem user account
+        if [ -e "/usr/sbin/oem-config-prepare" ] then
+            /usr/sbin/useradd -d /home/oem -G adm,sudo -m -N -u 29999 oem
+
+            /usr/sbin/oem-config-prepare --quiet
+            touch "/var/lib/oem-config/run"
+        fi
+
+        # Make the writable partition grow
+        echo "LABEL=writable    /     ext4    defaults,x-systemd.growfs    0 0" >>/etc/fstab
+
+        # Create a 1GB swapfile
+        dd if=/dev/zero of=/swapfile bs=1M count=1024
+        chmod 0600 /swapfile
+        mkswap /swapfile
+
+        echo "/swapfile         none  swap    sw    0 0" >>/etc/fstab
+
+        if [ $(dpkg --print-architecture) == "amd64" ]; then
+            # We need to get a grub.cfg generated for our image
+            # This is copy-pasted from 999-cpc-fixes.chroot
+            # TODO: Make this better. One idea would be to have this exported
+            #  in functions or something, and then reused by both the cpc-fixes
+            #  and here. Another possibility is to actually trim down the
+            #  pseudo_grub_probe to only work for a regular preinstalled
+            #  desktop.
+            #  But short term it's safer to use a known code-base.
+            psuedo_grub_probe() {
+               cat <<"PSUEDO_GRUB_PROBE"
+#!/bin/sh
+Usage() {
+   cat <<EOF
+Usage: euca-psuedo-grub-probe
+   this is a wrapper around grub-probe to provide the answers for an ec2 guest
+EOF
+}
+bad_Usage() { Usage 1>&2; fail "$@"; }
+
+short_opts=""
+long_opts="device-map:,target:,device"
+getopt_out=$(getopt --name "${0##*/}" \
+   --options "${short_opts}" --long "${long_opts}" -- "$@") &&
+   eval set -- "${getopt_out}" ||
+   bad_Usage
+
+device_map=""
+target=""
+device=0
+arg=""
+
+while [ $# -ne 0 ]; do
+   cur=${1}; next=${2};
+   case "$cur" in
+      --device-map) device_map=${next}; shift;;
+      --device) device=1;;
+      --target) target=${next}; shift;;
+      --) shift; break;;
+   esac
+   shift;
+done
+arg=${1}
+
+case "${target}:${device}:${arg}" in
+   device:*:/*) echo "/dev/sda1"; exit 0;;
+   fs:*:*) echo "ext2"; exit 0;;
+   partmap:*:*)
+      # older versions of grub (lucid) want 'part_msdos' written
+      # rather than 'msdos'
+      legacy_pre=""
+      grubver=$(dpkg-query --show --showformat '${Version}\n' grub-pc 2>/dev/null) &&
+         dpkg --compare-versions "${grubver}" lt 1.98+20100804-5ubuntu3 &&
+         legacy_pre="part_"
+      echo "${legacy_pre}msdos";
+      exit 0;;
+   abstraction:*:*) echo ""; exit 0;;
+   drive:*:/dev/sda) echo "(hd0)";;
+   drive:*:/dev/sda*) echo "(hd0,1)";;
+   fs_uuid:*:*) exit 1;;
+esac
+PSUEDO_GRUB_PROBE
+            }
+
+            gprobe="/usr/sbin/grub-probe"
+            moved=0
+            if [ -f "${gprobe}" ]; then
+               mv "${gprobe}" "${gprobe}.dist"
+               moved=1
+            fi
+            psuedo_grub_probe > "${gprobe}"
+            chmod 755 "${gprobe}"
+
+            # Generate grub.cfg
+            /usr/sbin/update-grub2
+
+            grub2cfg="/boot/grub/grub.cfg"
+            [ ! -f "${grub2cfg}" ] ||
+               sed -i -e "s,root=/dev/[hs]da1,root=LABEL=writable," "${grub2cfg}"
+
+            [ ${moved} -eq 0 ] || mv "${gprobe}.dist" "${gprobe}"
+        fi
+    fi
+fi



More information about the Neon-commits mailing list