Adding live-initramfs 1.87.4-1.
[live-boot-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 . /scripts/live-functions
24
25 log_begin_msg "Setting up swap..."
26
27 # live-initramfs script
28
29 FSTAB=/root/etc/fstab
30
31 if [ -n "${NOSWAP}" ]
32 then
33     exit 0
34 fi
35
36 devices=""
37 for device in /dev/[hs]d[a-z][0-9]*; do
38     if ! [ -b "$device" ]; then
39         continue
40     fi
41
42     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
44     if [ "$magic" = "SWAPSPACE2" -o "$magic" = "SWAP-SPACE" ]; then
45 #        log "Found $device"
46         devices="$devices $device"
47         fi
48 done
49
50 for device in $devices; do
51     cat >> $FSTAB <<EOF
52 $device swap swap defaults 0 0
53 EOF
54 done
55
56 log_end_msg