OSDN Git Service

update messages
[android-x86/bootable-newinstaller.git] / initrd / init
1 #!/bin/busybox sh
2 #
3 # By Chih-Wei Huang <cwhuang@linux.org.tw>
4 # Last updated 2010/07/07
5 #
6 # License: GNU Public License
7 # We explicitely grant the right to use the scripts
8 # with Android-x86 project.
9 #
10
11 try_mount()
12 {
13         RW=$1; shift
14         # FIXME: any way to mount ntfs gracefully?
15         mount -o $RW $@ || mount.ntfs-3g -o rw,force $@
16 }
17
18 if [ -n "$DEBUG" ]; then
19         LOG=/tmp/log
20         set -x
21 else
22         LOG=/dev/null
23         [ -e $LOG ] || busybox mknod $LOG c 1 3
24 fi
25 exec 2> $LOG
26
27 busybox mount -t proc proc /proc
28 busybox mount -t sysfs sys /sys
29
30 busybox --install -s
31
32 export PATH=$PATH:/system/bin
33
34 if [ -n "$DEBUG" -o -n "$INSTALL" ]; then
35         mknod /dev/tty2 c 4 2 && openvt
36         mknod /dev/tty3 c 4 3 && openvt
37 else
38         echo 0 0 0 0 > /proc/sys/kernel/printk
39 fi
40
41 echo -n Detecting Android-x86...
42
43 while [ 1 ]; do
44         mdev -s
45
46         for device in /dev/sr* /dev/sd[a-z]*; do
47                 try_mount ro $device /mnt || continue
48                 cd /mnt/$SRC
49                 if [ ! -e ramdisk.img -o ! \( -e system.img -o -e system.sfs \) ]; then
50                         cd /
51                         umount /mnt
52                         continue
53                 fi
54                 mount -t tmpfs tmpfs /android
55                 cd /android
56                 zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
57                 if [ -e /mnt/$SRC/system.sfs ]; then
58                         mount -o loop /mnt/$SRC/system.sfs /sfs
59                         mount -o loop /sfs/system.img system
60                 else
61                         mount -o loop /mnt/$SRC/system.img system
62                 fi
63                 mkdir cache mnt mnt/sdcard
64                 mount -t tmpfs tmpfs cache
65                 echo " found at $device"
66                 break
67         done
68         mountpoint -q /android && break
69         sleep 1
70         echo -n .
71 done
72
73 ln -s android/system /
74
75 ln -s ../system/lib/modules /lib
76
77 if [ -n "$INSTALL" ]; then
78         cd /
79         zcat /mnt/$SRC/install.img | cpio -iud > /dev/null
80 fi
81
82 if [ -n "$DEBUG" -o -n "$BUSYBOX" ]; then
83         mv /bin /lib .
84         system/bin/ln -s android/lib /lib
85         system/bin/ln -s android/bin /bin
86         sed -i 's|\(PATH *\)\(/sbin\)|\1/bin:\2|;s|\(/system\)\(/bin/sh\)|\2|' init.rc
87         mv /sbin/* sbin
88         rmdir /sbin
89         ln -s android/sbin /
90 else
91         ln -s ../android/sbin/hotplug /sbin
92 fi
93
94 if [ -n "$DEBUG" ]; then
95         echo -e "\nType 'exit' to continue booting...\n"
96         sh
97 fi
98
99 # load scripts
100 for s in `ls /scripts/* /mnt/$SRC/scripts/*`; do
101         source $s
102 done
103
104 # A target should provide its detect_hardware function.
105 # On success, return 0 with the following values set.
106 #
107 # FB0DEV: framebuffer driver
108 # LANDEV: lan driver
109 # WIFDEV: wifi driver
110 # SNDDEV: sound driver
111 # CAMDEV: camera driver
112 # PREDEV: any module the drivers depend on but can't be loaded automatically
113 # EXTMOD: any other module
114
115 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
116
117 [ -n "$INSTALL" ] && do_install
118
119 load_modules
120 mount_data
121 mount_sdcard
122 setup_tslib
123
124 if [ -n "$DEBUG" ]; then
125         echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
126         echo -e "Type 'exit' to enter Android...\n"
127
128         # FIXME: all error messages in the shell are sent to $LOG
129         sh
130         chroot /android /init
131 else
132         exec switch_root /android /init
133 fi
134
135 sh # avoid kernel panic