linuxonandroid ubuntu12.04-v4-core启动文件(N7100 Android 4.3)

前端之家收集整理的这篇文章主要介绍了linuxonandroid ubuntu12.04-v4-core启动文件(N7100 Android 4.3)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

linuxonandroid ubuntu12.04-v4-core启动文件(N7100 Android 4.3)

一. 测试环境

环境的搭建不再详述。

二. 修改后的bootscript4-3.sh

官网的脚本bootscript.sh,经本人测试,在N7100 Android4.3上有点小问题。
在官网的脚本基础上,修改网卡的接口为wlan0,修改了存储卡的名字为手机上显示的实际名字。测试可以正常使用。
全部代码如下:

###########################################@H_301_31@
# Linux boot script V8.1 #@H_301_31@
# for N7100 Android v4.3 #@H_301_31@
# Built by Zachary Powell (zacthespack) #@H_301_31@
# and Martin Møller (Tuxling) #@H_301_31@
# Thanks to: #@H_301_31@
# Johan Vromans #@H_301_31@
# Marshall Levin #@H_301_31@
# Vaykadji@H_301_31@
# shile #@H_301_31@
# and to everyone at XDA! #@H_301_31@
# Feel free to edit/use this script as you#@H_301_31@
# like but credit Linuxonandroid.org #@H_301_31@
###########################################@H_301_31@
# $ver: V8.1 for N7100 Android v4.3 #@H_301_31@
###########################################@H_301_31@


###########################################@H_301_31@
# This is a function we use to stop the #@H_301_31@
# script in case of errors #@H_301_31@
###########################################@H_301_31@
error_exit@H_301_31@@H_301_31@() {
    echo@H_301_31@ "Error: $1@H_301_31@"@H_301_31@
    exit@H_301_31@ 1@H_301_31@
}


###########################################@H_301_31@
# Set up variables #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ -f@H_301_31@ /data/data/com.zpwebsites.linuxonandroid/files/busyBox ]; then@H_301_31@
        export@H_301_31@ bBox=/data/data/com.zpwebsites.linuxonandroid/files/busyBox
elif@H_301_31@ [ -f@H_301_31@ /data/data/com.zpwebsites.linuxonandroid.opensource/files/busyBox ]; then@H_301_31@
        export@H_301_31@ bBox=/data/data/com.zpwebsites.linuxonandroid.opensource/files/busyBox
else@H_301_31@
    export@H_301_31@ bBox=/system/xbin/busyBox
fi@H_301_31@

export@H_301_31@ usermounts=android   # Base folder all user mounts are done in,should be moved to app later@H_301_31@
export@H_301_31@ imgfile=$(dirname $0@H_301_31@)/ubuntu.img    # Default image file,another can be set by using an argument@H_301_31@
export@H_301_31@ bin=/system/bin
export@H_301_31@ mnt=/data/local/mnt
export@H_301_31@ USER=root
if@H_301_31@ [[ ! -d@H_301_31@ $mnt@H_301_31@ ]]; then@H_301_31@ mkdir $mnt@H_301_31@; fi@H_301_31@
export@H_301_31@ PATH=$bin@H_301_31@:/usr/bin:/usr/local/bin:/usr/sbin:/bin:/usr/local/sbin:/usr/games:$PATH@H_301_31@
export@H_301_31@ TERM=linux
export@H_301_31@ HOME=/root

###########################################@H_301_31@
# Handle arguments if present #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ $#@H_301_31@ -ne@H_301_31@ 0@H_301_31@ ]; then@H_301_31@
    if@H_301_31@ [ -f@H_301_31@ $1@H_301_31@ ]; then@H_301_31@ # Is full path present?@H_301_31@
        imgfile=$1@H_301_31@

    elif@H_301_31@ [ -f@H_301_31@ $(dirname $0@H_301_31@)/$1@H_301_31@ ]; then@H_301_31@ # Is only a filename present?@H_301_31@
        imgfile=$(dirname $0@H_301_31@)/$1@H_301_31@

    else@H_301_31@
        error_exit@H_301_31@ "Image file not found!($1@H_301_31@)"@H_301_31@
    fi@H_301_31@
fi@H_301_31@

