]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - modules.d/99base/dracut-lib.sh
feat(livenet): add memory size check depending on live image size
[thirdparty/dracut.git] / modules.d / 99base / dracut-lib.sh
index 6eaa0fe1497d5e73cf276013737b1397dcfb2568..a8ca2c96eb747d3574dc157f7a68d7011be69ebf 100755 (executable)
@@ -1151,3 +1151,28 @@ load_fstype() {
     done < /proc/filesystems
     modprobe "$1"
 }
+
+# parameter: size of live image
+# calls emergency shell if ram size is too small for the image
+check_live_ram() {
+    minmem=$(getarg rd.minmem)
+    minmem=${minmem:-1024}
+    imgsize=$1
+    memsize=$(($(sed -n 's/MemTotal: *\([[:digit:]]*\).*/\1/p' /proc/meminfo) / 1024))
+
+    if [ -z "$imgsize" ]; then
+        warn "Image size could not be determined"
+        return 0
+    fi
+
+    if [ $((memsize - imgsize)) -lt "$minmem" ]; 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
+    fi
+}