From 6c9872bc5d18f60e6b6ad94bdc18bd217e2119f9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 5 Jun 2012 18:43:37 +0200 Subject: [PATCH] Splitting out swap handling and rewriting to a live-boot subscript. --- initramfs-tools/scripts/live-bottom/12fstab | 39 ----------------------- scripts/boot.sh | 6 ++++ scripts/boot/swapon.sh | 48 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 39 deletions(-) create mode 100755 scripts/boot/swapon.sh diff --git a/initramfs-tools/scripts/live-bottom/12fstab b/initramfs-tools/scripts/live-bottom/12fstab index 94adddb..848fc2f 100755 --- a/initramfs-tools/scripts/live-bottom/12fstab +++ b/initramfs-tools/scripts/live-bottom/12fstab @@ -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 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 +} -- 2.1.4