summaryrefslogtreecommitdiffstats
path: root/modules.d/99img-lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 14:01:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 14:01:35 +0000
commite6f2eaf47a177a8eca054d1d70a1b6287e8c3521 (patch)
treec5719e819a9e37df4b54affd61438f382ec38a8f /modules.d/99img-lib
parentAdding upstream version 060+5. (diff)
downloaddracut-e6f2eaf47a177a8eca054d1d70a1b6287e8c3521.tar.xz
dracut-e6f2eaf47a177a8eca054d1d70a1b6287e8c3521.zip
Adding upstream version 102.upstream/102
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules.d/99img-lib')
-rwxr-xr-xmodules.d/99img-lib/img-lib.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/modules.d/99img-lib/img-lib.sh b/modules.d/99img-lib/img-lib.sh
index 4700832..efc6475 100755
--- a/modules.d/99img-lib/img-lib.sh
+++ b/modules.d/99img-lib/img-lib.sh
@@ -106,3 +106,37 @@ unpack_img() {
}
fi
}
+
+# parameter: <size of live image> in MiB
+# Call emergency shell if ram size is too small for the image.
+# Increase /run tmpfs size, if needed.
+check_live_ram() {
+ local minmem imgsize memsize runsize runavail
+ minmem=$(getarg rd.minmem)
+ imgsize=$1
+ memsize=$(($(check_meminfo MemTotal:) >> 10))
+ # shellcheck disable=SC2046
+ set -- $(findmnt -bnro SIZE,AVAIL /run)
+ # bytes to MiB
+ runsize=$(($1 >> 20))
+ runavail=$(($2 >> 20))
+
+ [ "$imgsize" ] || {
+ warn "Image size could not be determined"
+ return 0
+ }
+
+ if [ $((memsize - imgsize)) -lt "${minmem:=1024}" ]; then
+ sed -i "N;/and attach it to a bug report./s/echo$/echo\n\
+ echo \n\
+ echo 'Warning!!!'\n\
+ echo 'The memory size of your system is too small for this live image.'\n\
+ echo 'Expect killed processes due to out of memory conditions.'\n\
+ echo \n/" /usr/bin/dracut-emergency
+
+ emergency_shell
+ elif [ $((runavail - imgsize)) -lt "$minmem" ]; then
+ # Increase /run tmpfs size, if needed.
+ mount -o remount,size=$((runsize - runavail + imgsize + minmem))M /run
+ fi
+}