linuxonandroid ubuntu12.04-v4-core启动文件(N7100 Android 4.3)
一. 测试环境
手机型号:三星 N7100 Android 4.3 已root,已禁用selinux(Permissive)
系统版本:linuxonandroid ubuntu12.04-v4-core
small和full应该也可以使用此脚本。安装教程:
http://jingyan.baidu.com/article/25648fc1db54c69191fd00e7.html
环境的搭建不再详述。
二. 修改后的bootscript4-3.sh
官网的脚本bootscript.sh,经本人测试,在N7100 Android4.3上有点小问题。
在官网的脚本基础上,修改网卡的接口为wlan0,修改了存储卡的名字为手机上显示的实际名字。测试可以正常使用。
全部代码如下:
@H_502_30@###########################################
@H_502_30@# Linux boot script V8.1 #
@H_502_30@# for N7100 Android v4.3 #
@H_502_30@# Built by Zachary Powell (zacthespack) #
@H_502_30@# and Martin Møller (Tuxling) #
@H_502_30@# Thanks to: #
@H_502_30@# Johan Vromans #
@H_502_30@# Marshall Levin #
@H_502_30@# Vaykadji
@H_502_30@# shile #
@H_502_30@# and to everyone at XDA! #
@H_502_30@# Feel free to edit/use this script as you#
@H_502_30@# like but credit Linuxonandroid.org #
@H_502_30@###########################################
@H_502_30@# $ver: V8.1 for N7100 Android v4.3 #
@H_502_30@###########################################
@H_502_30@###########################################
@H_502_30@# This is a function we use to stop the #
@H_502_30@# script in case of errors #
@H_502_30@###########################################
error_exit() {
echo "Error: $1"
exit 1
}
@H_502_30@###########################################
@H_502_30@# Set up variables #
@H_502_30@###########################################
if [ -f /data/data/com.zpwebsites.linuxonandroid/files/busyBox ]; then
export bBox=/data/data/com.zpwebsites.linuxonandroid/files/busyBox
elif [ -f /data/data/com.zpwebsites.linuxonandroid.opensource/files/busyBox ]; then
export bBox=/data/data/com.zpwebsites.linuxonandroid.opensource/files/busyBox
else
export bBox=/system/xbin/busyBox
fi
export usermounts=android @H_502_30@# Base folder all user mounts are done in,should be moved to app later
export imgfile=$(dirname $0)/ubuntu.img @H_502_30@# Default image file,another can be set by using an argument
export bin=/system/bin
export mnt=/data/local/mnt
export USER=root
if [[ ! -d $mnt ]]; then mkdir $mnt; fi
export PATH=$bin:/usr/bin:/usr/local/bin:/usr/sbin:/bin:/usr/local/sbin:/usr/games:$PATH
export TERM=linux
export HOME=/root
@H_502_30@###########################################
@H_502_30@# Handle arguments if present #
@H_502_30@###########################################
if [ $# -ne 0 ]; then
if [ -f $1 ]; then @H_502_30@# Is full path present?
imgfile=$1
elif [ -f $(dirname $0)/$1 ]; then @H_502_30@# Is only a filename present?
imgfile=$(dirname $0)/$1
else
error_exit "Image file not found!($1)"
fi
fi
@H_502_30@###########################################
@H_502_30@# If a md5 file is found we check it here #
@H_502_30@###########################################
if [ -f $imgfile.md5 ]; then
echo "MD5 file found,use to check .img file? (y/n)"
read answer
if [ $answer == y ]; then
echo -n "Validating image checksum... "
$bBox md5sum -c -s $imgfile.md5
if [ $? -ne 0 ];then
echo "Failed!"
error_exit "Checksum Failed! The image is corrupted!"
else
echo "OK"
rm $imgfile.md5
fi
fi
fi
@H_502_30@################################
@H_502_30@# Find and read config file #
@H_502_30@# or use defaults if not found #
@H_502_30@################################
use_swap=no
cfgfile=$imgfile.config @H_502_30@# Default config file if not specified
if [ -f $imgfile.config ]; then
source $imgfile.config
fi
@H_502_30@###########################################
@H_502_30@# Set Swap up if wanted #
@H_502_30@# #
@H_502_30@###########################################
if [ $use_swap == yes ]; then
if [ -f $imgfile.swap ]; then
echo "Swap file found,using file"
echo "Turning on swap (if it errors here you do not have swap support"
swapon $imgfile.swap
else
echo "Creating Swap file"
dd if=/dev/zero of=$imgfile.swap bs=1048576 count=1024
mkswap $imgfile.swap
echo "Turning on swap (if it errors here you do not have swap support"
swapon $imgfile.swap
fi
fi
@H_502_30@###########################################
@H_502_30@# Set up loop device and mount image #
@H_502_30@###########################################
echo -n "Checking loop device... "
if [ -b /dev/block/loop255 ]; then
echo "FOUND"
else
echo "MISSING"
@H_502_30@# Loop device not found so we create it and verify it was actually created
echo -n "Creating loop device... "
$bBox mknod /dev/block/loop255 b 7 255
if [ -b /dev/block/loop255 ]; then
echo "OK"
else
echo "Failed"
error_exit "Unable to create loop device!"
fi
fi
$bBox losetup /dev/block/loop255 $imgfile
if [ $? -ne 0 ];then error_exit "Unable to attach image to loop device! (Image = $imgfile)"; fi
$bBox mount -t ext4 /dev/block/loop255 $mnt
if [ $? -ne 0 ];then error_exit "Unable to mount the loop device!"; fi
@H_502_30@###########################################
@H_502_30@# Mount all required partitions #
@H_502_30@###########################################
$bBox mount -t devpts devpts $mnt/dev/pts
if [ $? -ne 0 ];then error_exit "Unable to mount $mnt/dev/pts!"; fi
$bBox mount -t proc proc $mnt/proc
if [ $? -ne 0 ];then error_exit "Unable to mount $mnt/proc!"; fi
$bBox mount -t sysfs sysfs $mnt/sys
if [ $? -ne 0 ];then error_exit "Unable to mount $mnt/sys!"; fi
$bBox mount -o bind /storage/emulated/0 $mnt/sdcard
if [ $? -ne 0 ];then error_exit "Unable to bind $mnt/sdcard!"; fi
if [[ ! -d $mnt/root/cfg ]]; then mkdir $mnt/root/cfg; fi
$bBox mount -o bind $(dirname $imgfile) $mnt/root/cfg
$bBox mount -o bind /sys/fs/selinux $mnt/selinux
@H_502_30@###########################################
@H_502_30@# Checks if you have a external sdcard #
@H_502_30@# and mounts it if you do #
@H_502_30@###########################################
if [ -d /sdcard/external_sd ]; then
$bBox mount -o bind /sdcard/external_sd $mnt/external_sd
fi
if [ -d /Removable/MicroSD ]; then
$bBox mount -o bind /Removable/MicroSD $mnt/external_sd
fi
@H_502_30@# 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.
if [[ ! -d $mnt/external_sd ]]; then mkdir $mnt/external_sd;fi
if [ -d /storage/extSdCard ]; then
$bBox mount -o bind /storage/extSdCard $mnt/external_sd
fi
@H_502_30@###########################################
@H_502_30@# Mount all user defined mounts if any #
@H_502_30@###########################################
if [ -f $imgfile.mounts ]; then
olddir=$(pwd)
echo "Mounting user mounts"
cd $mnt
if [[ ! -d $mnt/$usermounts ]]; then $bBox mkdir -p $usermounts; fi
echo "# Script to unmount user defined mounts,do not delete or edit!" > $imgfile.shutdown
echo "cd $mnt/$usermounts" > $imgfile.shutdown
cd $mnt/$usermounts
for entry in $(cat "$imgfile.mounts"); do
ANDROID=${entry%;*}
LINUX=${entry#*;}
if [[ -d $ANDROID ]]; then
echo -n "Mounting $ANDROID to $usermounts/$LINUX... "
if [[ ! -d $mnt/$usermounts/$LINUX ]]; then $bBox mkdir -p $LINUX; fi
$bBox mount -o bind $ANDROID $mnt/$usermounts/$LINUX &> /dev/null
if [ $? -ne 0 ];then
echo FAIL
if [[ -d $mnt/$usermounts/$LINUX ]]; then $bBox rmdir -p $LINUX; fi
else
echo OK
echo "$bBox umount $mnt/$usermounts/$LINUX" >> $imgfile.shutdown
echo "$bBox rmdir -p $LINUX" >> $imgfile.shutdown
fi
else
echo "Android folder not found: $ANDROID"
fi
done
echo "cd $mnt" >> $imgfile.shutdown
echo "$bBox rmdir -p $usermounts" >> $imgfile.shutdown
cd $olddir
else
echo "No user defined mount points"
fi
@H_502_30@###########################################
@H_502_30@# Sets up network forwarding #
@H_502_30@###########################################
$bBox sysctl -w net.ipv4.ip_forward=1
if [ $? -ne 0 ];then error_exit "Unable to forward network!"; fi
@H_502_30@# If NOT $mnt/root/DONOTDELETE.txt exists we setup hosts and resolv.conf now
if [ ! -f $mnt/root/DONOTDELETE.txt ]; then
echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
if [ $? -ne 0 ];then error_exit "Unable to write resolv.conf file!"; fi
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
echo "127.0.0.1 localhost" > $mnt/etc/hosts
if [ $? -ne 0 ];then error_exit "Unable to write hosts file!"; fi
fi
@H_502_30@###########################################
@H_502_30@# Chroot into ubuntu #
@H_502_30@###########################################
$bBox chroot $mnt /root/init.sh $(basename $imgfile)
@H_502_30@###########################################
@H_502_30@# Shut down ubuntu #
@H_502_30@###########################################
echo "Shutting down Linux ARM"
@H_502_30@#for pid in `lsof | grep $mnt | sed -e's/ / /g' | cut -d' ' -f2`; do kill -9 $pid >/dev/null 2>&1; done
for pid in `$bBox lsof | $bBox grep $mnt | $bBox sed -e's/ / /g' | $bBox cut -d' ' -f2`; do $bBox kill -9 $pid >/dev/null 2>&1; done
sleep 5
@H_502_30@###########################################
@H_502_30@# Unmount all user defined mounts if any #
@H_502_30@###########################################
if [ -f $imgfile.shutdown ]; then
echo "Unmounting user defined mounts"
sh $imgfile.shutdown
rm $imgfile.shutdown
fi
$bBox umount $mnt/root/cfg
$bBox umount $mnt/sdcard
$bBox umount $mnt/external_sd
$bBox umount $mnt/dev/pts
@H_502_30@#$bBox umount $mnt/dev
$bBox umount $mnt/proc
$bBox umount $mnt/sys
$bBox umount $mnt/selinux
$bBox umount $mnt
$bBox losetup -d /dev/block/loop255 &> /dev/null
三. 运行效果