Q:为什么要装新系统? A:旧系统太多软件已过时,升级费时费力,
gcc
make
glib
等版本过旧,编译升级耗时久
按照 相关链接5
配置ssh, 其他一概不装
# 切换国内清华镜像源以加速
sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.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.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
pkg update
# 安装openssh
pkg install openssh
# 生成公私钥
ssh-keygen -A
# 启动ssh服务
sshd
# 获取账户名
whoami
# 配置termux密码
passwd 你的用户名
# 通过本机wifi获取手机ip,电脑在同一局域网下进行 `ssh 用户名@手机ip -p 8022` 连接
step1 下载centos cloud 版本,此版本是给qmenu等 kvm提供的,有现成的rootfs, 不用再自行制作。在 链接引用4
找到你喜欢的版本,一般Base就可以了30多兆, 也可以 ctrl + F
搜索 Mini,然后找到最新的下载链接, 获取下载链接比如 https://cloud.centos.org/centos/9-stream/aarch64/images/CentOS-Stream-Container-Base-9-20230227.0.aarch64.tar.xz
#使用临时目录
mkdir tmp && cd tmp
#安装wget
pkg install wget
#下载CentOS-Stream
wget https://cloud.centos.org/centos/9-stream/aarch64/images/CentOS-Stream-Container-Base-9-20230227.0.aarch64.tar.xz
#解压
tar xf CentOS-Stream-Container-Base-9-20230227.0.aarch64.tar.xz
#进入文件系统
cd 一串hash命名的文件夹,里面有 `layer.tar ` 文件
#创建文件系统存储位置
mkdir -p $HOME/Termux-Linux/centos9/centos-fs
#构建文件系统以及配置
proot --link2symlink tar -xf layer.tar -C $HOME/Termux-Linux/centos9/centos-fs --exclude="dev"||:
mkdir -p $HOME/Termux-Linux/centos9/binds
mkdir -p $HOME/Termux-Linux/centos9/centos-fs/tmp
echo "127.0.0.1 localhost" > $HOME/Termux-Linux/centos9/centos-fs/etc/hosts
echo "nameserver 8.8.8.8" > $HOME/Termux-Linux/centos9/centos-fs/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $HOME/Termux-Linux/centos9/centos-fs/etc/resolv.conf
cat <<EOF > $HOME/Termux-Linux/centos9/start.sh
#!/data/data/com.termux/files/usr/bin/bash
cd \$(dirname \$0)
unset LD_PRELOAD
command="proot"
command+=" --link2symlink"
command+=" -0"
command+=" -r centos-fs"
if [ -n "\$(ls -A binds)" ]; then
for f in binds/* ;do
. \$f
done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b centos-fs/root:/dev/shm"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=\$TERM"
command+=" LANG=C.UTF-8"
command+=" /bin/bash --login"
com="\$@"
if [ -z "\$1" ];then
exec \$command
else
\$command -c "\$com"
fi
EOF
#后置处理
termux-fix-shebang $HOME/Termux-Linux/centos9/start.sh
chmod +x $HOME/Termux-Linux/centos9/start.sh
screenfetch -A "CentOS" -L
#启动centos9系统,能看到回显字符变成[@root]
./start.sh
#替换镜像地址为阿里源
sed -i.bak -e 's|^mirrorlist=|#mirrorlist=|' -e 's|^#baseurl=|baseurl=|' -e 's|http://mirror.centos.org|https://mirrors.aliyun.com|' /etc/yum.repos.d/centos-*.repo
yum clean
yum makecache
配置termux自启动
cat << EOF > $PREFIX/etc/profile.d/start.sh
#!/data/data/com.termux/files/usr/bin/bash
echo "termux用户:"$(whoami)
if pgrep -x "sshd" >/dev/null
then
echo "sshd运行中..."
else
sshd
echo "自动开启sshd..."
fi
echo 自动引导Centos,exit退出
cd $HOME/Termux-Linux/centos9/ && ./start.sh
EOF