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 system
109 if [ -e system/system.img ]; then
110 mount --move system /sfs
111 mount -o loop,noatime /sfs/system.img system
113 elif [ -e /mnt/$SRC/system.img ]; then
115 mount -o loop,noatime /mnt/$SRC/system.img system
116 elif [ -s /mnt/$SRC/system/build.prop ]; then
118 mount --bind /mnt/$SRC/system system
119 elif [ -z "$SRC" -a -s /mnt/build.prop ]; then
120 mount --bind /mnt system
133 # "foo" as mount source is given to workaround a Busybox bug with NFS
134 # - as it's ignored anyways it shouldn't harm for other filesystems.
135 mount -o remount,rw foo /mnt
140 if [ -x system/bin/sh ]; then
141 echo Running MirBSD Korn Shell...
142 USER="($1)" system/bin/sh -l 2>&1
144 echo Running busybox ash...
149 echo -n Detecting Android-x86...
151 [ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE`
152 [ -z "$RAMDISK" ] && RAMDISK=ramdisk.img || RAMDISK=${RAMDISK##/dev/}
154 for c in `cat /proc/cmdline`; do
158 eval `echo $c | cut -b1-3,18-`
165 mount -t tmpfs tmpfs /android
168 for device in ${ROOT:-/dev/[hmnsv][dmrv][0-9a-z]*}; do
169 check_root $device && break 2
170 mountpoint -q /mnt && umount /mnt
177 ln -s android/system /
178 ln -s ../system/lib/firmware ../system/lib/modules /lib
180 if [ -n "$INSTALL" ]; then
181 zcat /src/install.img | ( cd /; cpio -iud > /dev/null )
184 if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then
186 sed -i 's|\( PATH.*\)|\1:/bin|' init.environ.rc
188 busybox mv /sbin/* sbin
190 ln -s android/bin android/lib android/sbin /
195 for s in `ls /scripts/* /src/scripts/*`; do
196 test -e "$s" && source $s
199 # ensure keyboard driver is loaded
200 if [ -n "$INSTALL" -o -n "$DEBUG" ]; then
201 busybox modprobe -a atkbd hid-apple
205 if [ 0$DEBUG -gt 0 ]; then
206 echo -e "\nType 'exit' to continue booting...\n"
207 debug_shell debug-found
210 # A target should provide its detect_hardware function.
211 # On success, return 0 with the following values set.
212 # return 1 if it wants to use auto_detect
213 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
215 [ -n "$INSTALL" ] && do_install
224 if [ 0$DEBUG -gt 1 ]; then
225 echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
226 echo -e "Type 'exit' to enter Android...\n"
228 debug_shell debug-late
229 SETUPWIZARD=${SETUPWIZARD:-0}
232 [ "$SETUPWIZARD" = "0" ] && echo "ro.setupwizard.mode=DISABLED" >> default.prop
234 [ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot}
236 # We must disable mdev before switching to Android
237 # since it conflicts with Android's init
238 echo > /proc/sys/kernel/hotplug
240 export ANDROID_ROOT=/system
242 exec ${SWITCH:-switch_root} /android /init
247 echo ' Android-x86 console shell. Use only in emergencies.'
249 debug_shell fatal-err