3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # and Thorsten Glaser <tg@mirbsd.org>
6 # Last updated 2018/01/12
8 # License: GNU Public License
9 # We explicitely grant the right to use the scripts
10 # with Android-x86 project.
13 PATH=/sbin:/bin:/system/bin:/system/xbin; export PATH
15 # configure debugging output
16 if [ -n "$DEBUG" ]; then
21 test -e "$LOG" || busybox mknod $LOG c 1 3
26 if test x"$HAS_CTTY" != x"Yes"; then
27 # initialise /proc and /sys
28 busybox mount -t proc proc /proc
29 busybox mount -t sysfs sys /sys
30 # let busybox install all applets as symlinks
32 # spawn shells on tty 2 and 3 if debug or installer
33 if test -n "$DEBUG" || test -n "$INSTALL"; then
34 # ensure they can open a controlling tty
36 # create device nodes then spawn on them
37 mknod /dev/tty2 c 4 2 && openvt
38 mknod /dev/tty3 c 4 3 && openvt
40 if test -z "$DEBUG" || test -n "$INSTALL"; then
41 echo 0 0 0 0 > /proc/sys/kernel/printk
43 # initialise /dev (first time)
45 echo /sbin/mdev > /proc/sys/kernel/hotplug
47 # re-run this script with a controlling tty
48 exec env HAS_CTTY=Yes setsid cttyhack /bin/sh "$0" "$@"
51 # now running under a controlling tty; debug output from stderr into log file
63 if [ "${ROOT#*:/}" != "$ROOT" ]; then
64 # for NFS roots, use nolock to avoid dependency to portmapper
69 mount.ntfs-3g -o rw,force $@
72 mount -o $RW,noatime $@
82 if [ "`dirname $1`" = "/dev" ]; then
85 [ ! -e /dev/block/$blk ] && ln $1 /dev/block
90 try_mount ro $dev /mnt || return 1
91 if [ -n "$iso" -a -e /mnt/$iso ]; then
92 mount --move /mnt /iso
94 mount -o loop /iso/$iso /mnt/iso
97 if [ -e /mnt/$SRC/$RAMDISK ]; then
98 zcat /mnt/$SRC/$RAMDISK | cpio -id > /dev/null
99 elif [ -b /dev/$RAMDISK ]; then
100 zcat /dev/$RAMDISK | cpio -id > /dev/null
104 if [ -e /mnt/$SRC/system.sfs ]; then
105 mount -o loop,noatime /mnt/$SRC/system.sfs /sfs
106 mount -o loop,noatime /sfs/system.img system
107 elif [ -e /mnt/$SRC/system.img ]; then
109 mount -o loop,noatime /mnt/$SRC/system.img system
110 elif [ -d /mnt/$SRC/system ]; then
112 mount --bind /mnt/$SRC/system system
113 elif [ -e /mnt/build.prop ]; then
114 mount --bind /mnt system
127 # "foo" as mount source is given to workaround a Busybox bug with NFS
128 # - as it's ignored anyways it shouldn't harm for other filesystems.
129 mount -o remount,rw foo /mnt
134 if [ -x system/bin/sh ]; then
135 echo Running MirBSD Korn Shell...
136 USER="($1)" system/bin/sh -l 2>&1
138 echo Running busybox ash...
143 echo -n Detecting Android-x86...
145 [ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE`
146 [ -z "$RAMDISK" ] && RAMDISK=ramdisk.img || RAMDISK=${RAMDISK##/dev/}
148 for c in `cat /proc/cmdline`; do
151 eval `echo $c | cut -b1-3,18-`
158 mount -t tmpfs tmpfs /android
161 for device in ${ROOT:-/dev/[hmnsv][dmrv][0-9a-z]*}; do
162 check_root $device && break 2
163 mountpoint -q /mnt && umount /mnt
170 ln -s android/system /
171 ln -s ../system/lib/firmware ../system/lib/modules /lib
173 if [ -n "$INSTALL" ]; then
174 zcat /src/install.img | ( cd /; cpio -iud > /dev/null )
177 if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then
179 sed -i 's|\( PATH.*\)|\1:/bin|' init.environ.rc
181 busybox mv /sbin/* sbin
183 ln -s android/bin android/lib android/sbin /
188 for s in `ls /scripts/* /src/scripts/*`; do
189 test -e "$s" && source $s
192 # ensure keyboard driver is loaded
193 [ -n "$INSTALL" -o -n "$DEBUG" ] && auto_detect &
195 if [ 0$DEBUG -gt 0 ]; then
196 echo -e "\nType 'exit' to continue booting...\n"
197 debug_shell debug-found
200 # A target should provide its detect_hardware function.
201 # On success, return 0 with the following values set.
202 # return 1 if it wants to use auto_detect
203 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
205 [ -n "$INSTALL" ] && do_install
214 if [ 0$DEBUG -gt 1 ]; then
215 echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
216 echo -e "Type 'exit' to enter Android...\n"
218 debug_shell debug-late
219 SETUPWIZARD=${SETUPWIZARD:-0}
222 [ "$SETUPWIZARD" = "0" ] && echo "ro.setupwizard.mode=DISABLED" >> default.prop
224 [ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot}
226 # We must disable mdev before switching to Android
227 # since it conflicts with Android's init
228 echo > /proc/sys/kernel/hotplug
230 export ANDROID_ROOT=/system
232 exec ${SWITCH:-switch_root} /android /init
237 echo ' Android-x86 console shell. Use only in emergencies.'
239 debug_shell fatal-err