​在安卓手机上运行 Ubuntu 14.04(中兴N881F)​

1、简介

首先,如果您对Android和Linux系统不熟悉,或者只是想做测试,建议借助一些成熟的app来实现,您只要在手 机上安装一个类似的app,运行后在其指引下进行安装设置,即可轻松搞掂。各app一般均可选择要安装的Linux发行版本 (Ubuntu,Debian,ArchLinux, Kali Linux,Fedora,openSUSE)和桌面环境((LXDE,Xfce,GNOME),使用者可根据自己手机的硬件配置进行选择。

警告:此文中所列软件没有任何担保,笔者也不对使用它的任何后果承担责任。非专业人士建议在闲置或淘汰的的手机上进行测试。

a、需要 root 手机 的app:

b、不需要 root 手机的 app:

2、自制映像文件(image)

2.1准备
已经 root 的手机,SD卡上有4GB以上的空闲空间
Terminal Emulator (终端模拟器) :用于提供 shell 命令的支持
Android VNC Viewer:用于 Android 设备的远程连接工具
Linux 系统环境 - 我的系统是Vmware环境下的 Ubuntu 14.04 LTS 虚拟机
手机内含busybox软件,如没有可安装:BusyBox。我用的手机是中兴N881F,busybox安装位置为/system/xbin。
2.2 创建操作系统映像
a、在ubuntu 系统上安装debootstrap:
# sudo apt-get install debootstrap
b、在具有足够空间的分区建立目录:
# mkdir /media/ubuntu
# cd /media/ubuntu
c、创建约3.8GB大小的空磁盘映像文件:
# dd if=/dev/zero of=ubuntu.img bs=8k count=458752
# sudo mkfs.ext4 -L chroot -c ubuntu.img
# sudo tune2fs -c 0 ubuntu.img
如果创建2GB左右的,改一下count数值如下:
# dd if=/dev/zero of=ubuntu.img bs=8k count=262144
d、将新创建的文件系统挂载到chroot:
# mkdir chroot
# sudo mount -o loop ubuntu.img chroot
e、开始下载核心系统文件。
# sudo debootstrap --arch armhf --foreign trusty chroot <a href="http://ports.ubuntu.com/">http://ports.ubuntu.com/</a>
f、这个过程较为耗时……。等待至下载完成之后,卸载文件系统:
# cd ../../
# sudo umount chroot
g、然后把 ubuntu.img复制到手机上。中兴N881F可复制到“/sdcard2/ubuntu” 目录。在ubuntu主机上操作:
# root@ubuntu:/media/ubuntu
# adb devices
List of devices attached 
ZTE-N881F       device
# root@ubuntu:/media/ubuntu# adb push ubuntu.img /sdcard2/ubuntu

3、在手机上进行设置
使ubuntu系统“运行”,并安装所需要的软件包。
a、首先,运行终端模拟器(也可以在宿主机上 adb shell),运行命令
# su
# cd /sdcard2/ubuntu
b、在终端模拟器中运行以下脚本,chroot到 ubuntu环境。这个脚本是在Zachary Powell (zacthespack) V6.1的基础上修改简化的。
##########################################
#Ubuntu boot script V6.1 for Android    
#Built by Zachary Powell (zacthespack)   
#Thanks to:                      
#Johan (sciurius)                 
#Marshall Levin                  
#and to everyone at XDA!           
##########################################
#Check for root                 
##########################################
perm=$(id|cut -b 5)
if [ "$perm" != "0" ];then echo "This script requires root! Type: su"; exit; fi
mount -o remount,rw /dev/block/mmcblk0p5 /system
##########################################
#Set up veriables                 
##########################################
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:/system/xbin:/usr/local/sbin:/usr/
export TERM=linux
export HOME=/root
##########################################
#Set up loop device               
##########################################
if [ -b /dev/block/loop255 ]; then
  echo "Loop device exists"
else
  busybox mknod /dev/block/loop255 b 7 255
fi
busybox losetup /dev/block/loop255 ubuntu.img
##########################################
#Mount all required partitions       
##########################################
busybox mount -t ext4 /dev/block/loop255 $mnt
busybox mount -t devpts devpts $mnt/dev/pts
busybox mount -t proc proc $mnt/proc
busybox mount -t sysfs sysfs $mnt/sys                                     
##########################################                                            
#Chroot into ubuntu                                                       
##########################################                                            
busybox chroot $mnt /bin/bash  
##########################################                                            
#Shut down ubuntu                 
##########################################                                            
echo "Shutting down Ubuntu ARM"                                                       
for pid in `lsof | grep $mnt | sed -e's/  / /g' | cut -d' ' -f2`; do kill -9 $pid >/dev/nu
sleep 5                                                                                   
umount $mnt/sdcard                                                                        
umount $mnt/external_sd                                                                   
umount $mnt/dev/pts                                                                       
umount $mnt/proc                                                                          
umount $mnt/sys                                                                           
umount $mnt
c、进行 debootstrap 第二阶段安装:
I have no name!@localhost:/# /debootstrap/debootstrap --second-stage
d、添加中文字符集,设置时区
I have no name!@localhost:/# sudo locale-gen zh_CN.utf8   #添加中文字符集
I have no name!@localhost:/# dpkg-reconfigure tzdata         #设置时区为Asia/Shanghai
如果时区设置命令执行出错,也可以直接复制相应文件:
I have no name!@localhost:/#sudo cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime
/usr/share/zoneinfo/Asia/Shangai 文件有点问题,可以用 Chongqing 或Hong-Kong等代替
I have no name!@localhost:/# sudo ntpdate time.windows.com    #更新时间
e、设置主机名和DNS服务器:
I have no name!@localhost:/# echo localhost > /etc/hostname
I have no name!@localhost:/# echo 'nameserver 8.8.8.8' > /etc/resolv.conf
f、设置、更新源
# echo "deb <a href="http://ports.ubuntu.com">http://ports.ubuntu.com</a> trusty main restricted universe multiverse" > /etc/apt/sources.list
# echo "deb <a href="http://ports.ubuntu.com">http://ports.ubuntu.com</a> trusty-security main restricted universe multiverse" >> /etc/apt/sources.list
# echo "deb <a href="http://ports.ubuntu.com">http://ports.ubuntu.com</a> trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list
# echo "deb <a href="http://ports.ubuntu.com">http://ports.ubuntu.com</a> trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list
# echo "deb <a href="http://ports.ubuntu.com">http://ports.ubuntu.com</a> trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
I have no name!@localhost:/# apt-get update
I have no name!@localhost:/# apt-get clean
g、安装轻量级的LXDE桌面环境和其它可选的软件。
I have no name!@localhost:/# adduser ubuntu
I have no name!@localhost:/# usermod -a -G sudo ubuntu
注:以上要去掉“I have no name!”提示,可在命令行以当前用户(root)启动1个新的 shell
I have no name!@localhost:/# exec /bin/bash --login +h
root@localhost:/# 
root@localhost:~# more /etc/issue
Ubuntu 14.04 LTS \n \l
root@localhost:~# apt-get install lxde

h、VNC 安装设置

root@localhost:/# apt-get install tightvncserver
root@localhost:/# vncserver    # 根据提示设置远程登录 password 等信息。
root@localhost:/# vncserver -kill :1
进入 /root/.vnc/ 目录,编辑 xstartup 文件: 注释 #/etc/X11/xsession 并增加以下 2行:
icewm
lxsession
i、启动 VNC, 命令格式
# vncserver -geometry <HEIGHT>x<WIDTH>
中兴N881F上执行:
# vncserver -geometry 960x540
Warning: localhost:1 is taken because of /tmp/.X11-unix/X1
Remove this file if there is no X server localhost:1
New 'X' desktop is localhost:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost:2.log

j、在手机上访问 ubuntu,需安装 Android VNC Viewer app.
在 androidVNC运行界面设置参数
Address - 输入 "localhost" 或 "127.0.0.1"
Port - 输入 5902, 端口号与 上一步输出信息中的 "localhost:"后面的数字相对应。如上面输出显示: New 'X' desktop is localhost:2, 则 port 为 5902
Color Format - 选择 "24-bit color (4bpp)"

点击 Connect 即可进入 lxde 桌面环境。

注:在 Windows 系统可安装 VNC Viewer 客户端,运行后在 VNC Server 栏输入您的手机 (WLAN IP地址):5901,点 Connect 之后输入之前设置的密码即可进入 lxde 桌面。

4、脚本

参考 3-b。每次退出 ubuntu之后若再进入ubuntu,可先做 3-b,再 3-i。

5、参考资料
编写过程主要参考了以下资料,还有其它就不一一列出了,在此一并表示感谢。

http://dawndiy.com/2012/08/16/install-and-run-ubun...

Like:
0
Tag:
To the top