Talk:Swap on microSD
(→Best Homemade Sites: new section) |
m (Reverted edits by 113.160.219.210 (Talk) to last revision by sixwheeledbeast) |
||
| Line 424: | Line 424: | ||
This script can be modified to suit different swap locations as required. | This script can be modified to suit different swap locations as required. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
Revision as of 09:18, 8 April 2019
SDCard Partition Methods Thread
Contents |
Talk on Dual SD Swap Method
See from post 67 - sixwheeledbeast
Swap Switching Scripts
Latest Version - sixwheeledbeast
Now uses "EOF gainroot" script, although this causes multiple banner messages in the ejectsd script, not sure how to fix. The first switching script works perfectly and fixes the multiple swapping due to a reorder.
swapswitch.sh
#!/bin/sh
#Made by sixwheeledbeast, Estel, Malkavian, peterleinchen and vi_
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
echo $swap0
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
echo $swap1
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
echo $swap2
# Go root if not
if [ `id -u` != 0 ] ; then
exec | sudo gainroot <<EOF
exec sh $0 $*
EOF
exit $?
fi
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
# Get and Print Current Swap Pre
swap=`cat /proc/swaps | awk '/dev/ {print $1}'`
echo $swap
banner "$swap"
sleep 5
#Logic
if [ "$swap" = "$swap1" ] ;
then
nice -20 swapon $swap2
nice -20 swapoff $swap1
elif [ "$swap" = "$swap2" ] ;
then
nice -20 swapon $swap1
nice -20 swapoff $swap2
elif [ "$swap" = "$swap0" ] ;
then
nice -20 swapon $swap1
nice -20 swapoff $swap0
sleep 5
# Get and Print Current Swap Post
swappost=`cat /proc/swaps | awk '/dev/ {print $1}'`
banner "$swappost" && exit 1
else
banner "Swap Switch Failed" && exit 1
fi
#End of Logic
swapswitchejectsd.sh
#!/bin/sh
##Made by sixwheeledbeast, Estel, Malkavian, peterleinchen and vi_
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
# Get and Print Current Swap Pre
preswap=`cat /proc/swaps | awk '/dev/ {print $1}'`
banner "$preswap"
sleep 5
#Logic
if [ "$preswap" = "$swap0" ];
then
banner "Swap on Internal already" && exit 1
elif [ "$preswap" = "$swap1" ];
then
# Go root if not
if [ `id -u` != 0 ] ; then
exec | sudo gainroot <<EOF
exec sh $0 $*
EOF
exit $?
fi
nice -20 swapon $swap0
nice -20 swapoff $swap1
sleep 3
swappostswitchone=`cat /proc/swaps | awk '/dev/ {print $1}'`
banner "$swappostswitchone"
sleep 2
banner "Safe to remove back cover" && exit
elif [ "$preswap" = "$swap2" ];
then
# Go root if not
if [ `id -u` != 0 ] ; then
exec | sudo gainroot <<EOF
exec sh $0 $*
EOF
exit $?
fi
nice -20 swapon $swap0
nice -20 swapoff $swap2
swappostswitchtwo=`cat /proc/swaps | awk '/dev/ {print $1}'`
banner "$swappostswitchtwo"
sleep 2
banner "Safe to remove back cover" && exit
else
banner "Swap Switch Failed"
sleep 2
banner "DO NOT REMOVE BACK COVER - Please check swaps manually via terminal" && exit 2
fi
Version 1 - sixwheeledbeast
swapswitch.sh
#!/bin/sh
# Made by sixwheeledbeast, Malkavian, Estel and vi_
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
echo $swap0
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
echo $swap1
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
echo $swap2
# Get Current Swap
swap=`cat /proc/swaps | awk '/dev/ {print $1}'`
echo $swap
# Go root
s=sudo
echo $sudo
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
#Print Current Swap Pre
banner "$swap"
sleep 5
#Logic
if [ "$swap" = "$swap1" ] ;
then
nice -20 $s swapon $swap2
nice -20 $s swapoff $swap1
elif [ "$swap" = "$swap2" ] ;
then
nice -20 $s swapon $swap1
nice -20 $s swapoff $swap2
elif [ "$swap" = "$swap0" ] ;
then
nice -20 $s swapon $swap1
nice -20 $s swapoff $swap0
else
banner "Swap Switch Failed"
fi
sleep 5
# Get Current Swap
swappost=`cat /proc/swaps | awk '/dev/ {print $1}'`
echo $swappost
#Print Current Swap Post
banner "$swappost"
swapswitchejectsd.sh
#!/bin/sh
# Made by sixwheeledbeast, Malkavian, Estel and vi_
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
# Get Current Swap
swap=`cat /proc/swaps | awk '/dev/ {print $1}'`
echo $swap
# Go root
s=sudo
echo $sudo
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
#Print Current Swap Pre
banner "$swap"
sleep 5
#Logic
if [ "$swap" = "$swap0" ]
then
banner "Swap on Internal already!"
elif [ "$swap" = "$swap1" ]
then
nice -20 $s swapon $swap0
nice -20 $s swapoff $swap1
elif [ "$swap" = "$swap2" ]
then
nice -20 $s swapon $swap0
nice -20 $s swapoff $swap2
else
banner "Swap Switch Failed"
fi
sleep 5
# Get Current Swap
swappost=`cat /proc/swaps | awk '/dev/ {print $1}'`
echo $swappost
if [ "$swappost" = "$swap0" ]
then
banner "Safe to remove back cover"
else
sleep 2
banner "ERROR! DO NOT REMOVE BACK COVER"
sleep 3
#Print Current Swap Post
banner "$swappost"
fi
Version 1 - Malkavian
swapswitch.sh
#!/bin/sh
# Made by Sixwheeledbeast and Malkavian
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
# Get Current Swap
old=`cat /proc/swaps | awk '/dev/ {print $1}'`
#Logic
if [ "$old" = "$swap0" ]
then if [ $RANDOM -lt 16384 ] # RANDOM gives a value from 0 to 32787. We try 50% of probabilities
then new="$swap1"
else new="$swap2"
fi
elif [ "$old" = "$swap1" ]
then new="$swap2"
elif [ "$old" = "$swap2" ]
then new="$swap1"
else banner "None of the configured swaps found active, revise the configuration. Current active swap (if any): $old"
exit 1
fi
swapon $new || \
( banner "Ops, something failed, cannot swapon $new (so swapoff of $old neither done)" && exit 1 )
nice -20 swapoff $old || \
( banner "Ops, something failed, swapon of $new done but cannot swapoff $old" && exit 1 )
banner "OK: Swap switched from $old to $new"
swapscriptejectsd.sh
#!/bin/sh
# Made by Sixwheeledbeast and Malkavian
# Setup swap names for script
## Swap 0 - Backup internal swap location
swap0=/dev/mmcblk0p3
## Swap 1 - First Main Swap Location
swap1=/dev/mmcblk1p2
## Swap 2 - Second Main Swap Location
swap2=/dev/mmcblk1p3
# Setup notification banner
banner(){
o=org
f=freedesktop
n=Notifications
run-standalone.sh dbus-send --type=method_call \
--dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1"
}
# Get Current Swap
old=`cat /proc/swaps | awk '/dev/ {print $1}'`
#Logic
if [ "$old" = "$swap0" ]
then banner "Swap on Internal already!"
exit 0
else swapon $swap0 || \
( banner "Ops, something failed, cannot swapon $swap0 (so swapoff of $old neither done)" && exit 1 )
nice -20 swapoff $old || \
( banner "Ops, something failed, swapon of $swap0 done but cannot swapoff $old" && exit 1 )
fi
Information on Starting Swap on SD at bootup
Upstart format - new file in event.d
etc/event.d/relocateswap
description "Micro SD Swap Location on Startup"
author "sixwheeledbeast"
console output
start on started rcS-late
script
swapon /dev/mmcblk1p2
sleep 10
swapoff /dev/mmcblk0p3
end script
Original script from main page
This script can be run via Terminal or using an application like Queen BeeCon Widget.
It is for refreshing swap if main swap space is on Micro SD Partition 2.
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Start Swap Refresh" uint32:0 string:"OK"; sudo swapon /dev/mmcblk0p3 ; sudo swapoff /dev/mmcblk1p2 ; run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Swapping Back to Main Swap on SD..." ; sudo swapon /dev/mmcblk1p2 ; sudo swapoff /dev/mmcblk0p3 ; run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Swap Refresh Complete" uint32:0 string:"OK"
This script can be modified to suit different swap locations as required.
