本文参考自
的文章 ,本文将实现如何通过Ubuntu-core在Aarch64上构建最小的Ubuntu文件系统。
@L_403_1@
1 下载文件创建rootfs文件夹
mkdir ~/rootfs && cd ~/rootfs
wget http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.1/release/ubuntu-base-16.04.2-base-arm64.tar.gz
mkdir ubuntu-rootfs
tar -xvf ubuntu-base-16.04.2-base-arm64.tar.gz -C ubuntu-rootfs
cd ubuntu-rootfs
ls
查看当前路径下的文件结构已经OK
bin dev home media opt root sbin srv system usr
boot etc lib mnt proc run snap sys tmp var
2 安装qemu-user-static搭建arm64模拟环境
此时位于 ~/rootfs/ubuntu-rootfs/ 路径下,需要安装qemu-user-static并拷贝qemu-aarch64-static到当前路径的 usr/bin/下。
apt-get install qemu-user-static
cp /usr/bin/qemu-aarch64-static usr/bin
cp -b /etc/resolv.conf etc/
3 chroot 到 模拟arm64的文件系统下
#创建ch-mount.sh 脚本
cd ../
vi ch-mount.sh
将以下的内容复制到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
通过ch-mount.sh脚本chroot到arm64的文件系统下
./ch-mount.sh -m ubuntu-rootfs
4 安装基础的软件包
apt-get install @H_403_247@\ language-pack-en-base @H_403_247@\ sudo @H_403_247@\ ssh @H_403_247@\ net-tools @H_403_247@\ network-manager @H_403_247@\ iputils-ping @H_403_247@\ rsyslog @H_403_247@\ bash-completion @H_403_247@\ htop \
5 系统基础的修改
添加用户、设定合适的组并设置密码
useradd -s '/bin/bash' -m -G adm,sudo yourusername
echo "Set password for yourusername:"
passwd yourusername
echo "Set password for root:"
passwd root
设置主机名
echo 'ubuntu.yourusername' > /etc/hostname
设置自动更新DNS
dpkg-reconfigure resolvconf
配置登录的串口
因为暂时未安装桌面,所以这里的配置要具体和内核中登录的串口的设备对应起来,不然对导致无法通过串口登录的问题。
start on stopped rc or RUNLEVEL=[12345] stop on RUNLEVEL [!12345] respawn exec /sbin/getty -L 115200 ttyFIQ0 vt102
本文环境的登录串口为ttyFIQ0,具体可能会因为目标板差异而不同,具体要参考所使用的平台进行修改。
6 退出并制作可烧录的固件
退出arm64模拟文件系统
exit
./ch-mount -u ubuntu-rootfs
使用dd指令制作空的固件容器
dd if=/dev/zero of=ubuntu-rootfs.img bs=1M count=2048
sudo mkfs.ext4 ubuntu-rootfs.img
将arm64文件系统内容制作到ubuntu-rootfs.img
mkdir ubuntu-mount
sudo mount ubuntu-rootfs.img ubuntu-rootfs/
sudo cp -rfp ubuntu-rootfs/* ubuntu-mount/ sudo umount ubuntu-mount/ e2fsck -p -f ubuntu-rootfs.img resize2fs -M ubuntu-rootfs.img