OSDN Git Service

init: change debug shell to be mksh
[android-x86/bootable-newinstaller.git] / initrd / init
1 #!/bin/busybox sh
2 #
3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # and Thorsten Glaser <tg@mirbsd.org>
5 #
6 # Last updated 2011/01/01
7 #
8 # License: GNU Public License
9 # We explicitely grant the right to use the scripts
10 # with Android-x86 project.
11 #
12
13 PATH=/sbin:/bin:/system/bin:/system/xbin; export PATH
14
15 # configure debugging output
16 if [ -n "$DEBUG" ]; then
17         LOG=/tmp/log
18         set -x
19 else
20         LOG=/dev/null
21         test -e "$LOG" || busybox mknod $LOG c 1 3
22 fi
23 exec 2>> $LOG
24
25 # early boot
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
31         busybox --install -s
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
35                 mknod /dev/tty c 5 0
36                 # create device nodes then spawn on them
37                 mknod /dev/tty2 c 4 2 && openvt
38                 mknod /dev/tty3 c 4 3 && openvt
39         else
40                 echo 0 0 0 0 > /proc/sys/kernel/printk
41         fi
42         # initialise /dev (first time)
43         mdev -s
44         # re-run this script with a controlling tty
45         exec env HAS_CTTY=Yes setsid cttyhack /bin/sh "$0" "$@"
46 fi
47
48 # now running under a controlling tty; debug output from stderr into log file
49 # boot up Android
50
51 try_mount()
52 {
53         RW=$1; shift
54         # FIXME: any way to mount ntfs gracefully?
55         mount -o $RW $@ || mount.ntfs-3g -o rw,force $@
56 }
57
58 remount_rw()
59 {
60         mount -o remount,rw /mnt
61 }
62
63 debug_shell()
64 {
65         if which mksh >/dev/null 2>&1; then
66                 echo Running MirBSD Korn Shell...
67                 USER="($1)" mksh -l 2>&1
68         else
69                 echo Running busybox ash...
70                 sh 2>&1
71         fi
72 }
73
74 echo -n Detecting Android-x86...
75
76 while :; do
77         mdev -s
78
79         for device in /dev/sr* /dev/sd[a-z]*; do
80                 try_mount ro $device /mnt || continue
81                 cd /mnt/$SRC
82                 if [ ! -e ramdisk.img -o ! \( -e system.sfs -o -e system.img -o -d system \) ]; then
83                         cd /
84                         umount /mnt
85                         continue
86                 fi
87                 mount -t tmpfs tmpfs /android
88                 cd /android
89                 zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
90                 if [ -e /mnt/$SRC/system.sfs ]; then
91                         mount -o loop /mnt/$SRC/system.sfs /sfs
92                         mount -o loop /sfs/system.img system
93                 elif [ -e /mnt/$SRC/system.img ]; then
94                         mount -o loop /mnt/$SRC/system.img system
95                 else
96                         remount_rw
97                         mount --bind /mnt/$SRC/system system
98                 fi
99                 mkdir cache mnt mnt/sdcard
100                 mount -t tmpfs tmpfs cache
101                 echo " found at $device"
102                 break
103         done
104         mountpoint -q /android && break
105         sleep 1
106         echo -n .
107 done
108
109 ln -s android/system /
110
111 ln -s ../system/lib/modules /lib
112
113 if [ -n "$INSTALL" ]; then
114         cd /
115         zcat /mnt/$SRC/install.img | cpio -iud > /dev/null
116 fi
117
118 if [ -n "$DEBUG" -o -n "$BUSYBOX" ]; then
119         mv /bin /lib .
120         system/bin/ln -s android/lib /lib
121         system/bin/ln -s android/bin /bin
122         sed -i 's|\(PATH *\)\(/sbin\)|\1/bin:\2|' init.rc
123         mv /sbin/* sbin
124         rmdir /sbin
125         ln -s android/sbin /
126 fi
127
128 if [ -n "$DEBUG" ]; then
129         echo -e "\nType 'exit' to continue booting...\n"
130         debug_shell debug-found
131 fi
132
133 # load scripts
134 for s in `ls /scripts/* /mnt/$SRC/scripts/*`; do
135         test -e "$s" && source $s
136 done
137
138 # A target should provide its detect_hardware function.
139 # On success, return 0 with the following values set.
140 #
141 # FB0DEV: framebuffer driver
142 # LANDEV: lan driver
143 # WIFDEV: wifi driver
144 # SNDDEV: sound driver
145 # CAMDEV: camera driver
146 # PREDEV: any module the drivers depend on but can't be loaded automatically
147 # EXTMOD: any other module
148
149 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
150
151 [ -n "$INSTALL" ] && do_install
152
153 load_modules
154 mount_data
155 mount_sdcard
156 setup_tslib
157 post_detect
158
159 if [ -n "$DEBUG" ]; then
160         echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
161         echo -e "Type 'exit' to enter Android...\n"
162
163         debug_shell debug-late
164         exec chroot /android /init
165 else
166         exec switch_root /android /init
167 fi
168
169 # avoid kernel panic
170 while :; do
171         echo
172         echo '  Android-x86 console shell. Use only in emergencies.'
173         echo
174         debug_shell fatal-err
175 done