summaryrefslogtreecommitdiff
path: root/scripts/live-bottom/13swap
blob: 8b47a0099d65b27b7742f4b3b00b5028430d9067 (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
#!/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}" ]
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

    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