3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # and Thorsten Glaser <tg@mirbsd.org>
6 # Last updated 2018/01/26
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
16 [ -n "$AUTO_INSTALL" ] && INSTALL=1
18 # configure debugging output
19 if [ -n "$DEBUG" -o -n "$INSTALL" ]; then
24 test -e "$LOG" || busybox mknod $LOG c 1 3
29 if test x"$HAS_CTTY" != x"Yes"; then
30 # initialise /proc and /sys
31 busybox mount -t proc proc /proc
32 busybox mount -t sysfs sys /sys
33 # let busybox install all applets as symlinks
35 # spawn shells on tty 2 and 3 if debug or installer
36 if test -n "$DEBUG" || test -n "$INSTALL"; then
37 # ensure they can open a controlling tty
39 # create device nodes then spawn on them
40 mknod /dev/tty2 c 4 2 && openvt
41 mknod /dev/tty3 c 4 3 && openvt
43 if test -z "$DEBUG" || test -n "$INSTALL"; then
44 echo 0 0 0 0 > /proc/sys/kernel/printk
46 # initialise /dev (first time)
48 echo /sbin/mdev > /proc/sys/kernel/hotplug
50 # re-run this script with a controlling tty
51 exec env HAS_CTTY=Yes setsid cttyhack /bin/sh "$0" "$@"
54 # now running under a controlling tty; debug output from stderr into log file
66 if [ "${ROOT#*:/}" != "$ROOT" ]; then
67 # for NFS roots, use nolock to avoid dependency to portmapper
68 mount -o $RW,noatime,nolock $@
73 mount.ntfs-3g -o rw,force $@
76 mount -o $RW,noatime $@
86 if [ "`dirname $1`" = "/dev" ]; then
89 [ ! -e /dev/block/$blk ] && ln $1 /dev/block
94 try_mount ro $dev /mnt || return 1
95 if [ -n "$iso" -a -e /mnt/$iso ]; then
96 mount --move /mnt /iso
98 mount -o loop /iso/$iso /mnt/iso
100 if [ -e /mnt/$SRC/$RAMDISK ]; then
101 zcat /mnt/$SRC/$RAMDISK | cpio -id > /dev/null
102 elif [ -b /dev/$RAMDISK ]; then
103 zcat /dev/$RAMDISK | cpio -id > /dev/null
107 if [ -e /mnt/$SRC/system.sfs ]; then
108 mount -o loop,noatime /mnt/$SRC/system.sfs /sfs
109 mount -o loop,noatime /sfs/system.img system
110 elif [ -e /mnt/$SRC/system.img ]; then
112 mount -o loop,noatime /mnt/$SRC/system.img system
113 elif [ -d /mnt/$SRC/system ]; then
115 mount --bind /mnt/$SRC/system system
116 elif [ -z "$SRC" -a -e /mnt/build.prop ]; then
117 mount --bind /mnt system
130 # "foo" as mount source is given to workaround a Busybox bug with NFS
131 # - as it's ignored anyways it shouldn't harm for other filesystems.
132 mount -o remount,rw foo /mnt
137 if [ -x system/bin/sh ]; then
138 echo Running MirBSD Korn Shell...
139 USER="($1)" system/bin/sh -l 2>&1
141 echo Running busybox ash...
146 echo -n Detecting Android-x86...
148 [ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE`
149 [ -z "$RAMDISK" ] && RAMDISK=ramdisk.img || RAMDISK=${RAMDISK##/dev/}
151 for c in `cat /proc/cmdline`; do
155 eval `echo $c | cut -b1-3,18-`
162 mount -t tmpfs tmpfs /android
165 for device in ${ROOT:-/dev/[hmnsv][dmrv][0-9a-z]*}; do
166 check_root $device && break 2
167 mountpoint -q /mnt && umount /mnt
174 ln -s android/system /
175 ln -s ../system/lib/firmware ../system/lib/modules /lib
177 if [ -n "$INSTALL" ]; then
178 zcat /src/install.img | ( cd /; cpio -iud > /dev/null )
181 if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then
183 sed -i 's|\( PATH.*\)|\1:/bin|' init.environ.rc
185 busybox mv /sbin/* sbin
187 ln -s android/bin android/lib android/sbin /
192 for s in `ls /scripts/* /src/scripts/*`; do
193 test -e "$s" && source $s
196 # ensure keyboard driver is loaded
197 if [ -n "$INSTALL" -o -n "$DEBUG" ]; then
198 busybox modprobe -a atkbd hid-apple
202 if [ 0$DEBUG -gt 0 ]; then
203 echo -e "\nType 'exit' to continue booting...\n"
204 debug_shell debug-found
207 # A target should provide its detect_hardware function.
208 # On success, return 0 with the following values set.
209 # return 1 if it wants to use auto_detect
210 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
212 [ -n "$INSTALL" ] && do_install
221 if [ 0$DEBUG -gt 1 ]; then
222 echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
223 echo -e "Type 'exit' to enter Android...\n"
225 debug_shell debug-late
226 SETUPWIZARD=${SETUPWIZARD:-0}
229 [ "$SETUPWIZARD" = "0" ] && echo "ro.setupwizard.mode=DISABLED" >> default.prop
231 [ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot}
233 # We must disable mdev before switching to Android
234 # since it conflicts with Android's init
235 echo > /proc/sys/kernel/hotplug
237 export ANDROID_ROOT=/system
239 exec ${SWITCH:-switch_root} /android /init
244 echo ' Android-x86 console shell. Use only in emergencies.'
246 debug_shell fatal-err