Adding temporary notes in a readme file.
[debian-live-boot/hramrach.git] / scripts / boot / mountroot.sh
blob2d14e4d13cffe666d3867259962385e75e1e4acc
1 #!/bin/sh
3 # set -e
5 mountroot ()
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
24 case "${LIVE_DEBUG}" in
25 true)
26 set -x
28 esac
30 case "${LIVE_READ_ONLY}" in
31 true)
32 Read_only
34 esac
36 Select_eth_device
38 # Needed here too because some things (*cough* udev *cough*)
39 # changes the timeout
41 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
42 then
43 if do_netmount
44 then
45 livefs_root="${mountpoint}"
46 else
47 panic "Unable to find a live file system on the network"
49 else
50 if [ -n "${ISCSI_PORTAL}" ]
51 then
52 do_iscsi && livefs_root="${mountpoint}"
53 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
54 then
55 # Do a local boot from hd
56 livefs_root=${ROOT}
57 else
58 if [ -x /usr/bin/memdiskfind ]
59 then
60 MEMDISK=$(/usr/bin/memdiskfind)
62 if [ $? -eq 0 ]
63 then
64 # We found a memdisk, set up phram
65 modprobe phram phram=memdisk,${MEMDISK}
67 # Load mtdblock, the memdisk will be /dev/mtdblock0
68 modprobe mtdblock
72 # Scan local devices for the image
73 i=0
74 while [ "$i" -lt 60 ]
76 livefs_root=$(find_livefs ${i})
78 if [ -n "${livefs_root}" ]
79 then
80 break
83 sleep 1
84 i="$(($i + 1))"
85 done
89 if [ -z "${livefs_root}" ]
90 then
91 panic "Unable to find a medium containing a live file system"
94 case "${LIVE_VERIFY_CHECKSUMS}" in
95 true)
96 Verify_checksums "${livefs_root}"
98 esac
100 if [ "${TORAM}" ]
101 then
102 live_dest="ram"
103 elif [ "${TODISK}" ]
104 then
105 live_dest="${TODISK}"
108 if [ "${live_dest}" ]
109 then
110 log_begin_msg "Copying live media to ${live_dest}"
111 copy_live_to "${livefs_root}" "${live_dest}"
112 log_end_msg
115 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
116 # because the mountpoint is left behind in /proc/mounts, so let's get
117 # rid of it when running from RAM
118 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
119 then
120 losetup -d /dev/loop0
122 if is_mountpoint /live/fromiso
123 then
124 umount /live/fromiso
125 rmdir --ignore-fail-on-non-empty /live/fromiso \
126 >/dev/null 2>&1 || true
130 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
131 then
132 setup_unionfs "${livefs_root}" "${rootmnt}"
133 else
134 mac="$(get_mac)"
135 mac="$(echo ${mac} | sed 's/-//g')"
136 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
140 if [ -n "${ROOT_PID}" ]
141 then
142 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
145 log_end_msg
147 # unionfs-fuse needs /dev to be bind-mounted for the duration of
148 # live-bottom; udev's init script will take care of things after that
149 case "${UNIONTYPE}" in
150 unionfs-fuse)
151 mount -n -o bind /dev "${rootmnt}/dev"
153 esac
155 # Move to the new root filesystem so that programs there can get at it.
156 if [ ! -d /root/live/image ]
157 then
158 mkdir -p /root/live/image
159 mount --move /live/image /root/live/image
162 # aufs2 in kernel versions around 2.6.33 has a regression:
163 # directories can't be accessed when read for the first the time,
164 # causing a failure for example when accessing /var/lib/fai
165 # when booting FAI, this simple workaround solves it
166 ls /root/* >/dev/null 2>&1
168 # Move findiso directory to the new root filesystem so that programs there can get at it.
169 if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
170 then
171 mkdir -p /root/live/findiso
172 mount -n --move /live/findiso /root/live/findiso
175 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
176 # because the mountpoint is left behind in /proc/mounts, so let's get
177 # rid of it when running from RAM
178 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
179 then
180 losetup -d /dev/loop0
182 if is_mountpoint /root/live/findiso
183 then
184 umount /root/live/findiso
185 rmdir --ignore-fail-on-non-empty /root/live/findiso \
186 >/dev/null 2>&1 || true
190 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
191 then
192 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
193 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
194 log_end_msg
197 if ! [ -d "/lib/live/boot" ]
198 then
199 panic "A wrong rootfs was mounted."
202 Fstab
203 Netbase
205 case "${LIVE_SWAPON}" in
206 true)
207 Swapon
209 esac
211 case "${UNIONFS}" in
212 unionfs-fuse)
213 umount "${rootmnt}/dev"
215 esac
217 exec 1>&6 6>&-
218 exec 2>&7 7>&-
219 kill ${tailpid}
220 [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null