summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/boot.sh6
-rwxr-xr-xscripts/boot/swapon.sh48
2 files changed, 54 insertions, 0 deletions
diff --git a/scripts/boot.sh b/scripts/boot.sh
index 6304c97..02ac43a 100755
--- a/scripts/boot.sh
+++ b/scripts/boot.sh
@@ -636,6 +636,12 @@ mountroot ()
run_scripts /scripts/live-bottom
log_end_msg
+ case "${LIVE_SWAPON}" in
+ true)
+ Swapon
+ ;;
+ esac
+
if [ "${UNIONFS}" = unionfs-fuse ]
then
umount "${rootmnt}/dev"
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
+}