summaryrefslogtreecommitdiffstats
path: root/system-boot/components/3020-swap
diff options
context:
space:
mode:
Diffstat (limited to 'system-boot/components/3020-swap')
-rwxr-xr-xsystem-boot/components/3020-swap62
1 files changed, 62 insertions, 0 deletions
diff --git a/system-boot/components/3020-swap b/system-boot/components/3020-swap
new file mode 100755
index 0000000..345b9a0
--- /dev/null
+++ b/system-boot/components/3020-swap
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#set -e
+
+Swap ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.swap=*|swap=*)
+ LIVE_SWAP="true"
+ LIVE_SWAP_DEVICES="${_PARAMETER#*swap=}"
+ ;;
+
+ live-boot.swap|swap)
+ LIVE_SWAP="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_SWAP}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ LIVE_SWAP_DEVICES="${LIVE_SWAP_DEVICES:-/dev/sd* /dev/vd*}"
+
+ for _DEVICE in $(echo ${LIVE_SWAP_DEVICES} | sed -e 's|,| |g')
+ 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" /root/etc/fstab
+ then
+ grep -v "swap swap" /root/etc/fstab > /root/etc/fstab.tmp
+ mv /root/etc/fstab.tmp /root/etc/fstab
+ fi
+
+ # Add new swap entries
+ for _DEVICE in ${_SWAP_DEVICES}
+ do
+ echo "${_DEVICE} swap swap defaults 0 0" >> /root/etc/fstab
+ done
+}