Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: feat(livenet): add memory size check depending on live image size #2344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions man/dracut.cmdline.7.asc
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,13 @@ NOTE: There must be enough free RAM available to hold the complete image.
+
This method is very suitable for diskless boots.

**rd.minmem=**__<megabyte>__::
Specify minimum free RAM in MB after copying a live disk image into memory.
The default is 1024.
+
This parameter only applies together with the parameters rd.writable.fsimg
or rd.live.ram.

**root=**live:__<url>__::
Boots a live image retrieved from __<url>__. Requires the dracut 'livenet'
module. Valid handlers: __http, https, ftp, torrent, tftp__.
Expand Down
2 changes: 2 additions & 0 deletions modules.d/90dmsquash-live/dmsquash-live-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then
fi
if [ -e "$SQUASHED" ]; then
if [ -n "$live_ram" ]; then
imgsize=$(($(stat -c %s -- $SQUASHED) / (1024 * 1024)))
check_live_ram $imgsize
echo 'Copying live image to RAM...' > /dev/kmsg
echo ' (this may take a minute)' > /dev/kmsg
dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null
Expand Down
7 changes: 7 additions & 0 deletions modules.d/90livenet/livenetroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ netroot="$2"
liveurl="${netroot#livenet:}"
info "fetching $liveurl"

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

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

check_live_ram $imgsize
fi

imgfile=
#retry until the imgfile is populated with data or the max retries
i=1
Expand Down
25 changes: 25 additions & 0 deletions modules.d/99base/dracut-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading