Moving initramfs-tools entry-point to backends.
[debian-live-boot.git] / scripts / boot / 9990-main.sh
blobfd10e5d43f7f7f9d6d109a987ffdcbc1d6ae5d51
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}"
138 # At this point /root should contain the final root filesystem.
139 # Move all mountpoints below /live into /root/lib/live/mount.
140 # This has to be done after mounting the root filesystem to /
141 # otherwise these mount points won't be accessible from the running system.
142 for _MOUNT in $(cat /proc/mounts | cut -f 2 -d " " | grep -e "^/live/")
144 local newmount
145 newmount="${rootmnt}/lib/live/mount/${_MOUNT#/live/}"
146 mkdir -p "${newmount}"
147 mount -o move "${_MOUNT}" "${newmount}" > /dev/null 2>&1 || \
148 mount -o bind "${_MOUNT}" "${newmount}" > /dev/null || \
149 log_warning_msg "W: failed to move or bindmount ${_MOUNT} to ${newmount}"
150 done
152 if [ -n "${ROOT_PID}" ]
153 then
154 echo "${ROOT_PID}" > "${rootmnt}"/lib/live/root.pid
157 log_end_msg
159 # unionfs-fuse needs /dev to be bind-mounted for the duration of
160 # live-bottom; udev's init script will take care of things after that
161 case "${UNIONTYPE}" in
162 unionfs-fuse)
163 mount -n -o bind /dev "${rootmnt}/dev"
165 esac
168 # aufs2 in kernel versions around 2.6.33 has a regression:
169 # directories can't be accessed when read for the first the time,
170 # causing a failure for example when accessing /var/lib/fai
171 # when booting FAI, this simple workaround solves it
172 ls /root/* >/dev/null 2>&1
174 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
175 # because the mountpoint is left behind in /proc/mounts, so let's get
176 # rid of it when running from RAM
177 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
178 then
179 losetup -d /dev/loop0
181 if is_mountpoint /root/lib/live/mount/findiso
182 then
183 umount /root/lib/live/mount/findiso
184 rmdir --ignore-fail-on-non-empty /root/lib/live/mount/findiso \
185 >/dev/null 2>&1 || true
189 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
190 then
191 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
192 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
193 log_end_msg
196 if ! [ -d "/lib/live/boot" ]
197 then
198 panic "A wrong rootfs was mounted."
201 Fstab
202 Netbase
204 Swap
206 case "${UNIONFS}" in
207 unionfs-fuse)
208 umount "${rootmnt}/dev"
210 esac
212 exec 1>&6 6>&-
213 exec 2>&7 7>&-
214 kill ${tailpid}
215 [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null