Adjusting internal file of the swap component to match its own boot parameter.
[live-boot-grml.git] / components / 3020-swap
diff --git a/components/3020-swap b/components/3020-swap
new file mode 100755 (executable)
index 0000000..a1bcdbe
--- /dev/null
@@ -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.d/swap
+       then
+               grep -v "swap swap" /root/etc/fstab.d/swap > /root/etc/fstab.d/swap.tmp
+               mv /root/etc/fstab.d/swap.tmp /root/etc/fstab.d/swap
+       fi
+
+       # Add new swap entries
+       for _DEVICE in ${_SWAP_DEVICES}
+       do
+               echo "${_DEVICE} swap swap defaults 0 0" >> /root/etc/fstab.d/swap
+       done
+}