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 # Latest change: Son Nov 26 18:04:13 CET 2006 [mika]
8 ################################################################################
10 set -e # exit on any error
12 . /etc/grml/script-functions
13 . /etc/grml/lsb-functions
14 . /etc/grml/autoconfig.functions
17 check4progs dd blkid swapon || exit 2
19 checkbootparam "anyswap" && export ANYSWAP='yes' || export ANYSWAP=""
26 ewarn 'grml-swapon: activate swap partitions defined in /etc/fstab'
28 ewarn 'Usage: grml-swapon [--help|-h] [--force]'
29 ewarn 'Tip: execute grml-rebuildfstab for rebuilding /etc/fstab'
35 einfo "Searching for swap partition(s) as requested."
38 [ -n "$ANYSWAP" ] && einfo "Option --force set, forcing usage of swap partitions."
40 while read p m f relax; do
41 case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
42 partoptions="users,exec"
45 case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
46 S1SUSP|S2SUSP|pmdisk|[zZ]*)
47 if [ -n "$ANYSWAP" ] ; then
48 einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
49 swapon $p 2>>$DEBUG ; eend $?
51 ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. Force usage via option: --force"
55 if [[ "$p" == LABEL* ]] ; then
56 p=$(blkid -t $p | awk -F: '{print $1}')
58 if grep -q $p /proc/swaps ; then
59 ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
61 einfo "Using swap partition ${WHITE}${p}${NORMAL}."
62 swapon $p 2>>$DEBUG ; eend $?