Sync with Debian git, incorporating 09_use_udevadm_info.dpatch
[live-initramfs-grml.git] / scripts / live-bottom / 13swap
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 if [ -z "${SWAPON}" ] || [ -n "${NOFSTAB}" ]
24 then
25         exit 0
26 fi
27
28 . /scripts/live-functions
29
30 log_begin_msg "Setting up swap"
31
32 # live-initramfs script
33
34 FSTAB=/root/etc/fstab
35 devices=""
36
37 for device in /dev/[hs]d[a-z][0-9]*
38 do
39         if ! [ -b "${device}" ]
40         then
41                 continue
42         fi
43
44         /lib/udev/vol_id ${device%%[0-9]*} 2>/dev/null | grep -q "^ID_FS_USAGE=raid" && continue
45
46         magic=$(/bin/dd if="${device}" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null) || continue
47
48         if [ "${magic}" = "SWAPSPACE2" -o "${magic}" = "SWAP-SPACE" ]
49         then
50                 #log "Found ${device}"
51                 devices="${devices} ${device}"
52         fi
53 done
54
55 for device in ${devices}
56 do
57
58 if ! grep -qs  "^${device} swap" "${FSTAB}"
59 then
60         echo "${device} swap swap defaults 0 0" >> "${FSTAB}"
61 fi
62
63 done
64
65 log_end_msg