Update 'etc-init.d-swapfile'
This commit is contained in:
parent
3addb104ce
commit
60acce89ee
@ -1,14 +1,20 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# (C) 2016 - 2023 Fernao Vellozo
|
# (C) 2016 - 2023 Fernao Vellozo | fernao@disroot.org
|
||||||
# This is free software under the terms of GPLv3
|
# This is free software under the terms of GPLv3
|
||||||
|
# v 1.0.5
|
||||||
|
|
||||||
|
# Service priority in the system
|
||||||
START=90
|
START=90
|
||||||
|
|
||||||
EXTRA_COMMANDS="status create"
|
EXTRA_COMMANDS="status create"
|
||||||
EXTRA_HELP=" status Check service status
|
EXTRA_HELP=" status Check service status
|
||||||
create Create a swapfile"
|
create Create a swapfile"
|
||||||
|
# if version is 19 or lower, use spaces on the help menu above
|
||||||
|
# if version 21 or higher, use tabs
|
||||||
|
#
|
||||||
|
# overlay partition is the default value
|
||||||
|
# it's better to change it and use other place to store the swapfile
|
||||||
|
|
||||||
# default value, it'd be better to use other place than overlay
|
|
||||||
SWPATH="/overlay/swapfile"
|
SWPATH="/overlay/swapfile"
|
||||||
|
|
||||||
boot() {
|
boot() {
|
||||||
@ -57,19 +63,28 @@ stop() {
|
|||||||
create() {
|
create() {
|
||||||
RAMTOTAL=`fgrep MemTotal /proc/meminfo | awk '{print $2}'`
|
RAMTOTAL=`fgrep MemTotal /proc/meminfo | awk '{print $2}'`
|
||||||
SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'`
|
SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'`
|
||||||
OVERLAYSIZE=`df | grep overlayfs | awk '{print $3}'`
|
OVERLAYSIZE=`df | grep overlayfs | awk '{print $4}'`
|
||||||
if [ $OVERLAYSIZE < $RAMTOTAL ]; then
|
|
||||||
|
if [ "$OVERLAYSIZE" -lt "$RAMTOTAL" ]; then
|
||||||
echo "ERROR: Not enough storage for a swapfile, quitting..."
|
echo "ERROR: Not enough storage for a swapfile, quitting..."
|
||||||
exit 1
|
exit 1
|
||||||
elif [ $SWAPTOTAL != 0 ]; then
|
elif [ $SWAPTOTAL != 0 ]; then
|
||||||
echo "ERROR: Swap already in use, quitting..."
|
echo "ERROR: Swap already in use, quitting..."
|
||||||
|
exit 1
|
||||||
|
elif [ -f $SWPATH ]; then
|
||||||
|
echo "ERROR: File already exists, quitting..."
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
dd if=/dev/zero of=$SWFILE bs=1024 count=$RAMTOTAL
|
echo "Creating Swap File of "$RAMTOTAL
|
||||||
mkswap -L SWAPFILE $SWFILE
|
echo "Please wait..."
|
||||||
chmod 600 $SWFILE
|
dd if=/dev/zero of=$SWPATH bs=1024 count=$RAMTOTAL
|
||||||
|
mkswap -L SWAPFILE $SWPATH
|
||||||
|
chmod 600 $SWPATH
|
||||||
/etc/init.d/swapfile enable
|
/etc/init.d/swapfile enable
|
||||||
logger "SwapFile created"
|
logger "SwapFile created"
|
||||||
echo "SwapFile successfully created, enabled to run after the next reboot"
|
echo "SwapFile successfully created and enabled to run after the next reboot"
|
||||||
|
/etc/init.d/swapfile start
|
||||||
|
echo; free
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user