修改Anlinux的shell,以安装ubuntu的新版本

多年前采用anlinux的app,来在termux上安装linux,后面有大神写出了proot-distro的东东来安装linux非常方便,还能通过修改/etc/proot-distro/目录下的文件,选择各种版本的linux,于是果断放弃了anlinux转用proot-distoo。然而proot-distro的作者却自己封装了linux的rootfs文件,没有辣么方便了,又从proot-distro更新到2.9.3后,竟然连我以前装的linux版本都启动不了了。于是想起了以前的anlinux的app,拿它与proot-distro的shell比较过,觉得它更简单,于是修改之,自己安装Canonical官方发布的arm版 ubuntu21.04,例子如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/data/data/com.termux/files/usr/bin/bash
folder=ubuntu-hirsute
if [ -d "$folder" ]; then
first=1
echo "skipping downloading"
fi
# 下载Canonical官方发布的 ubutnu21.04 的 rootfs
wget "https://partner-images.canonical.com/core/hirsute/current/ubuntu-hirsute-core-cloudimg-arm64-root.tar.gz"
tarball="ubuntu-hirsute-core-cloudimg-arm64-root.tar.gz"
cur=`pwd`
mkdir -p "$folder"
cd "$folder"
echo "Decompressing Rootfs, please be patient."
proot --link2symlink tar -zxvf ${cur}/${tarball}||:
cd "$cur"

mkdir -p ubuntu-binds
bin=start-hirsute.sh
echo "writing launch script"
cat > $bin <<- EOM
#!/bin/bash
cd \$(dirname \$0)
## unset LD_PRELOAD in case termux-exec is installed
unset LD_PRELOAD
command="proot"
command+=" --link2symlink"
command+=" -0"
command+=" -r $folder"
if [ -n "\$(ls -A ubuntu-binds)" ]; then
for f in ubuntu-binds/* ;do
. \$f
done
fi
command+=" -b /dev"
command+=" -b /proc"
command+=" -b ubuntu-hirsute/root:/dev/shm"
## uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home:/root"
## uncomment the following line to mount /sdcard directly to /
command+=" -b /sdcard"
command+=" -b /storage"
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
EOM

echo "fixing shebang of $bin"
termux-fix-shebang $bin
echo "making $bin executable"
chmod +x $bin
echo "removing image for some space"
rm $tarball
echo "You can now launch Ubuntu with the ./${bin} script"
安装完成后,执行 ./start-hirsute.sh 进入ubuntu21.04,发现不能apt update,后来发现是没有dns解析,于是
1
2
3
4
5
6
cd /etc
vim resolv.conf
添加
nameserver 114.114.114.114
nameserver 8.8.8.8
保存后退出
进入linux后,出现以下错误
1
2
3
4
goups: cannot find name for group ID 3003
groups: cannot find name for group ID 9997
goups: cannot find name for group ID 20xxx
groups: cannot find name for group ID 50xxx

这是由于termux安装ubuntu后没有给原本Android的系统用户组赋予名称导致的。由于每次在不同设备上安装termux.apk分配的u0_id (whoamis查到是u0_axxx)中的id值是不同的,这个需要每次改一下
解决方法:
1.用startubuntu进入系统su
2.执行以下命令

1
2
3
4
$ addgroup --system --gid 3003 inet
$ addgroup --system --gid 9997 sdcard_rw
$ addgroup --system --gid 50xxx all_axxx
$ reset