###########################################@H_301_31@
# If a md5 file is found we check it here #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ -f@H_301_31@ $imgfile@H_301_31@.md5 ]; then@H_301_31@
        echo@H_301_31@ "MD5 file found,use to check .img file? (y/n)"@H_301_31@
    read@H_301_31@ answer
    if@H_301_31@ [ $answer@H_301_31@ == y ]; then@H_301_31@
         echo@H_301_31@ -n "Validating image checksum... "@H_301_31@
             $bBox@H_301_31@ md5sum -c -s@H_301_31@ $imgfile@H_301_31@.md5
             if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@
                  echo@H_301_31@ "Failed!"@H_301_31@
                  error_exit@H_301_31@ "Checksum Failed! The image is corrupted!"@H_301_31@
             else@H_301_31@
                  echo@H_301_31@ "OK"@H_301_31@
                  rm $imgfile@H_301_31@.md5
             fi@H_301_31@
    fi@H_301_31@

fi@H_301_31@
################################@H_301_31@
# Find and read config file #@H_301_31@
# or use defaults if not found #@H_301_31@
################################@H_301_31@
use_swap=no

cfgfile=$imgfile@H_301_31@.config # Default config file if not specified@H_301_31@

if@H_301_31@ [ -f@H_301_31@ $imgfile@H_301_31@.config ]; then@H_301_31@
    source@H_301_31@ $imgfile@H_301_31@.config
fi@H_301_31@

###########################################@H_301_31@
# Set Swap up if wanted #@H_301_31@
# #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ $use_swap@H_301_31@ == yes ]; then@H_301_31@
    if@H_301_31@ [ -f@H_301_31@ $imgfile@H_301_31@.swap ]; then@H_301_31@
        echo@H_301_31@ "Swap file found,using file"@H_301_31@
        echo@H_301_31@ "Turning on swap (if it errors here you do not have swap support"@H_301_31@
        swapon $imgfile@H_301_31@.swap

    else@H_301_31@
        echo@H_301_31@ "Creating Swap file"@H_301_31@
        dd if@H_301_31@=/dev/zero of=$imgfile@H_301_31@.swap bs=1048576@H_301_31@ count=1024@H_301_31@
        mkswap $imgfile@H_301_31@.swap
        echo@H_301_31@ "Turning on swap (if it errors here you do not have swap support"@H_301_31@
        swapon $imgfile@H_301_31@.swap

    fi@H_301_31@
fi@H_301_31@
###########################################@H_301_31@
# Set up loop device and mount image #@H_301_31@
###########################################@H_301_31@
echo@H_301_31@ -n "Checking loop device... "@H_301_31@
if@H_301_31@ [ -b /dev/block/loop255 ]; then@H_301_31@
    echo@H_301_31@ "FOUND"@H_301_31@
else@H_301_31@
    echo@H_301_31@ "MISSING"@H_301_31@
    # Loop device not found so we create it and verify it was actually created@H_301_31@
    echo@H_301_31@ -n "Creating loop device... "@H_301_31@
    $bBox@H_301_31@ mknod /dev/block/loop255 b 7@H_301_31@ 255@H_301_31@
    if@H_301_31@ [ -b /dev/block/loop255 ]; then@H_301_31@
        echo@H_301_31@ "OK"@H_301_31@
    else@H_301_31@
        echo@H_301_31@ "Failed"@H_301_31@
        error_exit@H_301_31@ "Unable to create loop device!"@H_301_31@
    fi@H_301_31@
fi@H_301_31@

$bBox@H_301_31@ losetup /dev/block/loop255 $imgfile@H_301_31@
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to attach image to loop device! (Image = $imgfile@H_301_31@)"@H_301_31@; fi@H_301_31@

$bBox@H_301_31@ mount -t ext4 /dev/block/loop255 $mnt@H_301_31@
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to mount the loop device!"@H_301_31@; fi@H_301_31@

###########################################@H_301_31@
# Mount all required partitions #@H_301_31@
###########################################@H_301_31@
$bBox@H_301_31@ mount -t devpts devpts $mnt@H_301_31@/dev/pts
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to mount $mnt@H_301_31@/dev/pts!"@H_301_31@; fi@H_301_31@
$bBox@H_301_31@ mount -t proc proc $mnt@H_301_31@/proc
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to mount $mnt@H_301_31@/proc!"@H_301_31@; fi@H_301_31@
$bBox@H_301_31@ mount -t sysfs sysfs $mnt@H_301_31@/sys
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to mount $mnt@H_301_31@/sys!"@H_301_31@; fi@H_301_31@
$bBox@H_301_31@ mount -o bind@H_301_31@ /storage/emulated/0@H_301_31@ $mnt@H_301_31@/sdcard
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to bind $mnt@H_301_31@/sdcard!"@H_301_31@; fi@H_301_31@

