Talk:Swap on microSD

SDCard Partition Methods Thread

Contents

Talk on Dual SD Swap Method

See from post 67 - sixwheeledbeast

Swap Switching Scripts

Latest Version - 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