|
|
楼主 |
发表于 2026-8-26 22:58:52
|
显示全部楼层
本帖最后由 winpefk 于 2026-8-26 23:10 编辑
我先祭出安卓上rootfs构建和修补的脚本
联网得等会儿...
- # Android chroot container builder
- # The script is designed for arm64 arch, you may change it for yourself
- # Use proot for the network access in early stage
- id=$(whoami)
- rootfs=$1
- unset LD_PRELOAD
- if [ $id != root ];then
- echo No Permission to get proceed.
- exit
- fi
- SCRIPT_PATH="$0"
- SCRIPT_DIR="${SCRIPT_PATH%/*}"
- path_set="/usr/bin/busybox env PATH=/usr/bin:/usr/sbin:/bin:/sbin"
- in_container="proot -r $rootfs --sysvipc -w /tmp -b /dev -b /proc -b /sys"
- debootstrap --include=fakeroot,busybox-static,strace --download-only --arch arm64 --variant=minbase stable $rootfs [url]https://mirrors.tuna.tsinghua.edu.cn/debian[/url]
- debootstrap --include=fakeroot,busybox-static,strace --arch arm64 --variant=minbase stable $rootfs [url]https://mirrors.tuna.tsinghua.edu.cn/debian[/url]
- echo Base rootfs has been built, performing minor fixing.
- $in_container -0 $path_set /usr/bin/apt reinstall passwd -y # debootstrap installed a stub addgroup program which brokes the groupadd commmand
- $in_container -0 $path_set /usr/bin/apt reinstall perl-base -y #de.. use l2s(link2symlink) in proot. broke the hard link.
- $in_container -0 $path_set /usr/bin/apt reinstall coreutils -y
- # here are proofs:
- # in debootstrap(termux version)
- # .../usr/share/debootstrap/scripts/debian-common # Replace problematic binaries with a stub
- # echo "" > "$TARGET/bin/chown"
- # echo "" > "$TARGET/usr/sbin/groupadd"
- # ...
- $in_container -0 $path_set /usr/bin/apt clean
- $in_container -0 $path_set /usr/sbin/groupadd -g 3003 aid_inet
- $in_container -0 $path_set /usr/sbin/usermod -g aid_inet _apt
- $in_container -0 $path_set /usr/sbin/usermod -G aid_inet root
- #
- $in_container -0 $path_set /usr/bin/chmod 644 /etc/resolv.conf
- # newly found bug: chroot mode failed to set correct file permission flag
- # so containers running in chroot using sandbox cannot connect to the internet.
- # fix /tmp access
- $in_container -0 $path_set /usr/bin/chmod -R 777 /tmp/
- #
- # fix apt access
- $in_container -0 $path_set /usr/bin/chown _apt:aid_inet -R /etc/apt/
- #
- # lxc fixing
- cp $SCRIPT_DIR/mdev.service $rootfs/usr/lib/systemd/system/mdev.service
- $in_container -0 $path_set /usr/bin/ln -sf /usr/lib/systemd/system/mdev.service /etc/systemd/system/mdev.service
- $in_container -0 $path_set /usr/bin/chmod 640 /usr/lib/systemd/system/mdev.service
- $in_container -0 $path_set /usr/bin/chown root:systemd-journal /usr/lib/systemd/system/mdev.service
- $in_container -0 $path_set /usr/bin/ln -sf /etc/systemd/system/mdev.service /etc/systemd/system/sysinit.target.wants/mdev.service
- cp $SCRIPT_DIR/mdev.conf $rootfs/etc/mdev.conf
- $in_container -0 $path_set /usr/bin/chmod 640 /etc/mdev.conf
- $in_container -0 $path_set /usr/bin/chown root:root /etc/mdev.conf
- echo "All done!"
- echo "for proot container, don't use the script, use proot-distro instead."
- echo "If you want to build a rootfs for yourself without root access., try 'fakeroot debootstrap' instead."
复制代码
然后是同文件夹下的
mdev.conf
- # /etc/mdev.conf
- null root:root 666
- zero root:root 666
- random root:root 666
- urandom root:root 666
- tty root:tty 666
- console root:root 600
- ptmx root:root 666
- full root:root 666
复制代码
mdev.service
- # /etc/systemd/system/mdev.service
- [Unit]
- Description=BusyBox mdev daemon
- Before=sysinit.target
- DefaultDependencies=no
- ConditionPathExists=!/dev/kmsg
- [Service]
- Type=forking
- ExecStartPre=/bin/sh -c 'mount | grep -q " /dev/pts " || mount -t devpts devpts /dev/pts -o mode=0620,gid=5'
- ExecStart=/bin/busybox mdev -d
- Restart=always
- RestartSec=2
- [Install]
- WantedBy=sysinit.target
复制代码 |
|