在home下新建文件夹
mkdir /home/ubuntu-rootfs cd /home/ubuntu-rootfs
从Ubuntu官网获取裸文件系统
wget https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04-base-amd64.tar.gz
解压下载的系统文件包
sudo tar -xzvf ubuntu-base-22.04-base-amd64.tar.gz # 退回到上一级目录 cd ..
chroot实现文件系统隔离,需要qemu static解释器;
可能无法链接到qemu-aarch64-static, 到/usr/bin 文件下查找
sudo apt-get install qemu-user-static sudo cp /usr/bin/qemu-aarch64-static /home/ubuntu-rootfs/usr/bin/
复制网络配置文件 修改源
;不修改源后续可能无法联网
sudo cp -b /etc/resolv.conf /home/ubuntu-rootfs/etc/resolv.conf sudo vim /home/ubuntu-rootfs/etc/apt/source.list
source.list中原有的可以注释掉,替换为
#中科大源 deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main universe restricted deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main universe restricted deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
在 /home/ubuntu-rootfs 中编写挂载脚本
#!/bin/bash function help() { echo "" echo "usage: ch-mount.sh [-m <path>] [-u <path>] <command> [<args>]" echo "" echo "For example: bash ch-mount.sh -m /media/sdcard/" echo "" } while getopts "m:u:" arg do case $arg in m) echo "I:MOUNTING" sudo mount -t proc /proc ${2}proc sudo mount -t sysfs /sys ${2}sys sudo mount -o bind /dev ${2}dev sudo mount -o bind /dev/pts ${2}dev/pts sudo chroot ${2} ;; u) echo "I:UNMOUNTING" sudo umount ${2}proc sudo umount ${2}sys sudo umount ${2}dev/pts sudo umount ${2}dev ;; ?) echo "E:Unknow parameter" help exit 1 esac done
执行挂载命令
sudo bash ch-mount.sh -m /home/ubuntu-rootfs/ //卸载命令 //sudo bash ch-mount.sh -u /home/ubuntu-rootfs/