* Add script grml-swapon for activating swap partitions.
authorMichael Prokop <mika@grml.org>
Sun, 26 Nov 2006 17:13:51 +0000 (18:13 +0100)
committerMichael Prokop <mika@grml.org>
Sun, 26 Nov 2006 17:13:51 +0000 (18:13 +0100)
debian/changelog
debian/rules
manpages/grml-swapon.8 [new file with mode: 0644]
manpages/reread_partition_table.8
usr_sbin/grml-swapon [new file with mode: 0755]

index f2d5ef6..5dc6885 100644 (file)
@@ -1,3 +1,9 @@
+grml-scripts (0.8-32) unstable; urgency=low
+
+  * Add script grml-swapon for activating swap partitions.
+
+ -- Michael Prokop <mika@grml.org>  Sun, 26 Nov 2006 18:13:34 +0100
+
 grml-scripts (0.8-31) unstable; urgency=low
 
   * fma: use '-U' option for lzop as suggested by wuehlmaus in
index b71f2c2..47efcc4 100755 (executable)
@@ -54,7 +54,7 @@ binary-arch: build install
        dh_installchangelogs
        dh_installdocs
        dh_installman manpages/grml-scripts.1 manpages/grml-bind.8 manpages/reread_partition_table.8 manpages/gtf.1 manpages/random-hostname.1 \
-       manpages/grml-setkeyboard.8 manpages/grml-setlang.8 manpages/getsf.1 manpages/grml-iptstate.8 manpages/fma.1
+       manpages/grml-setkeyboard.8 manpages/grml-setlang.8 manpages/getsf.1 manpages/grml-iptstate.8 manpages/fma.1 manpages/grml-swapon.8
 #      cp --no-dereference man/*.1.gz debian/grml-scripts/usr/share/man/man1/
        dh_link /usr/sbin/blacklist /usr/sbin/unblacklist
        dh_link /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/align.1.gz
diff --git a/manpages/grml-swapon.8 b/manpages/grml-swapon.8
new file mode 100644 (file)
index 0000000..d71f0a5
--- /dev/null
@@ -0,0 +1,32 @@
+.TH grml-swapon 8
+.SH "NAME"
+grml\-swapon \- activate swap partitions with taking care of suspend signatures
+.SH SYNOPSIS
+.B grml\-swapon
+.RI [ OPTIONS ]
+.SH DESCRIPTION
+
+grml-swapon is a small script for enabling swap partitions found in /etc/fstab.
+Starting with grml 0.9 booting the live-cd system does not activate swap
+parititions by default anymore. It is possible to force usage of swap partitions
+via booting with the bootoption "swap". In case you forgot to use this
+bootoption but want to use swap partition(s) anyway you could do that by running
+"swapon -a". But the command "swapon" does not take of suspend signatures -
+therefore the existance of grml-swapon.  grml-swapon acts based on the
+information found in /etc/fstab. If your /etc/fstab is not up to date rebuild it
+running "grml-rebuildfstab".
+
+.SH OPTIONS
+.TP
+.B \-h, \-\-help
+Show help text.
+.TP
+.B \-\-force
+Force usage of swap partitions, activate them also if suspend signature is present.
+.SH SEE ALSO
+.BR grml-rebuildfstab (8).
+.SH AUTHOR
+grml-swapon was written by Michael Prokop <mika@grml.org>.
+.PP
+This manual page was written by Michael Prokop <mika@grml.org>
+for the grml project (but may be used by others).
index 72d7fda..f4b808e 100644 (file)
@@ -22,5 +22,5 @@ Reread partition table for disk /dev/hda.
 reread_partition_table was written by Michael Prokop
 <mika@grml.org>.
 .PP
-This manual page was written by Michael Prokop
-<mika@grml.org> for the Debian project (but may be used by others).
+This manual page was written by Michael Prokop <mika@grml.org>
+for the grml project (but may be used by others).
diff --git a/usr_sbin/grml-swapon b/usr_sbin/grml-swapon
new file mode 100755 (executable)
index 0000000..1235433
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/zsh
+# Filename:      grml-swapon
+# Purpose:       activate swap partitions with taking care of suspend signatures
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Bug-Reports:   see http://grml.org/bugs/
+# License:       This file is licensed under the GPL v2.
+# Latest change: Son Nov 26 18:04:13 CET 2006 [mika]
+################################################################################
+
+set -e # exit on any error
+
+. /etc/grml/script-functions
+. /etc/grml/lsb-functions
+. /etc/grml/autoconfig.functions
+
+check4root || exit 1
+check4progs dd blkid swapon || exit 2
+
+checkbootparam "anyswap" && export ANYSWAP='yes' || export ANYSWAP=""
+
+case $1 in
+   --force)
+     ANYSWAP='yes'
+     ;;
+   -h*|--h*)
+     ewarn 'grml-swapon: activate swap partitions defined in /etc/fstab'
+     eindent
+       ewarn 'Usage: grml-swapon [--help|-h] [--force]'
+       ewarn 'Tip: execute grml-rebuildfstab for rebuilding /etc/fstab'
+     eoutdent
+     eend 1
+     ;;
+esac
+
+einfo "Searching for swap partition(s) as requested."
+eindent
+
+[ -n "$ANYSWAP" ] && einfo "Option --force set, forcing usage of swap partitions."
+
+while read p m f relax; do
+  case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
+  partoptions="users,exec"
+  fnew=""
+  case "$f" in swap)
+     case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
+             S1SUSP|S2SUSP|pmdisk|[zZ]*)
+                if [ -n "$ANYSWAP" ] ; then
+                  einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
+                  swapon $p 2>>$DEBUG ; eend $?
+                else
+                  ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. Force usage via option: --force"
+                fi
+               ;;
+             *)
+                if [[ "$p" == LABEL* ]] ; then
+                   p=$(blkid -t $p | awk -F: '{print $1}')
+                fi
+                if grep -q $p /proc/swaps ; then
+                   ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
+                else
+                   einfo "Using swap partition ${WHITE}${p}${NORMAL}."
+                   swapon $p 2>>$DEBUG ; eend $?
+                fi
+               ;;
+     esac
+   continue
+   ;;
+  esac
+ done <<EOT
+$(cat /etc/fstab)
+EOT
+
+eoutdent