summaryrefslogtreecommitdiff
path: root/scripts/live-bottom/13swap
blob: ecbdce1093370b058e96d269ad917d41858065f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

#set -e

# initramfs-tools header

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
	prereqs)
		prereqs
		exit 0
		;;
esac

# live-initramfs header

if [ -n "${NOSWAP}" ] || [ -n "${NOFSTAB}" ]
then
	exit 0
fi

. /scripts/live-functions

log_begin_msg "Setting up swap"

# live-initramfs script

FSTAB=/root/etc/fstab
devices=""

for device in /dev/[hs]d[a-z][0-9]*
do
	if ! [ -b "${device}" ]
	then
		continue
	fi

	/lib/udev/vol_id ${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

for device in ${devices}
do

cat >> ${FSTAB} << EOF
${device} swap swap defaults 0 0
EOF

done

log_end_msg