Splitting out swap handling and rewriting to a live-boot subscript.
authorDaniel Baumann <daniel@debian.org>
Tue, 5 Jun 2012 16:43:37 +0000 (18:43 +0200)
committerDaniel Baumann <daniel@debian.org>
Tue, 5 Jun 2012 17:35:56 +0000 (19:35 +0200)
initramfs-tools/scripts/live-bottom/12fstab
scripts/boot.sh
scripts/boot/swapon.sh [new file with mode: 0755]

index 94adddb..848fc2f 100755 (executable)
@@ -44,45 +44,6 @@ then
        echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${FSTAB}"
 fi
 
-if [ -n "${LIVE_SWAPON}" ]
-then
-       devices=""
-
-       for device in /dev/[sv]d[a-z][0-9]*
-       do
-               if ! [ -b "${device}" ]
-               then
-                       continue
-               fi
-
-               /sbin/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
-
-               if [ "${magic}" = "SWAPSPACE2" -o "${magic}" = "SWAP-SPACE" ]
-               then
-                       #log "Found ${device}"
-                       devices="${devices} ${device}"
-               fi
-       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 ${devices}
-       do
-               echo "${device} swap swap defaults 0 0" >> "${FSTAB}"
-       done
-fi
-
-# disabled for now
-#rm -f /root/etc/rcS.d/S*checkroot.sh
-
 if [ "${NOFASTBOOT}" != "true" ]
 then
        touch root/fastboot
index 6304c97..02ac43a 100755 (executable)
@@ -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 (executable)
index 0000000..158d81b
--- /dev/null
@@ -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
+}