From d52bb6661e952f05ae32b4dac8a706fdc6f5ffd3 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Sun, 26 Nov 2006 18:13:51 +0100 Subject: [PATCH] * Add script grml-swapon for activating swap partitions. --- debian/changelog | 6 ++++ debian/rules | 2 +- manpages/grml-swapon.8 | 32 +++++++++++++++++ manpages/reread_partition_table.8 | 4 +-- usr_sbin/grml-swapon | 73 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 manpages/grml-swapon.8 create mode 100755 usr_sbin/grml-swapon diff --git a/debian/changelog b/debian/changelog index f2d5ef6..5dc6885 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +grml-scripts (0.8-32) unstable; urgency=low + + * Add script grml-swapon for activating swap partitions. + + -- Michael Prokop 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 diff --git a/debian/rules b/debian/rules index b71f2c2..47efcc4 100755 --- a/debian/rules +++ b/debian/rules @@ -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 index 0000000..d71f0a5 --- /dev/null +++ b/manpages/grml-swapon.8 @@ -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 . +.PP +This manual page was written by Michael Prokop +for the grml project (but may be used by others). diff --git a/manpages/reread_partition_table.8 b/manpages/reread_partition_table.8 index 72d7fda..f4b808e 100644 --- a/manpages/reread_partition_table.8 +++ b/manpages/reread_partition_table.8 @@ -22,5 +22,5 @@ Reread partition table for disk /dev/hda. reread_partition_table was written by Michael Prokop . .PP -This manual page was written by Michael Prokop - for the Debian project (but may be used by others). +This manual page was written by Michael Prokop +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 index 0000000..1235433 --- /dev/null +++ b/usr_sbin/grml-swapon @@ -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 +# 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 <