构建最小 ARM Ubuntu 文件系统

本文详细指导如何从Ubuntu官方获取基础文件系统,安装qemu-user-static搭建模拟环境,挂载并chroot到模拟系统中,进而安装基础软件包,并制作ARM64镜像。适合学习和实践ARM设备文件系统构建。
摘要由CSDN通过智能技术生成

以构建 Ubuntu16.04 为例,使用 qemu 构建文件系统.

1.下载 Ubuntu 官方提供的 base 文件系统

下载地址:http://cdimage.ubuntu.com/ubuntu-base/releases/20.04.3/release/ubuntu-base-20.04.3-base-arm64.tar.gz

wget http://cdimage.ubuntu.com/ubuntu-base/releases/20.04.3/release/ubuntu-base-20.04.3-base-arm64.tar.gz

mkdir ubuntu

sudo tar xpf ubuntu-base-16.04.6-base-armhf.tar.gz -C ubuntu/

2. 安装 qemu-user-static 搭建 arm 模拟环境
 

sudo apt-get install qemu-user-static
sudo cp /usr/bin/qemu-arm-static ubuntu/usr/bin
#sudo cp /usr/bin/qemu-aarch64-static ubuntu/usr/bin
sudo cp -b /etc/resolv.conf ubuntu/etc/

64位文件系统:copy 自 /usr/bin/qemu-aarch64-static

32位文件系统:需要复制/usr/bin/qemu-arm-static

3.挂载 proc,sys,dev 等文件系统,chroot 到模拟 arm 文件系统
 

在 PC 机 Ubuntu 下新建脚本文件 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

脚本文件新建好后就可以开始进入文件系统安装一些初始包了,键入以下指令进入模拟文件
系统:
 

sudo bash ch-mount.sh -m ubuntu/
或:
./ch-mount.sh -m ubuntu/

4.安装一些基础软件包

使用 ch-mount.sh 脚本进入模拟文件系统后就可以模拟 ARM 平台下的文件系统进行操作了。
执行以下安装必要的软件包,方便后续使用 U 盘或 TF 卡安装文件系统。

apt-get update
apt-get upgrade -y
apt-get install sudo dialog apt-utils iputils-ping wget -y
apt-get install net-tools ethtool wireless-tools network-manager resolvconf
-y
apt-get install rsyslog bash-completion htop lxtask vim -y
apt-get install synaptic xfce4-power-manager -y

5.制作文件系统镜像

mkdir tmp
dd if=/dev/zero of=rootfs-ubuntu.img bs=1M count=0 seek=4000
mkfs.ext4 rootfs-ubuntu.img
sudo mount rootfs-ubuntu16.img tmp/
sudo cp -rfp ubuntu/* tmp/
sudo umount tmp
e2fsck -p -f rootfs-ubuntu.img
resize2fs -M rootfs-ubuntu.img
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值