Skip to content

Commit

Permalink
feat(livenet): add memory size check depending on live image size
Browse files Browse the repository at this point in the history
For writeable live images, the memory must hold the complete image.
That means it must be at least the size of the image plus some RAM
necessary to run processes.
With too small RAM, the OOM Killer steps in and makes the boot hang.
This patch lets the system go into the emergency shell instead.

The default minimum RAM after subtracting the live image size is set to 1G.
The parameter rd.minmem.liverw is added to modify this.
  • Loading branch information
tblume committed Jun 21, 2023
1 parent 7ed765d commit d8c954c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules.d/90livenet/livenetroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ netroot="$2"
liveurl="${netroot#livenet:}"
info "fetching $liveurl"

if getargbool 0 'rd.writable.fsimg'; then

minmem=$(getarg rd.minmem.liverw)
minmem=${minmem:-1024}

memsize=$(($(sed -n 's/MemTotal: *\([[:digit:]]*\).*/\1/p' /proc/meminfo) / 1024))
imgsize=$(($(curl -sI "$liveurl" | sed -n 's/Content-Length: *\([[:digit:]]*\).*/\1/p') / (1024 * 1024)))

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
fi

imgfile=
#retry until the imgfile is populated with data or the max retries
i=1
Expand Down

0 comments on commit d8c954c

Please sign in to comment.