From 3addb104cebb710e57bca0f955dff035b8b33f2a Mon Sep 17 00:00:00 2001 From: fernao Date: Sat, 1 Jul 2023 23:36:23 -0300 Subject: [PATCH] Update 'etc-init.d-swapfile' --- etc-init.d-swapfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/etc-init.d-swapfile b/etc-init.d-swapfile index b5f9773..24980a5 100644 --- a/etc-init.d-swapfile +++ b/etc-init.d-swapfile @@ -8,7 +8,8 @@ EXTRA_COMMANDS="status create" EXTRA_HELP=" status Check service status create Create a swapfile" -SWPATH="/mnt/routerdata/swapfile" +# default value, it'd be better to use other place than overlay +SWPATH="/overlay/swapfile" boot() { if [ -f $SWPATH ]; then @@ -56,7 +57,11 @@ stop() { create() { RAMTOTAL=`fgrep MemTotal /proc/meminfo | awk '{print $2}'` SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'` - if [ $SWAPTOTAL != 0 ]; then + OVERLAYSIZE=`df | grep overlayfs | awk '{print $3}'` + if [ $OVERLAYSIZE < $RAMTOTAL ]; then + echo "ERROR: Not enough storage for a swapfile, quitting..." + exit 1 + elif [ $SWAPTOTAL != 0 ]; then echo "ERROR: Swap already in use, quitting..." else dd if=/dev/zero of=$SWFILE bs=1024 count=$RAMTOTAL