安卓运行Linux

简要步骤

  • dbus-launch和安卓proot容器有些兼容问题。

  • proot-distro需要修改/etc下的一些脚本,并写入sha256才能安装自己下载的rootfs。

  1. Termux换北外源:
#替换北外源
sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.bfsu.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.bfsu.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.bfsu.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
apt update && apt upgrade
  • 常规自定义ubuntu21.10安装脚本大体如下:
#!/data/data/com.termux/files/usr/bin/bash
directory="ubuntu-impish"
distribution="Ubuntu impish"
if [ -d "${PREFIX}/share/${directory}" ]; then
printf "\n\e[31mError: distribution ${distribution} is already installed.\e[0m\n\n"
exit
fi
printf "\n\e[34m[\e[32m*\e[34m]\e[36m Checking device architecture...\e[0m\n"
case $(uname -m) in
aarch64) arch="arm64" multiarch="aarch64-linux-gnu" ;;
armv7l|armv8l) arch="armhf" multiarch="arm-linux-gnueabihf" ;;
x86_64) arch="amd64" multiarch="x86_64-linux-gnu" ;;
*)
printf "\e[34m[\e[32m*\e[34m]\e[31m Unsupported architecture.\e[0m\n\n"; exit ;;
esac
pkg install proot -y > /dev/null 2>&1
printf "\e[34m[\e[32m*\e[34m]\e[36m Downloading ${distribution}, please wait...\e[34m\n\n"
tarball="${directory}.tar.gz"
if ! curl --location --output "${tarball}" \
"https://partner-images.canonical.com/core/impish/current/ubuntu-impish-core-cloudimg-${arch}-root.tar.gz"; then
printf "\e[0m\n\e[34m[\e[32m*\e[34m]\e[31m Download failed, please check your network connection.\e[0m\n\n"
rm -f "${tarball}"
exit
fi
printf "\e[0m\n\e[34m[\e[32m*\e[34m]\e[36m Installing ${distribution}, please wait...\e[0m\n"
mkdir -p "${PREFIX}/share/${directory}"
proot --link2symlink tar -xf "${tarball}" --directory="${PREFIX}/share/${directory}" --exclude='dev'||:
rm -f "${tarball}"
cat <<- EOF > "${PREFIX}/share/${directory}/etc/ld.so.preload"
/lib/${multiarch}/libgcc_s.so.1
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/etc/profile.d/config.sh"
export LANG="zh_CN.UTF-8"
export MOZ_FAKE_NO_SANDBOX="1"
export PULSE_SERVER="127.0.0.1"
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/etc/resolv.conf"
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/etc/hosts"
127.0.0.1  localhost
::1        ip6-localhost ip6-loopback
EOF
while read group_name group_id; do
cat <<- EOF >> "${PREFIX}/share/${directory}/etc/group"
${group_name}:x:${group_id}:
EOF
cat <<- EOF >> "${PREFIX}/share/${directory}/etc/gshadow"
${group_name}:*::
EOF
done < <(paste <(id -Gn | tr ' ' '\n') <(id -G | tr ' ' '\n'))
cat <<- EOF > "${PREFIX}/share/${directory}/proc/.loadavg"
0.35 0.22 0.15 1/575 7767
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/proc/.stat"
cpu  265542 13183 24203 611072 152293 68 191340 255 0 0 0
cpu0 265542 13183 24203 611072 152293 68 191340 255 0 0 0
intr 815181 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 906205
btime 163178502
processes 25384
procs_running 1
procs_blocked 0
softirq 1857962 55 2536781 34 1723322 8 2457784 5 1914410
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/proc/.uptime"
11965.80 11411.22
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/proc/.vmstat"
nr_free_pages 705489
nr_alloc_batch 0
nr_inactive_anon 1809
nr_active_anon 61283
nr_inactive_file 69543
nr_active_file 58416
nr_unevictable 64
nr_mlock 64
nr_anon_pages 60894
nr_mapped 99503
nr_file_pages 130218
nr_dirty 9
nr_writeback 0
nr_slab_reclaimable 2283
nr_slab_unreclaimable 3714
nr_page_table_pages 1911
nr_kernel_stack 687
nr_unstable 0
nr_bounce 0
nr_vmscan_write 0
nr_vmscan_immediate_reclaim 0
nr_writeback_temp 0
nr_isolated_anon 0
nr_isolated_file 0
nr_shmem 2262
nr_dirtied 3675
nr_written 3665
nr_pages_scanned 0
workingset_refault 1183
workingset_activate 1183
workingset_nodereclaim 0
nr_anon_transparent_hugepages 0
nr_free_cma 0
nr_dirty_threshold 21574
nr_dirty_background_threshold 5393
pgpgin 541367
pgpgout 23248
pswpin 1927
pswpout 2562
pgalloc_dma 182
pgalloc_normal 76067
pgalloc_high 326333
pgalloc_movable 0
pgfree 1108260
pgactivate 53201
pgdeactivate 2592
pgfault 420060
pgmajfault 4323
pgrefill_dma 0
pgrefill_normal 2589
pgrefill_high 0
pgrefill_movable 0
pgsteal_kswapd_dma 0
pgsteal_kswapd_normal 0
pgsteal_kswapd_high 0
pgsteal_kswapd_movable 0
pgsteal_direct_dma 0
pgsteal_direct_normal 1211
pgsteal_direct_high 7987
pgsteal_direct_movable 0
pgscan_kswapd_dma 0
pgscan_kswapd_normal 0
pgscan_kswapd_high 0
pgscan_kswapd_movable 0
pgscan_direct_dma 0
pgscan_direct_normal 4172
pgscan_direct_high 25365
pgscan_direct_movable 0
pgscan_direct_throttle 0
pginodesteal 0
slabs_scanned 9728
kswapd_inodesteal 0
kswapd_low_wmark_hit_quickly 0
kswapd_high_wmark_hit_quickly 0
pageoutrun 1
allocstall 189
pgrotated 7
drop_pagecache 0
drop_slab 0
htlb_buddy_alloc_success 0
htlb_buddy_alloc_fail 0
unevictable_pgs_culled 64
unevictable_pgs_scanned 0
unevictable_pgs_rescued 0
unevictable_pgs_mlocked 64
unevictable_pgs_munlocked 0
unevictable_pgs_cleared 0
unevictable_pgs_stranded 0
EOF
cat <<- EOF > "${PREFIX}/share/${directory}/proc/.version"
Linux version 5.11.0 (termux@android) (gcc version 4.9 (GCC)) $(uname -v)
EOF
cat <<- EOF > "${PREFIX}/bin/start-${directory}"
#!/data/data/com.termux/files/usr/bin/bash
unset LD_PRELOAD
command="proot"
command+=" --kernel-release=5.11.0"
command+=" --link2symlink"
command+=" --kill-on-exit"
command+=" --rootfs=\${PREFIX}/share/${directory}"
command+=" --root-id"
command+=" --bind=/dev"
command+=" --bind=/dev/urandom:/dev/random"
command+=" --bind=/proc"
command+=" --bind=/proc/self/fd:/dev/fd"
command+=" --bind=/proc/self/fd/0:/dev/stdin"
command+=" --bind=/proc/self/fd/1:/dev/stdout"
command+=" --bind=/proc/self/fd/2:/dev/stderr"
command+=" --bind=/sys"
command+=" --bind=/storage/self/primary:/sdcard"
command+=" --bind=/data/data/com.termux"
command+=" --bind=\${PREFIX}/share/${directory}/tmp:/dev/shm"
if ! cat /proc/loadavg > /dev/null 2>&1; then
command+=" --bind=\${PREFIX}/share/${directory}/proc/.loadavg:/proc/loadavg"
fi
if ! cat /proc/stat > /dev/null 2>&1; then
command+=" --bind=\${PREFIX}/share/${directory}/proc/.stat:/proc/stat"
fi
if ! cat /proc/uptime > /dev/null 2>&1; then
command+=" --bind=\${PREFIX}/share/${directory}/proc/.uptime:/proc/uptime"
fi
if ! cat /proc/vmstat > /dev/null 2>&1; then
command+=" --bind=\${PREFIX}/share/${directory}/proc/.vmstat:/proc/vmstat"
fi
command+=" --bind=\${PREFIX}/share/${directory}/proc/.version:/proc/version"
command+=" /usr/bin/env --ignore-environment"
command+=" TERM=\${TERM-xterm-256color}"
command+=" /bin/su --login"
com="\$@"; [ -z "\$1" ] && exec \${command} || \${command} "\${com}"
EOF
chmod +x "${PREFIX}/bin/start-${directory}"
printf "\e[34m[\e[32m*\e[34m]\e[36m Installation finished.\e[0m\n\n"
printf "\e[36mNow run '\e[32mstart-${directory}\e[36m' to login.\e[0m\n\n"

  • 至于最新版根镜像,ubuntu站可以找到,修改一下别人写好的安装脚本指向地址就可以了。手动安装也问题不大。
  1. 更新一下termux并为它请求存储权限:
