summaryrefslogtreecommitdiff
path: root/scripts/boot
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2012-06-05 18:43:37 +0200
committerDaniel Baumann <daniel@debian.org>2012-06-05 19:35:56 +0200
commit6c9872bc5d18f60e6b6ad94bdc18bd217e2119f9 (patch)
treebdd79d02e8f7e5d731685897bcb0d3de0fac6911 /scripts/boot
parentf4d4be1f0223a2e888286988503ea26fee2a8324 (diff)
downloadlive-boot-6c9872bc5d18f60e6b6ad94bdc18bd217e2119f9.tar.gz
live-boot-6c9872bc5d18f60e6b6ad94bdc18bd217e2119f9.zip
Splitting out swap handling and rewriting to a live-boot subscript.
Diffstat (limited to 'scripts/boot')
-rwxr-xr-xscripts/boot/swapon.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/boot/swapon.sh b/scripts/boot/swapon.sh
new file mode 100755
index 0000000..158d81b
--- /dev/null
+++ b/scripts/boot/swapon.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+#set -e
+
+Swapon ()
+{
+ _DEVICES="/dev/sd* /dev/vd*"
+
+ if [ -e /run ]
+ then
+ # wheezy
+ _FSTAB="/root/etc/fstab.d/swap"
+ else
+ # squeeze
+ _FSTAB="/root/etc/fstab"
+ fi
+
+ for _DEVICE in ${_DEVICES}
+ do
+ if [ ! -b "${_DEVICE}" ]
+ then
+ continue
+ fi
+
+ blkid -o udev -p ${_DEVICE%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue
+
+ _MAGIC="$(/bin/dd if=${_DEVICE} bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null)" || continue
+
+ case "${_MAGIC}" in
+ SWAPSPACE2|SWAP-SPACE)
+ _SWAP_DEVICES="${_SWAP_DEVICES} ${_DEVICE}"
+ ;;
+ esac
+ done
+
+ # Remove all auto swap entries
+ if grep -qs "swap swap" "${_FSTAB}"
+ then
+ grep -v "swap swap" "${_FSTAB}" > "${_FSTAB}".tmp
+ mv "${_FSTAB}".tmp "${_FSTAB}"
+ fi
+
+ # Add new swap entries
+ for _DEVICE in _SWAP_DEVICES
+ do
+ echo "${_DEVICE} swap swap defaults 0 0" >> "${_FSTAB}"
+ done
+}