Splitting out already reviewed cmdline parsing script.
[debian-live-boot.git] / scripts / boot / 9990-main.sh
blob3ad6a7260e5396167efa03769fc7f01e44b44587
1 #!/bin/sh
3 # set -e
5 Main ()
7 if [ -x /scripts/local-top/cryptroot ]
8 then
9 /scripts/local-top/cryptroot
12 exec 6>&1
13 exec 7>&2
14 exec > boot.log
15 exec 2>&1
16 tail -f boot.log >&7 &
17 tailpid="${!}"
19 . /live.vars
21 _CMDLINE="$(cat /proc/cmdline)"
22 Cmdline
23 Cmdline_old
25 case "${LIVE_DEBUG}" in
26 true)
27 set -x
29 esac
31 case "${LIVE_READ_ONLY}" in
32 true)
33 Read_only
35 esac
37 Select_eth_device
39 # Needed here too because some things (*cough* udev *cough*)
40 # changes the timeout
42 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
43 then
44 if do_netmount
45 then
46 livefs_root="${mountpoint}"
47 else
48 panic "Unable to find a live file system on the network"
50 else
51 if [ -n "${ISCSI_PORTAL}" ]
52 then
53 do_iscsi && livefs_root="${mountpoint}"
54 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
55 then
56 # Do a local boot from hd
57 livefs_root=${ROOT}
58 else
59 if [ -x /usr/bin/memdiskfind ]
60 then
61 MEMDISK=$(/usr/bin/memdiskfind)
63 if [ $? -eq 0 ]
64 then
65 # We found a memdisk, set up phram
66 modprobe phram phram=memdisk,${MEMDISK}
68 # Load mtdblock, the memdisk will be /dev/mtdblock0
69 modprobe mtdblock
73 # Scan local devices for the image
74 i=0
75 while [ "$i" -lt 60 ]
77 livefs_root=$(find_livefs ${i})
79 if [ -n "${livefs_root}" ]
80 then
81 break
84 sleep 1
85 i="$(($i + 1))"
86 done
90 if [ -z "${livefs_root}" ]
91 then
92 panic "Unable to find a medium containing a live file system"
95 case "${LIVE_VERIFY_CHECKSUMS}" in
96 true)
97 Verify_checksums "${livefs_root}"
99 esac
101 if [ "${TORAM}" ]
102 then
103 live_dest="ram"
104 elif [ "${TODISK}" ]
105 then
106 live_dest="${TODISK}"
109 if [ "${live_dest}" ]
110 then
111 log_begin_msg "Copying live media to ${live_dest}"
112 copy_live_to "${livefs_root}" "${live_dest}"
113 log_end_msg
116 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
117 # because the mountpoint is left behind in /proc/mounts, so let's get
118 # rid of it when running from RAM
119 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
120 then
121 losetup -d /dev/loop0
123 if is_mountpoint /live/fromiso
124 then
125 umount /live/fromiso
126 rmdir --ignore-fail-on-non-empty /live/fromiso \
127 >/dev/null 2>&1 || true
131 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
132 then
133 setup_unionfs "${livefs_root}" "${rootmnt}"
134 else
135 mac="$(get_mac)"
136 mac="$(echo ${mac} | sed 's/-//g')"
137 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
141 if [ -n "${ROOT_PID}" ]
142 then
143 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
146 log_end_msg
148 # unionfs-fuse needs /dev to be bind-mounted for the duration of
149 # live-bottom; udev's init script will take care of things after that
150 case "${UNIONTYPE}" in
151 unionfs-fuse)
152 mount -n -o bind /dev "${rootmnt}/dev"
154 esac
156 # Move to the new root filesystem so that programs there can get at it.
157 if [ ! -d /root/live/image ]
158 then
159 mkdir -p /root/live/image
160 mount --move /live/image /root/live/image
163 # aufs2 in kernel versions around 2.6.33 has a regression:
164 # directories can't be accessed when read for the first the time,
165 # causing a failure for example when accessing /var/lib/fai
166 # when booting FAI, this simple workaround solves it
167 ls /root/* >/dev/null 2>&1
169 # Move findiso directory to the new root filesystem so that programs there can get at it.
170 if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
171 then
172 mkdir -p /root/live/findiso
173 mount -n --move /live/findiso /root/live/findiso
176 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
177 # because the mountpoint is left behind in /proc/mounts, so let's get
178 # rid of it when running from RAM
179 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
180 then
181 losetup -d /dev/loop0
183 if is_mountpoint /root/live/findiso
184 then
185 umount /root/live/findiso
186 rmdir --ignore-fail-on-non-empty /root/live/findiso \
187 >/dev/null 2>&1 || true
191 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
192 then
193 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
194 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
195 log_end_msg
198 if ! [ -d "/lib/live/boot" ]
199 then
200 panic "A wrong rootfs was mounted."
203 Fstab
204 Netbase
206 case "${LIVE_SWAPON}" in
207 true)
208 Swapon
210 esac
212 case "${UNIONFS}" in
213 unionfs-fuse)
214 umount "${rootmnt}/dev"
216 esac
218 exec 1>&6 6>&-
219 exec 2>&7 7>&-
220 kill ${tailpid}
221 [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null