Making overwriting of /bin/mount within initramfs with mount.util-linux dependent...
[debian-live-boot.git] / scripts / boot / 9990-main.sh
blobc696781434caa71a2550ecd7c46cbf635228b0b9
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_old
24 Debug
26 Read_only
28 Select_eth_device
30 if [ -e /conf/param.conf ]
31 then
32 . /conf/param.conf
35 if [ -n "${FUSE_MOUNT}" ]
36 then
37 # fuse does not work with klibc mount
38 ln -f /bin/mount.util-linux /bin/mount
41 # Needed here too because some things (*cough* udev *cough*)
42 # changes the timeout
44 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
45 then
46 if do_netmount
47 then
48 livefs_root="${mountpoint}"
49 else
50 panic "Unable to find a live file system on the network"
52 else
53 if [ -n "${ISCSI_PORTAL}" ]
54 then
55 do_iscsi && livefs_root="${mountpoint}"
56 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
57 then
58 # Do a local boot from hd
59 livefs_root=${ROOT}
60 else
61 if [ -x /usr/bin/memdiskfind ]
62 then
63 MEMDISK=$(/usr/bin/memdiskfind)
65 if [ $? -eq 0 ]
66 then
67 # We found a memdisk, set up phram
68 modprobe phram phram=memdisk,${MEMDISK}
70 # Load mtdblock, the memdisk will be /dev/mtdblock0
71 modprobe mtdblock
75 # Scan local devices for the image
76 i=0
77 while [ "$i" -lt 60 ]
79 livefs_root=$(find_livefs ${i})
81 if [ -n "${livefs_root}" ]
82 then
83 break
86 sleep 1
87 i="$(($i + 1))"
88 done
92 if [ -z "${livefs_root}" ]
93 then
94 panic "Unable to find a medium containing a live file system"
97 Verify_checksums "${livefs_root}"
99 if [ "${TORAM}" ]
100 then
101 live_dest="ram"
102 elif [ "${TODISK}" ]
103 then
104 live_dest="${TODISK}"
107 if [ "${live_dest}" ]
108 then
109 log_begin_msg "Copying live media to ${live_dest}"
110 copy_live_to "${livefs_root}" "${live_dest}"
111 log_end_msg
114 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
115 # because the mountpoint is left behind in /proc/mounts, so let's get
116 # rid of it when running from RAM
117 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
118 then
119 losetup -d /dev/loop0
121 if is_mountpoint /live/fromiso
122 then
123 umount /live/fromiso
124 rmdir --ignore-fail-on-non-empty /live/fromiso \
125 >/dev/null 2>&1 || true
129 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
130 then
131 setup_unionfs "${livefs_root}" "${rootmnt}"
132 else
133 mac="$(get_mac)"
134 mac="$(echo ${mac} | sed 's/-//g')"
135 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
139 if [ -n "${ROOT_PID}" ]
140 then
141 echo "${ROOT_PID}" > "${rootmnt}"/lib/live/root.pid
144 log_end_msg
146 # unionfs-fuse needs /dev to be bind-mounted for the duration of
147 # live-bottom; udev's init script will take care of things after that
148 case "${UNIONTYPE}" in
149 unionfs-fuse)
150 mount -n -o bind /dev "${rootmnt}/dev"
152 esac
154 # Move to the new root filesystem so that programs there can get at it.
155 mkdir -p /root/lib/live/mount/medium
156 mount --move /live/medium /root/lib/live/mount/medium
158 # aufs2 in kernel versions around 2.6.33 has a regression:
159 # directories can't be accessed when read for the first the time,
160 # causing a failure for example when accessing /var/lib/fai
161 # when booting FAI, this simple workaround solves it
162 ls /root/* >/dev/null 2>&1
164 # Move findiso directory to the new root filesystem so that programs there can get at it.
165 if [ -d /live/findiso ]
166 then
167 mkdir -p /root/lib/live/mount/findiso
168 mount -n --move /live/findiso /root/lib/live/mount/findiso
171 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
172 # because the mountpoint is left behind in /proc/mounts, so let's get
173 # rid of it when running from RAM
174 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
175 then
176 losetup -d /dev/loop0
178 if is_mountpoint /root/lib/live/mount/findiso
179 then
180 umount /root/lib/live/mount/findiso
181 rmdir --ignore-fail-on-non-empty /root/lib/live/mount/findiso \
182 >/dev/null 2>&1 || true
186 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
187 then
188 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
189 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
190 log_end_msg
193 if ! [ -d "/lib/live/boot" ]
194 then
195 panic "A wrong rootfs was mounted."
198 Fstab
199 Netbase
201 Swap
203 case "${UNIONFS}" in
204 unionfs-fuse)
205 umount "${rootmnt}/dev"
207 esac
209 exec 1>&6 6>&-
210 exec 2>&7 7>&-
211 kill ${tailpid}
212 [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null