commit:     66d90af4a77053403c2def45fe110307b53258be
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 12 16:12:58 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Oct 12 16:12:58 2024 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=66d90af4

Restructure grub installation

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 targets/diskimage-stage2/controller.sh    |  2 +-
 targets/support/create-qcow2.sh           | 34 +++++++++++++++++++++++--------
 targets/support/diskimage-installation.sh |  8 ++++++++
 targets/support/qcow2-grub-install.sh     |  7 +++++++
 targets/support/qcow2-installation.sh     |  9 --------
 5 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/targets/diskimage-stage2/controller.sh 
b/targets/diskimage-stage2/controller.sh
index 5dac4cc9..a904ef5a 100755
--- a/targets/diskimage-stage2/controller.sh
+++ b/targets/diskimage-stage2/controller.sh
@@ -5,7 +5,7 @@ source ${clst_shdir}/support/functions.sh
 case $1 in
         run)
                # We need to install grub's EFI files and do very basic 
configuration
-               exec_in_chroot "${clst_shdir}/support/qcow2-installation.sh" || 
exit 1
+               exec_in_chroot 
"${clst_shdir}/support/diskimage-installation.sh" || exit 1
                ;;
 
        pre-kmerge)

diff --git a/targets/support/create-qcow2.sh b/targets/support/create-qcow2.sh
index 2d100b80..b41d635a 100755
--- a/targets/support/create-qcow2.sh
+++ b/targets/support/create-qcow2.sh
@@ -49,6 +49,27 @@ qcow2die() {
        die "$@"
 }
 
+# We need a means to execute a script inside the qcow with filesystems mounted
+exec_in_qcow2() {
+       local file_name=$(basename ${1})
+
+       # copy_to_chroot ${1}
+       cp -pPR "${1}" "${mymountpoint}/tmp" || die
+        # copy_to_chroot ${clst_shdir}/support/chroot-functions.sh
+        cp -pPR "${clst_shdir}/support/chroot-functions.sh" 
"${mymountpoint}/tmp" || die
+
+        # Ensure the file has the executable bit set
+        chmod +x "${mymountpoint}/tmp/${file_name}" || die
+
+        echo "Running ${file_name} in qcow2:"
+        echo "    ${clst_CHROOT} ${mymountpoint} /tmp/${file_name}"
+        ${clst_CHROOT} "${mymountpoint}" "/tmp/${file_name}" || exit 1
+
+        rm -f "${mymountpoint}/tmp/${file_name}" || die
+        rm -f "${mymountpoint}/tmp/chroot-functions.sh" || die
+}
+
+
 echo "Creating a new qcow2 disk image file ${myqcow2}.tmp.qcow2 with size 
${clst_qcow2_size/%iB/}"
 qemu-img create -f qcow2 "${myqcow2}.tmp.qcow2" ${clst_qcow2_size/%iB/} || die 
"Cannot create qcow2 file"
 
@@ -94,7 +115,10 @@ mount ${mypartefi} "${mymountpoint}/boot" || qcow2die 
"Could not mount boot part
 echo "Copying files into the mounted directories from ${clst_stage_path}"
 cp -a "${clst_stage_path}"/* "${mymountpoint}/" || qcow2die "Could not copy 
content into mounted image"
 
-# at this point we have a working system
+# now we can chroot in and install grub
+#/usr/sbin/grub-install --verbose --no-floppy --efi-directory=/boot 
--removable --skip-fs-probe \
+#       --no-nvram --no-bootsector --target=x86_64-efi || die "grub-install 
failed"
+exec_in_qcow2 "${clst_shdir}/support/qcow2-grub-install.sh"
 
 echo "Creating a CONTENTS file ${myqcow2}.CONTENTS"
 pushd "${mymountpoint}/" &> /dev/null || qcow2die "Could not cd into 
mountpoint"
@@ -104,14 +128,6 @@ popd &> /dev/null                     || qcow2die "Could 
not cd out of mountpoin
 echo "Compressing the CONTENTS file"
 gzip "${myqcow2}.CONTENTS"      || qcow2die "Could not compress the CONTENTS 
file"
 
-# note: the following must already have been done by the stage2:
-# - rudimentary configuration
-# - installation of cloud-init if requested
-# - installation of kernel
-# - installation of fallback efi loader
-# - enabling of services
-# luckily efi requires no image magic, just regular files...
-
 echo "Unmounting things"
 umount "${mymountpoint}/boot" || qcow2die "Could not unmount boot partition"
 umount "${mymountpoint}" || qcow2die "Could not unmount root partition"

diff --git a/targets/support/diskimage-installation.sh 
b/targets/support/diskimage-installation.sh
new file mode 100755
index 00000000..8599112b
--- /dev/null
+++ b/targets/support/diskimage-installation.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+source /tmp/chroot-functions.sh
+
+# do some basic system setup here
+
+# we can't install the boot loader because nothing is mounted anywhere
+

diff --git a/targets/support/qcow2-grub-install.sh 
b/targets/support/qcow2-grub-install.sh
new file mode 100755
index 00000000..e1bda92b
--- /dev/null
+++ b/targets/support/qcow2-grub-install.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+source /tmp/chroot-functions.sh
+
+# install the boot loader here
+
+/bin/bash

diff --git a/targets/support/qcow2-installation.sh 
b/targets/support/qcow2-installation.sh
deleted file mode 100755
index 17f32aa6..00000000
--- a/targets/support/qcow2-installation.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-source /tmp/chroot-functions.sh
-
-# basic system setup
-
-# now we install grub into the future EFI partition
-/usr/sbin/grub-install --verbose --no-floppy --efi-directory=/boot --removable 
--skip-fs-probe \
-       --no-nvram --no-bootsector --target=x86_64-efi || die "grub-install 
failed"

Reply via email to