From 54933050545f6e6dc9e8e7bd3cd206139f56d459 Mon Sep 17 00:00:00 2001 From: Matej Matuska Date: Wed, 7 Dec 2022 21:50:48 +0100 Subject: [PATCH 1/2] Add leapp debug tools to initramfs Install a script with debug utilities to the Leapp upgrade dracut module. --- .../dracut/90sys-upgrade/leapp_debug_tools.sh | 38 +++++++++++++++++++ .../dracut/90sys-upgrade/module-setup.sh | 2 + 2 files changed, 40 insertions(+) create mode 100644 repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh new file mode 100644 index 0000000000..91c228ced9 --- /dev/null +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh @@ -0,0 +1,38 @@ +# library containing some useful functions for debugging in initramfs + +# mounts the sysroot +leapp_dbg_mount() { + systemctl start sysroot.mount + mount -o remount,rw /sysroot +} + +# source programs from $NEWROOT, mount if not mounted +leapp_dbg_source() { + systemctl is-active sysroot.mount --quiet || { + echo "sysroot not mounted, mounting..."; + leapp_dbg_mount || return 1 + } + + for dir in /bin /sbin; do + export PATH="$PATH:${NEWROOT}$dir" + done + + export LD_LIBRARY_PATH=/sysroot/lib64 +} + +# chroot into $NEWROOT +leapp_dbg_chroot() { + systemctl is-active sysroot.mount --quiet || { + echo "sysroot not mounted, mounting..."; + leapp_dbg_mount || return 1 + } + + for dir in /sys /run /proc /dev /dev/pts; do + mount --bind $dir "$NEWROOT$dir" + done || { echo "Failed to mount some directories" || return 1 } + + chroot $NEWROOT sh -c "mount -a; /bin/bash" + for dir in /sys /run /proc /dev/pts /dev; do + umount $NEWROOT$dir + done +} diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh index d38617db00..a9cfffb416 100755 --- a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh @@ -72,6 +72,8 @@ install() { inst_script "${_moddir}/initrd-system-upgrade-generator" \ "${generatordir}/initrd-system-upgrade-generator" + inst_script "${_moddir}/leapp_debug_tools.sh" "/bin/leapp_debug_tools.sh" + ## upgrade shell service #sysinit_wantsdir="${_initdir}${unitdir}/sysinit.target.wants" #mkdir -p "$sysinit_wantsdir" From 8876f5fecd1e3fda8442f1a8a161448a4a2d253e Mon Sep 17 00:00:00 2001 From: Matej Matuska Date: Tue, 20 Dec 2022 12:25:48 +0100 Subject: [PATCH 2/2] Add autosourcing --- .../files/dracut/90sys-upgrade/.profile | 9 +++++++++ .../files/dracut/90sys-upgrade/.shrc | 4 ++++ .../files/dracut/90sys-upgrade/leapp_debug_tools.sh | 9 ++++++--- .../files/dracut/90sys-upgrade/module-setup.sh | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.profile create mode 100644 repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.shrc diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.profile b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.profile new file mode 100644 index 0000000000..c4fe05a750 --- /dev/null +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.profile @@ -0,0 +1,9 @@ +#!/bin/sh +# script read at startup by login shells +# in the initramfs this is read for example by the emergency shell + +# set the environment file, containing shell commands to execute at startup of +# interactive shells +if [ -f "$HOME/.shrc" ]; then + ENV="$HOME/.shrc"; export ENV +fi diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.shrc b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.shrc new file mode 100644 index 0000000000..5e965f4787 --- /dev/null +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/.shrc @@ -0,0 +1,4 @@ +#!/bin/sh + +# shell commands to execute on interactive shell startup +. leapp_debug_tools.sh diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh index 91c228ced9..5878b75b57 100644 --- a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/leapp_debug_tools.sh @@ -1,3 +1,4 @@ +#!/bin/sh # library containing some useful functions for debugging in initramfs # mounts the sysroot @@ -29,10 +30,12 @@ leapp_dbg_chroot() { for dir in /sys /run /proc /dev /dev/pts; do mount --bind $dir "$NEWROOT$dir" - done || { echo "Failed to mount some directories" || return 1 } + done || { + echo "Failed to mount some directories" || return 1 + } - chroot $NEWROOT sh -c "mount -a; /bin/bash" + chroot "$NEWROOT" sh -c "mount -a; /bin/bash" for dir in /sys /run /proc /dev/pts /dev; do - umount $NEWROOT$dir + umount "$NEWROOT$dir" done } diff --git a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh index a9cfffb416..06479fb515 100755 --- a/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh +++ b/repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/module-setup.sh @@ -73,6 +73,8 @@ install() { "${generatordir}/initrd-system-upgrade-generator" inst_script "${_moddir}/leapp_debug_tools.sh" "/bin/leapp_debug_tools.sh" + inst_script "${_moddir}/.profile" "/.profile" + inst_script "${_moddir}/.shrc" "/.shrc" ## upgrade shell service #sysinit_wantsdir="${_initdir}${unitdir}/sysinit.target.wants"