贾志东 发表于 2024-7-8 22:01:37

使用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
来源:https://www.cnblogs.com/Moe-hacker/p/18289497
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 使用ruri快速构建跨架构chroot容器