简要步骤
dbus-launch和安卓proot容器有些兼容问题。
proot-distro需要修改/etc下的一些脚本,并写入sha256才能安装自己下载的rootfs。
- 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站可以找到,修改一下别人写好的安装脚本指向地址就可以了。手动安装也问题不大。
- 更新一下termux并为它请求存储权限:
apt update
termux-setup-storage
- 更改为
proot-distro
启动,因为它支持更好。
mv $PREFIX/share/ubuntu-impish \
$PREFIX/var/lib/proot-distro/ \
installed-rootfs/ubuntu
为Termux编译zink,实现3d加速,对openGL支持好,这个内容复杂,请阅读网络文章。
启动脚本
#! /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
- 登入系统后,修改软件源为国内镜像,会报证书错误,因为
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之
- 简化xfce4桌面:
sudo apt install xfdesktop4 xfwm4 xfce4-panel xfce4-session xfce4-settings
- 安装
gtk4
开发环境:
$ sudo apt-get install libgtk-4-bin libgtk-4-common libgtk-4-dev libgtk-4-doc
中文乱码解决
- 首先安装中文字体:
sudo apt-get install language-pack-zh-hans
- 生成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