Ubuntu目前有个项目叫Ubuntu for Android(http://www.ubuntu.com/devices/android),看起来非常cool:
它的原理在http://www.ubuntu.com/devices/android并无介绍。但是我们猜测可以用chroot配合实现一个最简单的Ubuntu for Android。
我们为Andriod编写一个脚本Ubuntu.sh,在该脚本中启动Ubuntu的文件系统,透过chroot进行:
#!/system/bin/shif [ `id -u` != "0" ]thenecho -e "\033[33m Becoming root \033[0m"su -c buexit 1fiecho -e "\033[33m Setting some stuff up..\033[0m "export bin=/system/binexport mnt=/data/local/ubuntuexport PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATHexport TERM=linuxexport HOME=/rootif [ ! -d $mnt ]thenmkdir $mntfiecho -e "\033[33m Mounting the Linux Image \033[0m"#replace /dev/block/mmcblk1p2 by the partition Ubuntu p_w_picpath is replaced#it might be a loop p_w_picpathbusybox mount -t ext4 -o noatime,nodiratime /dev/block/mmcblk1p2 $mntbusybox mount -t devpts devpts $mnt/dev/ptsbusybox mount -t proc proc $mnt/procbusybox mount -t sysfs sysfs $mnt/sysecho -e "\033[33m Setting Up Networking\033[0m"sysctl -w net.ipv4.ip_forward=1echo "nameserver 8.8.8.8" >> $mnt/etc/resolv.confecho "nameserver 8.8.4.4" >> $mnt/etc/resolv.confecho "127.0.0.1 localhost" > $mnt/etc/hostsecho -e "\033[33m Mounting sdcard in /mnt/sdcard\033[0m"if [ ! -d $mnt/mnt/sdcard ]thenmkdir $mnt/mnt/sdcardfibusybox mount --bind /mnt/sdcard/ $mnt/mnt/sdcardecho -e "\033[33m Entering CHROOT \033[0m"echo " "chroot $mnt /bin/bashecho " "echo -e "\033[33m Shutting down CHROOT\033[0m"echo -e "\033[33m umount $mnt/mnt/sdcard\033[0m"busybox umount $mnt/mnt/sdcardsysctl -w net.ipv4.ip_forward=0echo -e "\033[33m umount $mnt/dev/pts\033[0m"busybox umount $mnt/dev/ptsecho -e "\033[33m umount $mnt/proc\033[0m"busybox umount $mnt/procecho -e "\033[33m umount $mnt/sys\033[0m"busybox umount $mnt/sysecho -e "\033[33m umount $mnt\033[0m"busybox fuser -k $mntbusybox umount $mnt
其中的一行:
busybox mount -t ext4 -o noatime,nodiratime /dev/block/mmcblk1p2 $mnt
是为了mount Ubuntu的rootfs,我们的实验中Ubuntu的rootfs存放在/dev/block/mmcblk1p2。该文件系统通过rootstack得到:
sudo rootstock -f ubuntu -l <yourname> -p <yourpassword> -i 1G --seed linux-p_w_picpath-omap,build-essential,tightvncserver, lxde
将得到的tgz包解压到我们sd卡的分区2。
运行Ubuntu.sh,进入到了Ubuntu的根文件系统,并执行了bash,之后我们开一个vncserver:
export USER=rootvncserver -geometry 800x480
在Android端,通过VNCClient软件连接到127.0.0.1:5901即可。