apt update
termux-setup-storage
  1. 更改为proot-distro启动,因为它支持更好。
mv $PREFIX/share/ubuntu-impish \
$PREFIX/var/lib/proot-distro/ \
     installed-rootfs/ubuntu
  1. 为Termux编译zink,实现3d加速,对openGL支持好,这个内容复杂,请阅读网络文章

  2. 启动脚本

#! /bin/bash
#3d加速的变量定义
1. export XDG_RUNTIME_DIR=$TMPDIR
2. export GALLIUM_DRIVER=zink
       
3. proot-distro login ubuntu --bind \
/storage/emulated/0:/home/xxx/sdcard 
--bind \
/storage/sdcard1:/home/xxx/sdcard1 \
--shared-tmp --user xxx
  1. 登入系统后,修改软件源为国内镜像,会报证书错误,因为https方式更安全,但需要证书,解决方法简单,把/etc/apt/sources.list文件的https改为http,然后重新安装证书:
#重新安装证书
apt install ca-certificates
  • 如果出现dpkg报错,先检查perl命令是否正常,如果错误,替换perl程序。如果不是,执行下列命令:
cd /var/lib/dpkg
mv info xxxx
mkdir info
apt update
apt install -f
mv info/* xxxx
rm -rf info
mv xxxx info
apt upgrade
  • 修改/etc/apt/sources.list文件,用vim替换所有http字符串为https。vim的全局替换命令是: %s/xxx/yyy/g

  • perl文件的替换方法是:

#得到仓库安装包
apt reinstall perl-base
#拷贝缓存的包到家目录示例:
cp /var/cache/apt/archives/per-base ~
#新建一个目录解压,在extract目录下
#得到perl的二进制文件
mkdir extract
dpkg -x per-base extract/
#查找perl程序路径并替换之
type perl
#然后rm,cp之
  1. 简化xfce4桌面:
sudo apt install xfdesktop4 xfwm4 xfce4-panel xfce4-session xfce4-settings
  1. 安装gtk4开发环境:
$ sudo apt-get install libgtk-4-bin libgtk-4-common libgtk-4-dev libgtk-4-doc

中文乱码解决

  1. 首先安装中文字体:
sudo apt-get install language-pack-zh-hans
  1. 生成locale:
sudo vim /etc/environment
#添加如下内容
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
#再修改local文件,没有就新建:
sudo vim /var/lib/locales/supported.d/local
#添加内容:
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GBK GBK
zh_CN GB2312
 
#执行命令:
sudo locale-gen
 
#如果中文显示空格乱码,就是缺字体:
sudo apt-get install fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming
 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,270评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,489评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,630评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,906评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,928评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,718评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,442评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,345评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,802评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,984评论 3 337
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,117评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,810评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,462评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,011评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,139评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,377评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,060评论 2 355

推荐阅读更多精彩内容