0、解压根文件系统包
mkdir ubuntu-rootfs
sudo tar -xpf ubuntu-base-22.04.3-base-armhf.tar.gz -C ubuntu-rootfs/
1、首先确保安装了qemu-user-static
sudo apt-get install qemu-user-static
2、确保qemu-arm-static复制到正确目录
sudo cp /usr/bin/qemu-arm-static ubuntu-rootfs/usr/bin/
3、使用可用的挂载脚本ch-mount.sh
#!/bin/bash
function mnt() {
echo "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}
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}/proc
sudo umount ${2}/sys
sudo umount ${2}/dev/pts
sudo umount ${2}/dev
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
4、正确运行挂载脚本
sudo ./ch-mount.sh -m ubuntu-rootfs/
5、出现格式不对无法完成挂载的情况
主要是由于未正确配置使用的qemu用户模式系统架构导致的。
sudo ./ch-mount.sh -m ubuntu-rootfs
MOUNTING
chroot: failed to run command ‘/bin/bash’: Exec format error
6、安装binfmt
binfmt(Binary Format)是一个内核模块,它的用处如它的名字,通过二进制文件头来识别它的格式,从而指定用哪个解释器去启动——可以理解为二进制文件的hashbang。有了它我们就可以像启动原生ELF一样启动一个ARM或其他任何QEMU支持的程序了。文章来源:https://www.toymoban.com/news/detail-492008.html
sudo apt install qemu-user-binfmt
7、显示当前环境下执行文件系统架构支持情况
update-binfmts --display
输出如下,可见此处qemu-arm是disabled文章来源地址https://www.toymoban.com/news/detail-492008.html
python2.7 (disabled):
package = python2.7
type = magic
offset = 0
magic = \x03\xf3\x0d\x0a
mask =
interpreter = /usr/bin/python2.7
detector =
python3.8 (disabled):
package = python3.8
type = magic
offset = 0
magic = \x55\x0d\x0d\x0a
mask =
interpreter = /usr/bin/python3.8
detector =
qemu-aarch64 (disabled):
package = qemu-user-static
type = magic
offset = 0
magic = \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00
mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter = /usr/bin/qemu-aarch64-static
detector =
qemu-alpha (disabled):
package = qemu-user-static
type = magic
offset = 0
magic = \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90
mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter = /usr/bin/qemu-alpha-static
detector =
qemu-arm (disabled):
package = qemu-user-static
type = magic
offset = 0
magic = \x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00
mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter = /usr/bin/qemu-arm-static
detector =
...
8、启用qemu-arm
sudo update-binfmts --enable qemu-arm
9、正确挂载根文件系统即可
sudo ./ch-mount.sh -m ubuntu-rootfs
10、更新挂载脚本ch-mount.sh
#!/bin/bash
function mnt() {
echo "MOUNTING"
sudo update-binfmts --enable qemu-arm
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}
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}/proc
sudo umount ${2}/sys
sudo umount ${2}/dev/pts
sudo umount ${2}/dev
sudo update-binfmts --disable qemu-arm
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
到了这里,关于制作arm ubuntu根文件系统chroot失败解决办法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!