X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=initrd%2Finit;h=32d6a4e4e2c4eda34fcf09b3e12a2ed8aa3a736b;hb=9c63ab239f8bc07860da29dfd74d14f144b14ab4;hp=5d747c54ca6ec6d523c0ff7d966095e053718a62;hpb=ff377d794eca9856b5dade764b8578d175f66162;p=android-x86%2Fbootable-newinstaller.git diff --git a/initrd/init b/initrd/init index 5d747c5..32d6a4e 100755 --- a/initrd/init +++ b/initrd/init @@ -3,7 +3,7 @@ # By Chih-Wei Huang # and Thorsten Glaser # -# Last updated 2011/08/18 +# Last updated 2017/04/23 # # License: GNU Public License # We explicitely grant the right to use the scripts @@ -36,10 +36,12 @@ if test x"$HAS_CTTY" != x"Yes"; then # create device nodes then spawn on them mknod /dev/tty2 c 4 2 && openvt mknod /dev/tty3 c 4 3 && openvt - else + fi + if test -z "$DEBUG" || test -n "$INSTALL"; then echo 0 0 0 0 > /proc/sys/kernel/printk fi # initialise /dev (first time) + mkdir -p /dev/block echo /sbin/mdev > /proc/sys/kernel/hotplug mdev -s # re-run this script with a controlling tty @@ -63,29 +65,52 @@ try_mount() RW="nolock,$RW" fi # FIXME: any way to mount ntfs gracefully? - mount -o $RW $@ || mount.ntfs-3g -o rw,force $@ + mount -o $RW,noatime $@ || mount.ntfs-3g -o rw,force $@ } check_root() { - try_mount ro $1 /mnt && [ -e /mnt/$SRC/ramdisk.img ] - [ $? -ne 0 ] && return 1 - zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null + if [ "`dirname $1`" = "/dev" ]; then + [ -e $1 ] || return 1 + blk=`basename $1` + [ ! -e /dev/block/$blk ] && ln $1 /dev/block + dev=/dev/block/$blk + else + dev=$1 + fi + try_mount ro $dev /mnt || return 1 + if [ -n "$iso" -a -e /mnt/$iso ]; then + mount --move /mnt /iso + mkdir /mnt/iso + mount -o loop /iso/$iso /mnt/iso + SRC=iso + fi + if [ -e /mnt/$SRC/$RAMDISK ]; then + zcat /mnt/$SRC/$RAMDISK | cpio -id > /dev/null + elif [ -b /dev/$RAMDISK ]; then + zcat /dev/$RAMDISK | cpio -id > /dev/null + else + return 1 + fi if [ -e /mnt/$SRC/system.sfs ]; then - mount -o loop /mnt/$SRC/system.sfs /sfs - mount -o loop /sfs/system.img system + mount -o loop,noatime /mnt/$SRC/system.sfs /sfs + mount -o loop,noatime /sfs/system.img system elif [ -e /mnt/$SRC/system.img ]; then - mount -o loop /mnt/$SRC/system.img system + remount_rw + mount -o loop,noatime /mnt/$SRC/system.img system elif [ -d /mnt/$SRC/system ]; then remount_rw mount --bind /mnt/$SRC/system system + elif [ -e /mnt/build.prop ]; then + mount --bind /mnt system else rm -rf * return 1 fi - mkdir cache mnt mnt/sdcard - mount -t tmpfs tmpfs cache + mkdir -p mnt echo " found at $1" + rm /sbin/mke2fs + hash -r } remount_rw() @@ -97,9 +122,9 @@ remount_rw() debug_shell() { - if which mksh >/dev/null 2>&1; then + if [ -x system/bin/sh ]; then echo Running MirBSD Korn Shell... - USER="($1)" mksh -l 2>&1 + USER="($1)" system/bin/sh -l 2>&1 else echo Running busybox ash... sh 2>&1 @@ -108,10 +133,23 @@ debug_shell() echo -n Detecting Android-x86... +[ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE` +[ -z "$RAMDISK" ] && RAMDISK=ramdisk.img || RAMDISK=${RAMDISK##/dev/} + +for c in `cat /proc/cmdline`; do + case $c in + iso-scan/filename=*) + eval `echo $c | cut -b1-3,18-` + ;; + *) + ;; + esac +done + mount -t tmpfs tmpfs /android cd /android while :; do - for device in ${ROOT:-/dev/sr* /dev/[hs]d[a-z]*}; do + for device in ${ROOT:-/dev/[hmsv][dmr][0-9a-z]*}; do check_root $device && break 2 mountpoint -q /mnt && umount /mnt done @@ -121,48 +159,38 @@ done ln -s mnt/$SRC /src ln -s android/system / -ln -s ../system/lib/modules /lib -ln -s ../system/lib/firmware /lib +ln -s ../system/lib/firmware ../system/lib/modules /lib if [ -n "$INSTALL" ]; then - cd / - zcat /src/install.img | cpio -iud > /dev/null + zcat /src/install.img | ( cd /; cpio -iud > /dev/null ) fi if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then mv /bin /lib . - system/bin/ln -s android/lib /lib - system/bin/ln -s android/bin /bin - sed -i 's|\(PATH *\)\(/sbin\)|\1/bin:\2|' init.rc - mv /sbin/* sbin + sed -i 's|\( PATH.*\)|\1:/bin|' init.environ.rc + rm /sbin/modprobe + busybox mv /sbin/* sbin rmdir /sbin - ln -s android/sbin / + ln -s android/bin android/lib android/sbin / + hash -r fi +# load scripts +for s in `ls /scripts/* /src/scripts/*`; do + test -e "$s" && source $s +done + # ensure keyboard driver is loaded -[ -n "$INSTALL" -o -n "$DEBUG" ] && modprobe atkbd +[ -n "$INSTALL" -o -n "$DEBUG" ] && auto_detect & -if [ -n "$DEBUG" ]; then +if [ 0$DEBUG -gt 0 ]; then echo -e "\nType 'exit' to continue booting...\n" debug_shell debug-found fi -# load scripts -for s in `ls /scripts/* /src/scripts/*`; do - test -e "$s" && source $s -done - # A target should provide its detect_hardware function. # On success, return 0 with the following values set. -# -# FB0DEV: framebuffer driver -# LANDEV: lan driver -# WIFDEV: wifi driver -# SNDDEV: sound driver -# CAMDEV: camera driver -# PREDEV: any module the drivers depend on but can't be loaded automatically -# EXTMOD: any other module - +# return 1 if it wants to use auto_detect [ "$AUTO" != "1" ] && detect_hardware && FOUND=1 [ -n "$INSTALL" ] && do_install @@ -174,18 +202,24 @@ setup_tslib setup_dpi post_detect -if [ -n "$DEBUG" ]; then +if [ 0$DEBUG -gt 1 ]; then echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles" echo -e "Type 'exit' to enter Android...\n" debug_shell debug-late - SWITCH=chroot + SETUPWIZARD=${SETUPWIZARD:-0} fi +[ "$SETUPWIZARD" = "0" ] && echo "ro.setupwizard.mode=DISABLED" >> default.prop + +[ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot} + # We must disable mdev before switching to Android # since it conflicts with Android's init echo > /proc/sys/kernel/hotplug +export ANDROID_ROOT=/system + exec ${SWITCH:-switch_root} /android /init # avoid kernel panic