3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # and Thorsten Glaser <tg@mirbsd.org>
6 # Last updated 2014/01/15
8 # License: GNU Public License
9 # We explicitely grant the right to use the scripts
10 # with Android-x86 project.
13 PATH=/sbin:/bin; 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
67 # FIXME: any way to mount ntfs gracefully?
68 mount -o $RW $@ || mount.ntfs-3g -o rw,force $@
73 if [ "`dirname $1`" = "/dev" ]; then
76 [ ! -e /dev/block/$blk ] && ln $1 /dev/block
81 try_mount ro $dev /mnt && [ -e /mnt/$SRC/ramdisk.img ]
82 [ $? -ne 0 ] && return 1
83 zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
84 if [ -e /mnt/$SRC/system.sfs ]; then
85 mount -o loop /mnt/$SRC/system.sfs /sfs
86 mount -o loop /sfs/system.img system
87 elif [ -e /mnt/$SRC/system.img ]; then
89 mount -o loop /mnt/$SRC/system.img system
90 elif [ -d /mnt/$SRC/system ]; then
92 mount --bind /mnt/$SRC/system system
98 mount -t tmpfs tmpfs cache
104 # "foo" as mount source is given to workaround a Busybox bug with NFS
105 # - as it's ignored anyways it shouldn't harm for other filesystems.
106 mount -o remount,rw foo /mnt
111 if which mksh >/dev/null 2>&1; then
112 echo Running MirBSD Korn Shell...
113 USER="($1)" mksh -l 2>&1
115 echo Running busybox ash...
120 echo -n Detecting Android-x86...
122 mount -t tmpfs tmpfs /android
125 for device in ${ROOT:-/dev/[hmsv][dmr][0-9a-z]*}; do
126 check_root $device && break 2
127 mountpoint -q /mnt && umount /mnt
134 ln -s android/system /
135 ln -s ../system/lib/modules /lib
136 ln -s ../system/lib/firmware /lib
138 if [ -n "$INSTALL" ]; then
140 zcat /src/install.img | cpio -iud > /dev/null
143 # ensure keyboard driver is loaded
144 [ -n "$INSTALL" -o -n "$DEBUG" ] && modprobe atkbd
146 if [ 0$DEBUG -gt 0 ]; then
147 echo -e "\nType 'exit' to continue booting...\n"
148 debug_shell debug-found
152 for s in `ls /scripts/* /src/scripts/*`; do
153 test -e "$s" && source $s
156 # A target should provide its detect_hardware function.
157 # On success, return 0 with the following values set.
158 # return 1 if it wants to use auto_detect
159 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
161 [ -n "$INSTALL" ] && do_install
169 find_network_dev_name
171 if [ 0$DEBUG -gt 1 ]; then
172 echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
173 echo -e "Type 'exit' to enter Android...\n"
175 debug_shell debug-late
178 [ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot}
180 # We must disable mdev before switching to Android
181 # since it conflicts with Android's init
182 echo > /proc/sys/kernel/hotplug
184 exec ${SWITCH:-switch_root} /android /init
189 echo ' Android-x86 console shell. Use only in emergencies.'
191 debug_shell fatal-err