3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # and Thorsten Glaser <tg@mirbsd.org>
6 # Last updated 2011/08/18
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)
44 echo /sbin/mdev > /proc/sys/kernel/hotplug
46 # re-run this script with a controlling tty
47 exec env HAS_CTTY=Yes setsid cttyhack /bin/sh "$0" "$@"
50 # now running under a controlling tty; debug output from stderr into log file
62 if [ "${ROOT#*:/}" != "$ROOT" ]; then
63 # for NFS roots, use nolock to avoid dependency to portmapper
66 # FIXME: any way to mount ntfs gracefully?
67 mount -o $RW $@ || mount.ntfs-3g -o rw,force $@
72 try_mount ro $1 /mnt && [ -e /mnt/$SRC/ramdisk.img ]
73 [ $? -ne 0 ] && return 1
74 zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
75 if [ -e /mnt/$SRC/system.sfs ]; then
76 mount -o loop /mnt/$SRC/system.sfs /sfs
77 mount -o loop /sfs/system.img system
78 elif [ -e /mnt/$SRC/system.img ]; then
79 mount -o loop /mnt/$SRC/system.img system
80 elif [ -d /mnt/$SRC/system ]; then
82 mount --bind /mnt/$SRC/system system
87 mkdir cache mnt mnt/sdcard
88 mount -t tmpfs tmpfs cache
94 # "foo" as mount source is given to workaround a Busybox bug with NFS
95 # - as it's ignored anyways it shouldn't harm for other filesystems.
96 mount -o remount,rw foo /mnt
101 if which mksh >/dev/null 2>&1; then
102 echo Running MirBSD Korn Shell...
103 USER="($1)" mksh -l 2>&1
105 echo Running busybox ash...
110 echo -n Detecting Android-x86...
112 mount -t tmpfs tmpfs /android
115 for device in ${ROOT:-/dev/sr* /dev/[hs]d[a-z]*}; do
116 check_root $device && break 2
117 mountpoint -q /mnt && umount /mnt
124 ln -s android/system /
125 ln -s ../system/lib/modules /lib
126 ln -s ../system/lib/firmware /lib
128 if [ -n "$INSTALL" ]; then
130 zcat /src/install.img | cpio -iud > /dev/null
133 if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then
135 system/bin/ln -s android/lib /lib
136 system/bin/ln -s android/bin /bin
137 sed -i 's|\(PATH *\)\(/sbin\)|\1/bin:\2|' init.rc
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