diff options
author | Simon Rettberg | 2022-05-20 12:20:32 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-05-20 12:20:32 +0200 |
commit | 38169f5b1b3343d2867a9f01a7335a4ae14e58bb (patch) | |
tree | 2109c2ca8529ca7dc998a18c5f9ea9eed1b927ce /modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh | |
parent | dnbd3: workqueue branch has been merged into master (diff) | |
download | systemd-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
Diffstat (limited to 'modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh')
-rwxr-xr-x | modules.d/copy-initrd/hooks/copy-initramfs-into-newroot.sh | 23 |
1 files changed, 23 insertions, 0 deletions
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 + |