2 # Filename: grml-swapon
3 # Purpose: activate swap partitions with taking care of suspend signatures
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 set -e # exit on any error
11 . /etc/grml/script-functions
12 . /etc/grml/lsb-functions
13 . /etc/grml/autoconfig.functions
16 check4progs dd blkid swapon || exit 2
18 checkbootparam "anyswap" && export ANYSWAP='yes' || export ANYSWAP=""
25 ewarn 'grml-swapon: activate swap partitions defined in /etc/fstab'
27 ewarn 'Usage: grml-swapon [--help|-h] [--force]'
28 ewarn 'Tip: execute grml-rebuildfstab for rebuilding /etc/fstab'
34 einfo "Searching for swap partition(s) as requested."
37 [ -n "$ANYSWAP" ] && einfo "Option --force set, forcing usage of swap partitions."
39 while read p m f relax; do
40 case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
41 partoptions="users,exec"
44 case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
45 S1SUSP|S2SUSP|pmdisk|[zZ]*)
46 if [ -n "$ANYSWAP" ] ; then
47 einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
48 swapon $p 2>>$DEBUG ; eend $?
50 ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. Force usage via option: --force"
54 if [[ "$p" == LABEL* ]] ; then
55 p=$(blkid -t $p | awk -F: '{print $1}')
57 if grep -q $p /proc/swaps ; then
58 ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
60 einfo "Using swap partition ${WHITE}${p}${NORMAL}."
61 swapon $p 2>>$DEBUG ; eend $?