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

fix(check_live_ram): increase /run tmpfs size if needed #2551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 12 additions & 25 deletions modules.d/99base/dracut-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,18 @@ show_memstats() {
esac
}

# parameter: <memory_name:> example: MemTotal:
# Check /proc/meminfo
# echo the field value, if present.
check_meminfo() {
local - m sz
set +x
while read -r m sz _ || [ "$m" ]; do
[ "$m" = "$1" ] && echo "$sz" && return 0
done < /proc/meminfo
return 1
}

remove_hostonly_files() {
rm -fr /etc/cmdline /etc/cmdline.d/*.conf "$hookdir/initqueue/finished"
if [ -f /lib/dracut/hostonly-files ]; then
Expand All @@ -1151,28 +1163,3 @@ 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
}
34 changes: 34 additions & 0 deletions modules.d/99img-lib/img-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading