commit: 5ac6234f0932bd10acd1d0d64faf262a9d312771
Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 12 16:29:35 2024 +0000
Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Oct 12 16:29:35 2024 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=5ac6234f
For chrooting into the mount point, add a lot of NIH
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
targets/support/create-qcow2.sh | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/targets/support/create-qcow2.sh b/targets/support/create-qcow2.sh
index b41d635a..dfc1309a 100755
--- a/targets/support/create-qcow2.sh
+++ b/targets/support/create-qcow2.sh
@@ -41,7 +41,13 @@ mydevice=/dev/nbd0
# from the moment on when the nbd was set up...
qcow2die() {
echo "Something went wrong. Cleaning up..."
+
# here we just ignore errors
+ umount "${mymountpoint}/proc"
+ umount "${mymountpoint}/sys"
+ umount "${mymountpoint}/dev"
+ umount "${mymountpoint}/run"
+
umount "${mydevice}p1"
umount "${mydevice}p2"
qemu-nbd -d "${mydevice}"
@@ -50,23 +56,39 @@ qcow2die() {
}
# We need a means to execute a script inside the qcow with filesystems mounted
+# Which means reproducing half of catalyst here.
exec_in_qcow2() {
local file_name=$(basename ${1})
+ # prepare qcow2 for chrooting
+ mount --types proc /proc "${mymountpoint}/proc"
+ mount --rbind /sys "${mymountpoint}/sys"
+ mount --make-rslave "${mymountpoint}/sys"
+ mount --rbind /dev "${mymountpoint}/dev"
+ mount --make-rslave "${mymountpoint}/dev"
+ mount --bind /run "${mymountpoint}/run"
+ mount --make-slave "${mymountpoint}/run"
+
# copy_to_chroot ${1}
- cp -pPR "${1}" "${mymountpoint}/tmp" || die
+ cp -pPR "${1}" "${mymountpoint}/tmp" || qcow2die
# copy_to_chroot ${clst_shdir}/support/chroot-functions.sh
- cp -pPR "${clst_shdir}/support/chroot-functions.sh"
"${mymountpoint}/tmp" || die
+ cp -pPR "${clst_shdir}/support/chroot-functions.sh"
"${mymountpoint}/tmp" || qcow2die
# Ensure the file has the executable bit set
- chmod +x "${mymountpoint}/tmp/${file_name}" || die
+ chmod +x "${mymountpoint}/tmp/${file_name}" || qcow2die
echo "Running ${file_name} in qcow2:"
echo " ${clst_CHROOT} ${mymountpoint} /tmp/${file_name}"
- ${clst_CHROOT} "${mymountpoint}" "/tmp/${file_name}" || exit 1
+ ${clst_CHROOT} "${mymountpoint}" "/tmp/${file_name}" || qcow2die
+
+ rm -f "${mymountpoint}/tmp/${file_name}" || qcow2die
+ rm -f "${mymountpoint}/tmp/chroot-functions.sh" || qcow2die
- rm -f "${mymountpoint}/tmp/${file_name}" || die
- rm -f "${mymountpoint}/tmp/chroot-functions.sh" || die
+ # cleanup qcow2 dir
+ umount "${mymountpoint}/proc" || qcow2die
+ umount "${mymountpoint}/sys" || qcow2die
+ umount "${mymountpoint}/dev" || qcow2die
+ umount "${mymountpoint}/run" || qcow2die
}