Adding upstream version 3.0~a29.
[live-boot-grml.git] / initramfs-tools / scripts / live-bottom / 12fstab
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8 FSTAB=/root/etc/fstab
9
10 prereqs()
11 {
12         echo "${PREREQ}"
13 }
14
15 case "${1}" in
16         prereqs)
17                 prereqs
18                 exit 0
19                 ;;
20 esac
21
22 # live-boot header
23
24 # FIXME: stop hardcoding overloading of initramfs-tools functions
25 . /scripts/functions
26 . /lib/live/boot/initramfs-tools.sh
27
28 if [ -n "${NOFSTAB}" ]
29 then
30         exit 0
31 fi
32
33 log_begin_msg "Configuring fstab"
34
35 # live-boot script
36
37 if ! grep -qs  "^${UNIONTYPE}" "${FSTAB}"
38 then
39         echo "${UNIONTYPE} / ${UNIONTYPE} rw 0 0" >> "${FSTAB}"
40 fi
41
42 if ! grep -qs "^tmpfs /tmp" "${FSTAB}"
43 then
44         echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${FSTAB}"
45 fi
46
47 if [ -n "${SWAPON}" ]
48 then
49         devices=""
50
51         for device in /dev/[hs]d[a-z][0-9]*
52         do
53                 if ! [ -b "${device}" ]
54                 then
55                         continue
56                 fi
57
58                 /sbin/blkid -o udev -p ${device%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue
59
60                 magic=$(/bin/dd if="${device}" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null) || continue
61
62                 if [ "${magic}" = "SWAPSPACE2" -o "${magic}" = "SWAP-SPACE" ]
63                 then
64                         #log "Found ${device}"
65                         devices="${devices} ${device}"
66                 fi
67         done
68
69         # Remove all auto swap entries
70         if grep -qs  "swap swap" "${FSTAB}"
71         then
72                 grep -v "swap swap" "${FSTAB}" > "${FSTAB}".tmp
73                 mv "${FSTAB}".tmp "${FSTAB}"
74         fi
75
76         # Add new swap entries
77         for device in ${devices}
78         do
79                 echo "${device} swap swap defaults 0 0" >> "${FSTAB}"
80         done
81 fi
82
83 # disabled for now
84 #rm -f /root/etc/rcS.d/S*checkroot.sh
85
86 if [ "${NOFASTBOOT}" != "Yes" ]
87 then
88         touch root/fastboot
89 fi
90
91 log_end_msg