summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2020-08-14 13:52:23 +0200
committerJonathan Bauer2020-08-14 13:52:23 +0200
commit0ff82e4656f77afff96c861494aff596dfb9d832 (patch)
treeaf1deec568fabbbd377ae3bbd1aa0e8cd65fe610
parent[slx-network] use 'noname-' prefix for hostname fallback (diff)
downloadsystemd-init-0ff82e4656f77afff96c861494aff596dfb9d832.tar.gz
systemd-init-0ff82e4656f77afff96c861494aff596dfb9d832.tar.xz
systemd-init-0ff82e4656f77afff96c861494aff596dfb9d832.zip
[dnbd3-rootfs] only copy /run/initramfs if enough space
-rwxr-xr-xmodules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh22
1 files changed, 17 insertions, 5 deletions
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 aca83b8e..0cae2b35 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
@@ -3,11 +3,23 @@
type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
# Needed to be able to go back to dracut at system shutdown.
-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"
+# 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 \