A workaround to make sure /dev/mtd0 can be created
[live-boot-grml.git] / components / 9990-main.sh
1 #!/bin/sh
2
3 # set -e
4
5 Live ()
6 {
7         if [ -x /scripts/local-top/cryptroot ]
8         then
9                 /scripts/local-top/cryptroot
10         fi
11
12         exec 6>&1
13         exec 7>&2
14         exec > boot.log
15         exec 2>&1
16         tail -f boot.log >&7 &
17         tailpid="${!}"
18
19         LIVE_BOOT_CMDLINE="${LIVE_BOOT_CMDLINE:-$(cat /proc/cmdline)}"
20         Cmdline_old
21
22         Debug
23
24         Read_only
25
26         Select_eth_device
27
28         if [ -e /conf/param.conf ]
29         then
30                 . /conf/param.conf
31         fi
32
33         # Needed here too because some things (*cough* udev *cough*)
34         # changes the timeout
35
36         if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
37         then
38                 if do_netmount
39                 then
40                         livefs_root="${mountpoint}"
41                 else
42                         panic "Unable to find a live file system on the network"
43                 fi
44         else
45                 if [ -n "${ISCSI_PORTAL}" ]
46                 then
47                         do_iscsi && livefs_root="${mountpoint}"
48                 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
49                 then
50                         # Do a local boot from hd
51                         livefs_root=${ROOT}
52                 else
53                         if [ -x /usr/bin/memdiskfind ]
54                         then
55                                 MEMDISK=$(/usr/bin/memdiskfind)
56
57                                 if [ $? -eq 0 ]
58                                 then
59                                         # We found a memdisk, set up phram
60                                         # Sometimes "modprobe phram" can not successfully create /dev/mtd0.
61                                         # Have to try several times.
62                                         max_try=20
63                                         while [ ! -c /dev/mtd0 -a "$max_try" -gt 0 ]; do
64                                           modprobe phram phram=memdisk,${MEMDISK}
65                                           sleep 0.2
66                                           if [ -c /dev/mtd0 ]; then
67                                                 break
68                                           else
69                                                 rmmod phram
70                                           fi
71                                           max_try=$((max_try - 1))
72                                         done
73
74                                         # Load mtdblock, the memdisk will be /dev/mtdblock0
75                                         modprobe mtdblock
76                                 fi
77                         fi
78
79                         # Scan local devices for the image
80                         i=0
81                         while [ "$i" -lt 60 ]
82                         do
83                                 livefs_root=$(find_livefs ${i})
84
85                                 if [ -n "${livefs_root}" ]
86                                 then
87                                         break
88                                 fi
89
90                                 sleep 1
91                                 i="$(($i + 1))"
92                         done
93                 fi
94         fi
95
96         if [ -z "${livefs_root}" ]
97         then
98                 panic "Unable to find a medium containing a live file system"
99         fi
100
101         Verify_checksums "${livefs_root}"
102
103         if [ "${TORAM}" ]
104         then
105                 live_dest="ram"
106         elif [ "${TODISK}" ]
107         then
108                 live_dest="${TODISK}"
109         fi
110
111         if [ "${live_dest}" ]
112         then
113                 log_begin_msg "Copying live media to ${live_dest}"
114                 copy_live_to "${livefs_root}" "${live_dest}"
115                 log_end_msg
116         fi
117
118         # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
119         # because the mountpoint is left behind in /proc/mounts, so let's get
120         # rid of it when running from RAM
121         if [ -n "$FROMISO" ] && [ "${TORAM}" ]
122         then
123                 losetup -d /dev/loop0
124
125                 if is_mountpoint /run/live/fromiso
126                 then
127                         umount /run/live/fromiso
128                         rmdir --ignore-fail-on-non-empty /run/live/fromiso \
129                                 >/dev/null 2>&1 || true
130                 fi
131         fi
132
133         if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
134         then
135                 setup_unionfs "${livefs_root}" "${rootmnt}"
136         else
137                 mac="$(get_mac)"
138                 mac="$(echo ${mac} | sed 's/-//g')"
139                 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
140         fi
141
142         if [ -n "${ROOT_PID}" ]
143         then
144                 echo "${ROOT_PID}" > "${rootmnt}"/lib/live/root.pid
145         fi
146
147         log_end_msg
148
149         # aufs2 in kernel versions around 2.6.33 has a regression:
150         # directories can't be accessed when read for the first the time,
151         # causing a failure for example when accessing /var/lib/fai
152         # when booting FAI, this simple workaround solves it
153         ls /root/* >/dev/null 2>&1
154
155         # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
156         # because the mountpoint is left behind in /proc/mounts, so let's get
157         # rid of it when running from RAM
158         if [ -n "$FINDISO" ] && [ "${TORAM}" ]
159         then
160                 losetup -d /dev/loop0
161
162                 if is_mountpoint /run/live/findiso
163                 then
164                         umount /run/live/findiso
165                         rmdir --ignore-fail-on-non-empty /run/live/findiso \
166                                 >/dev/null 2>&1 || true
167                 fi
168         fi
169
170         if [ -L /root/etc/resolv.conf ] ; then
171                 # assume we have resolvconf
172                 DNSFILE="${rootmnt}/etc/resolvconf/resolv.conf.d/base"
173         else
174                 DNSFILE="${rootmnt}/etc/resolv.conf"
175         fi
176         if [ -f /etc/resolv.conf ] && ! grep -E -q -v '^[[:space:]]*#|^[[:space:]]*$' ${DNSFILE}
177         then
178                 log_begin_msg "Copying /etc/resolv.conf to ${DNSFILE}"
179                 cp -v /etc/resolv.conf ${DNSFILE}
180                 log_end_msg
181         fi
182
183         if ! [ -d "/lib/live/boot" ]
184         then
185                 panic "A wrong rootfs was mounted."
186         fi
187
188         # avoid breaking existing user scripts that rely on the old path
189         # this includes code that checks what is mounted on /lib/live/mount/*
190         # (eg: grep /lib/live /proc/mount)
191         # XXX: to be removed before the bullseye release
192         mkdir -p ${rootmnt}/lib/live/mount
193         mount --rbind /run/live ${rootmnt}/lib/live/mount
194
195         Fstab
196         Netbase
197
198         Swap
199
200         exec 1>&6 6>&-
201         exec 2>&7 7>&-
202         kill ${tailpid}
203         [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && ( \
204                                 cp boot.log "${rootmnt}/var/log/live" 2>/dev/null; \
205                                 cp fsck.log "${rootmnt}/var/log/live" 2>/dev/null )
206 }