if@H_301_31@ [[ ! -d@H_301_31@ $mnt@H_301_31@/root/cfg ]]; then@H_301_31@ mkdir $mnt@H_301_31@/root/cfg; fi@H_301_31@
$bBox@H_301_31@ mount -o bind@H_301_31@ $(dirname $imgfile@H_301_31@) $mnt@H_301_31@/root/cfg

$bBox@H_301_31@ mount -o bind@H_301_31@ /sys/fs/selinux $mnt@H_301_31@/selinux

###########################################@H_301_31@
# Checks if you have a external sdcard #@H_301_31@
# and mounts it if you do #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ -d@H_301_31@ /sdcard/external_sd ]; then@H_301_31@
    $bBox@H_301_31@ mount -o bind@H_301_31@ /sdcard/external_sd  $mnt@H_301_31@/external_sd
fi@H_301_31@
if@H_301_31@ [ -d@H_301_31@ /Removable/MicroSD ]; then@H_301_31@
    $bBox@H_301_31@ mount -o bind@H_301_31@ /Removable/MicroSD  $mnt@H_301_31@/external_sd
fi@H_301_31@
# This is for the HD version of the Archos 70 internet tablet,may be the same for the SD card edition but i dont know.@H_301_31@

if@H_301_31@ [[ ! -d@H_301_31@ $mnt@H_301_31@/external_sd ]]; then@H_301_31@ mkdir $mnt@H_301_31@/external_sd;fi@H_301_31@
if@H_301_31@ [ -d@H_301_31@ /storage/extSdCard ]; then@H_301_31@
    $bBox@H_301_31@ mount -o bind@H_301_31@ /storage/extSdCard  $mnt@H_301_31@/external_sd
fi@H_301_31@

