Allowing to superseed live-boot cmdline through configuration files.
[debian-live-boot.git] / scripts / boot / 3020-swapon
bloba1bcdbec2fc5ad4cb23af56a0bad4e5a7a4d8e0f
1 #!/bin/sh
3 #set -e
5 Swap ()
7 for _PARAMETER in ${LIVE_BOOT_CMDLINE}
8 do
9 case "${_PARAMETER}" in
10 live-boot.swap=*|swap=*)
11 LIVE_SWAP="true"
12 LIVE_SWAP_DEVICES="${_PARAMETER#*swap=}"
15 live-boot.swap|swap)
16 LIVE_SWAP="true"
18 esac
19 done
21 case "${LIVE_SWAP}" in
22 true)
26 return 0
28 esac
30 LIVE_SWAP_DEVICES="${LIVE_SWAP_DEVICES:-/dev/sd* /dev/vd*}"
32 for _DEVICE in $(echo ${LIVE_SWAP_DEVICES} | sed -e 's|,| |g')
34 if [ ! -b "${_DEVICE}" ]
35 then
36 continue
39 blkid -o udev -p ${_DEVICE%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue
41 _MAGIC="$(/bin/dd if=${_DEVICE} bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null)" || continue
43 case "${_MAGIC}" in
44 SWAPSPACE2|SWAP-SPACE)
45 _SWAP_DEVICES="${_SWAP_DEVICES} ${_DEVICE}"
47 esac
48 done
50 # Remove all auto swap entries
51 if grep -qs "swap swap" /root/etc/fstab.d/swap
52 then
53 grep -v "swap swap" /root/etc/fstab.d/swap > /root/etc/fstab.d/swap.tmp
54 mv /root/etc/fstab.d/swap.tmp /root/etc/fstab.d/swap
57 # Add new swap entries
58 for _DEVICE in ${_SWAP_DEVICES}
60 echo "${_DEVICE} swap swap defaults 0 0" >> /root/etc/fstab.d/swap
61 done