summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-20 12:20:32 +0200
committerSimon Rettberg2022-05-20 12:20:32 +0200
commit38169f5b1b3343d2867a9f01a7335a4ae14e58bb (patch)
tree2109c2ca8529ca7dc998a18c5f9ea9eed1b927ce
parentdnbd3: workqueue branch has been merged into master (diff)
downloadsystemd-init-38169f5b1b3343d2867a9f01a7335a4ae14e58bb.tar.gz
systemd-init-38169f5b1b3343d2867a9f01a7335a4ae14e58bb.tar.xz
systemd-init-38169f5b1b3343d2867a9f01a7335a4ae14e58bb.zip
Split initramfs copying logic into new module, enable in debug mode only
-rwxr-xr-xbuild-initramfs.sh2
-rwxr-xr-xmodules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh23
-rwxr-xr-xmodules.d/copy-initrd/module-setup.sh12
-rwxr-xr-xmodules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh47
-rwxr-xr-xmodules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh6
5 files changed, 53 insertions, 37 deletions
diff --git a/build-initramfs.sh b/build-initramfs.sh
index 244b4d42..d5843f15 100755
--- a/build-initramfs.sh
+++ b/build-initramfs.sh
@@ -471,7 +471,7 @@ main() {
fi
if [ "$debug" = "yes" ]; then
dracut_parameters+=("--stdlog" "4")
- dracut_modules+=(i18n terminfo)
+ dracut_modules+=(i18n terminfo copy-initrd)
fi
# Initialize and exit if we are only preparing the build environment
diff --git a/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh b/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh
new file mode 100755
index 00000000..cdb3f50a
--- /dev/null
+++ b/modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+# -*- coding: utf-8 -*-
+type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
+
+# Needed to be able to go back to dracut at system shutdown.
+# only do this if there is enough space in /run since systemd decided to limit
+# some tmpfs to 10% of the memory size breaking the system with low memory...
+# See: https://github.com/systemd/systemd/commit/b67ec8e5b2e1a74d7e9a3a2b3ac60b7b2e39d4ea
+_run_size_kb="$(slx-tools fs_path_space /run | cut -d' ' -f2)"
+_initrd_block_size="$( stat -f / -c%S)"
+_initrd_total_blocks="$(stat -f / -c%b)"
+_initrd_free_blocks="$(stat -f / -c%a)"
+_initrd_used_blocks="$(( _initrd_total_blocks - _initrd_free_blocks ))"
+_initrd_size_kb="$(( ( _initrd_used_blocks * _initrd_block_size ) / 1024 ))"
+if [ "$(( _run_size_kb - _initrd_size_kb ))" -ge "200000" ]; then
+ # more than 200MB space, should be safe to copy initramfs over
+ temporary_directory_path="$(mktemp --directory)"
+ mount --options bind / "$temporary_directory_path"
+ cp --recursive --no-target-directory "$temporary_directory_path" /run/initramfs
+ umount "$temporary_directory_path"
+ rm --dir "$temporary_directory_path"
+fi
+
diff --git a/modules.d/copy-initrd/module-setup.sh b/modules.d/copy-initrd/module-setup.sh
new file mode 100755
index 00000000..050a84e3
--- /dev/null
+++ b/modules.d/copy-initrd/module-setup.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+check() {
+ # only if requested
+ return 255
+}
+depends() {
+ echo base bash
+}
+install() {
+ inst_hook pre-pivot 00 \
+ "$moddir/hooks/copy-initramfs-into-newroot.sh"
+}
diff --git a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
index 0cae2b35..d0e847ca 100755
--- a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
+++ b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
@@ -2,25 +2,6 @@
# -*- coding: utf-8 -*-
type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
-# Needed to be able to go back to dracut at system shutdown.
-# only do this if there is enough space in /run since systemd decided to limit
-# some tmpfs to 10% of the memory size breaking the system with low memory...
-# See: https://github.com/systemd/systemd/commit/b67ec8e5b2e1a74d7e9a3a2b3ac60b7b2e39d4ea
-_run_size_kb="$(slx-tools fs_path_space /run | cut -d' ' -f2)"
-_initrd_block_size="$( stat -f / -c%S)"
-_initrd_total_blocks="$(stat -f / -c%b)"
-_initrd_free_blocks="$(stat -f / -c%a)"
-_initrd_used_blocks="$(( _initrd_total_blocks - _initrd_free_blocks ))"
-_initrd_size_kb="$(( ( _initrd_used_blocks * _initrd_block_size ) / 1024 ))"
-if [ "$(( _run_size_kb - _initrd_size_kb ))" -ge "200000" ]; then
- # more than 200MB space, should be safe to copy initramfs over
- temporary_directory_path="$(mktemp --directory)"
- mount --options bind / "$temporary_directory_path"
- cp --recursive --no-target-directory "$temporary_directory_path" /run/initramfs
- umount "$temporary_directory_path"
- rm --dir "$temporary_directory_path"
-fi
-
# Dracut may not be installed on the new root. Thus copy all services over.
dracut_mount_unit_path="$(systemctl show -p FragmentPath dracut-mount.service \
| cut -c 14-)"
@@ -29,19 +10,19 @@ new_systemd_system_unit_path="${NEWROOT}/lib/systemd/system"
mkdir --parents "$new_systemd_system_unit_path/initrd.target.wants"
for file in \
- dracut-cmdline.service \
- dracut-initqueue.service \
- dracut-mount.service \
- dracut-pre-mount.service \
- dracut-pre-pivot.service \
- dracut-pre-trigger.service \
- dracut-pre-udev.service
+ dracut-cmdline.service \
+ dracut-initqueue.service \
+ dracut-mount.service \
+ dracut-pre-mount.service \
+ dracut-pre-pivot.service \
+ dracut-pre-trigger.service \
+ dracut-pre-udev.service
do
- cp "${systemd_system_unit_path}/${file}" \
- "${new_systemd_system_unit_path}/${file}"
- # "ln" returns an error if the link already exists.
- source_path="../${file}"
- target_path="${new_systemd_system_unit_path}/initrd.target.wants/${file}"
- ln --symbolic "$source_path" "$target_path" &>/dev/null || \
- warn "Failed to link \"$source_path\" to \"$target_path\"."
+ cp "${systemd_system_unit_path}/${file}" \
+ "${new_systemd_system_unit_path}/${file}"
+ # "ln" returns an error if the link already exists.
+ source_path="../${file}"
+ target_path="${new_systemd_system_unit_path}/initrd.target.wants/${file}"
+ ln --symbolic "$source_path" "$target_path" &>/dev/null || \
+ warn "Failed to link \"$source_path\" to \"$target_path\"."
done
diff --git a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh
index ff01474f..1d601a22 100755
--- a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh
+++ b/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh
@@ -11,8 +11,8 @@ cat "/run/openslx/network.conf" >> "${NEWROOT}/opt/openslx/config"
# Set root/demo password for stage4, if set
if [ -n "${SLX_ROOT_PASS}" ]; then
- sed -i "s#^root:[^:]*:#root:$SLX_ROOT_PASS:#" $NEWROOT/etc/shadow
+ sed -i "s#^root:[^:]*:#root:$SLX_ROOT_PASS:#" "$NEWROOT/etc/shadow"
fi
-if [ -n "${SLX_DEMO_PASS}" ] && grep -q '^demo' $NEWROOT/etc/shadow; then
- sed -i "s#^demo:[^:]*:#demo:$SLX_DEMO_PASS:#" $NEWROOT/etc/shadow
+if [ -n "${SLX_DEMO_PASS}" ] && grep -q '^demo' "$NEWROOT/etc/shadow"; then
+ sed -i "s#^demo:[^:]*:#demo:$SLX_DEMO_PASS:#" "$NEWROOT/etc/shadow"
fi