使用ruri快速构建跨架构chroot容器

在开发过程中,我们偶尔会用到跨架构Linux容器。
ruri全称“轻量型,用户友好的Linux容器实现”,是一个1M左右大小的Linux容器实现,提供了一系列功能选项,致力于成为更加强大且安全的chroot命令替换。
我们以在x86_64系统下运行arm64的Ubuntu容器为例:

确认binfmt_misc支持:

~$ cat /proc/filesystems | grep binfmt_misc
nodev   binfmt_misc

确保能看见binfmt_misc的输出,大多系统甚至安卓的GKI内核应该都是支持的。

安装qemu-user-static:

sudo apt install qemu-user-static

获取rootfs:

这里使用作者编写的rootfstool脚本:

git clone https://github.com/Moe-hacker/rootfstool
cd rootfstool
./rootfstool download --mirror bfsu --distro ubuntu --version noble --arch arm64

于是我们得到了rootfs.tar.xz

获取ruri二进制:

前往https://github.com/moe-hacker/ruri/releases,下载最新的ruri-x86_64

wget https://github.com/Moe-hacker/ruri/releases/download/v3.3/ruri-x86_64
chmod 777 ruri-x86_64

解压rootfs,启动:

mkdir ubuntu-arm64
tar -xvf /path/to/rootfs.tar.xz -C ubuntu-arm64
cp /usr/bin/qemu-aarch64-static ubuntu-arm64/
sudo ./ruri-x86_64 -a aarch64 -q /qemu-aarch64-static ./ubuntu-arm64/

配置容器DNS:

最后在容器中:

rm /etc/resolv.conf
echo nameserver 114.114.114.114 > /etc/resolv.conf
posted @ 2024-07-08 10:58  Moe-hacker  阅读(5)  评论(0编辑  收藏  举报