###########################################@H_301_31@
# Mount all user defined mounts if any #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ -f@H_301_31@ $imgfile@H_301_31@.mounts ]; then@H_301_31@
    olddir=$(pwd@H_301_31@)
    echo@H_301_31@ "Mounting user mounts"@H_301_31@

    cd@H_301_31@ $mnt@H_301_31@
    if@H_301_31@ [[ ! -d@H_301_31@ $mnt@H_301_31@/$usermounts@H_301_31@ ]]; then@H_301_31@ $bBox@H_301_31@ mkdir -p $usermounts@H_301_31@; fi@H_301_31@

    echo@H_301_31@ "# Script to unmount user defined mounts,do not delete or edit!"@H_301_31@ > $imgfile@H_301_31@.shutdown
    echo@H_301_31@ "cd $mnt@H_301_31@/$usermounts@H_301_31@"@H_301_31@ > $imgfile@H_301_31@.shutdown

    cd@H_301_31@ $mnt@H_301_31@/$usermounts@H_301_31@
    for@H_301_31@ entry in@H_301_31@ $(cat "$imgfile@H_301_31@.mounts"@H_301_31@); do@H_301_31@
        ANDROID=${entry%;*}@H_301_31@
        LINUX=${entry#*;}@H_301_31@

        if@H_301_31@ [[ -d@H_301_31@ $ANDROID@H_301_31@ ]]; then@H_301_31@
            echo@H_301_31@ -n "Mounting $ANDROID@H_301_31@ to $usermounts@H_301_31@/$LINUX@H_301_31@... "@H_301_31@
            if@H_301_31@ [[ ! -d@H_301_31@ $mnt@H_301_31@/$usermounts@H_301_31@/$LINUX@H_301_31@ ]]; then@H_301_31@ $bBox@H_301_31@ mkdir -p $LINUX@H_301_31@; fi@H_301_31@
            $bBox@H_301_31@ mount -o bind@H_301_31@ $ANDROID@H_301_31@ $mnt@H_301_31@/$usermounts@H_301_31@/$LINUX@H_301_31@ &> /dev/null
            if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@
                echo@H_301_31@ FAIL
                if@H_301_31@ [[ -d@H_301_31@ $mnt@H_301_31@/$usermounts@H_301_31@/$LINUX@H_301_31@ ]]; then@H_301_31@ $bBox@H_301_31@ rmdir -p $LINUX@H_301_31@; fi@H_301_31@
            else@H_301_31@
                echo@H_301_31@ OK
                echo@H_301_31@ "$bBox@H_301_31@ umount $mnt@H_301_31@/$usermounts@H_301_31@/$LINUX@H_301_31@"@H_301_31@ >> $imgfile@H_301_31@.shutdown
                echo@H_301_31@ "$bBox@H_301_31@ rmdir -p $LINUX@H_301_31@"@H_301_31@ >> $imgfile@H_301_31@.shutdown
            fi@H_301_31@
        else@H_301_31@
            echo@H_301_31@ "Android folder not found: $ANDROID@H_301_31@"@H_301_31@
        fi@H_301_31@
    done@H_301_31@
    echo@H_301_31@ "cd $mnt@H_301_31@"@H_301_31@ >> $imgfile@H_301_31@.shutdown
    echo@H_301_31@ "$bBox@H_301_31@ rmdir -p $usermounts@H_301_31@"@H_301_31@ >> $imgfile@H_301_31@.shutdown
    cd@H_301_31@ $olddir@H_301_31@

else@H_301_31@
    echo@H_301_31@ "No user defined mount points"@H_301_31@
fi@H_301_31@

###########################################@H_301_31@
# Sets up network forwarding #@H_301_31@
###########################################@H_301_31@
$bBox@H_301_31@ sysctl -w net.ipv4.ip_forward=1@H_301_31@
if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to forward network!"@H_301_31@; fi@H_301_31@

# If NOT $mnt/root/DONOTDELETE.txt exists we setup hosts and resolv.conf now@H_301_31@
if@H_301_31@ [ ! -f@H_301_31@ $mnt@H_301_31@/root/DONOTDELETE.txt ]; then@H_301_31@
    echo@H_301_31@ "nameserver 8.8.8.8"@H_301_31@ > $mnt@H_301_31@/etc/resolv.conf
    if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to write resolv.conf file!"@H_301_31@; fi@H_301_31@
    echo@H_301_31@ "nameserver 8.8.4.4"@H_301_31@ >> $mnt@H_301_31@/etc/resolv.conf
    echo@H_301_31@ "127.0.0.1 localhost"@H_301_31@ > $mnt@H_301_31@/etc/hosts
    if@H_301_31@ [ $? -ne@H_301_31@ 0@H_301_31@ ];then@H_301_31@ error_exit@H_301_31@ "Unable to write hosts file!"@H_301_31@; fi@H_301_31@
fi@H_301_31@


###########################################@H_301_31@
# Chroot into ubuntu #@H_301_31@
###########################################@H_301_31@
$bBox@H_301_31@ chroot $mnt@H_301_31@ /root/init.sh $(basename $imgfile@H_301_31@)

###########################################@H_301_31@
# Shut down ubuntu #@H_301_31@
###########################################@H_301_31@
echo@H_301_31@ "Shutting down Linux ARM"@H_301_31@
#for pid in `lsof | grep $mnt | sed -e's/ / /g' | cut -d' ' -f2`; do kill -9 $pid >/dev/null 2>&1; done@H_301_31@
for@H_301_31@ pid in@H_301_31@ `$bBox@H_301_31@ lsof | $bBox@H_301_31@ grep $mnt@H_301_31@ | $bBox@H_301_31@ sed -e@H_301_31@'s/ / /g'@H_301_31@ | $bBox@H_301_31@ cut -d@H_301_31@' '@H_301_31@ -f@H_301_31@2`; do@H_301_31@ $bBox@H_301_31@ kill -9@H_301_31@ $pid@H_301_31@ >/dev/null 2@H_301_31@>&1@H_301_31@; done@H_301_31@
sleep 5@H_301_31@

###########################################@H_301_31@
# Unmount all user defined mounts if any #@H_301_31@
###########################################@H_301_31@
if@H_301_31@ [ -f@H_301_31@ $imgfile@H_301_31@.shutdown ]; then@H_301_31@
    echo@H_301_31@ "Unmounting user defined mounts"@H_301_31@
    sh $imgfile@H_301_31@.shutdown
    rm $imgfile@H_301_31@.shutdown
fi@H_301_31@

$bBox@H_301_31@ umount $mnt@H_301_31@/root/cfg
$bBox@H_301_31@ umount $mnt@H_301_31@/sdcard
$bBox@H_301_31@ umount $mnt@H_301_31@/external_sd
$bBox@H_301_31@ umount $mnt@H_301_31@/dev/pts
#$bBox umount $mnt/dev@H_301_31@
$bBox@H_301_31@ umount $mnt@H_301_31@/proc
$bBox@H_301_31@ umount $mnt@H_301_31@/sys
$bBox@H_301_31@ umount $mnt@H_301_31@/selinux
$bBox@H_301_31@ umount $mnt@H_301_31@
$bBox@H_301_31@ losetup -d@H_301_31@ /dev/block/loop255 &> /dev/null

三. 运行效果

猜你在找的Ubuntu相关文章