util-linux-ng: add support for handling swap partitions to init

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2010-11-19 00:17:34 +01:00
parent 30542200df
commit 30ff848faa

View File

@ -28,27 +28,29 @@
. /etc/profile . /etc/profile
INSTALLED_MEMORY=`cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}'` INSTALLED_MEMORY=`cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}'`
SWAP=`blkid -t TYPE="swap" -o device`
SWAPFILE="$HOME/.cache/swapfile"
if [ $INSTALLED_MEMORY -le 500000 -a -f $HOME/.config/swapon ]; then if [ $INSTALLED_MEMORY -le 500000 ]; then
if [ -z "$SWAP" -a ! -f $SWAPFILE ]; then
if [ ! -f $HOME/.cache/swapfile ]; then
progress "creating swapfile" progress "creating swapfile"
mkdir -p $HOME/.cache
mkdir -p $HOME/.cache dd if=/dev/zero of=$SWAPFILE bs=1024 count=262144 2>&1 > /dev/null
dd if=/dev/zero of=$HOME/.cache/swapfile bs=1024 count=524288 2>&1 > /dev/null mkswap $SWAPFILE 2>&1 > /dev/null
mkswap $HOME/.cache/swapfile 2>&1 > /dev/null
fi fi
progress "enable swapfile" progress "enable swap"
swapon -p 10000 $HOME/.cache/swapfile [ -z "$SWAP" -a -f $SWAPFILE ] && SWAP=$SWAPFILE
for i in $SWAP; do
[ $INSTALLED_MEMORY -le 260000 ] \ swapon -p 10000 $SWAP 2>&1 > /dev/null
&& sysctl -w vm.swappiness=100 2>&1 > /dev/null \ done
|| sysctl -w vm.swappiness=60 2>&1 > /dev/null
if [ $INSTALLED_MEMORY -le 260000 ]; then
sysctl -w vm.swappiness=100 2>&1 > /dev/null
else
sysctl -w vm.swappiness=60 2>&1 > /dev/null
fi
else else
sysctl -w vm.swappiness=0 2>&1 > /dev/null sysctl -w vm.swappiness=0 2>&1 > /dev/null
fi fi