本文参考自
的文章 ,本文将实现如何通过Ubuntu-core在Aarch64上构建最小的Ubuntu文件系统。
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
此时位于 ~/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/
#创建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
apt-get install \
language-pack-en-base \
sudo \
ssh \
net-tools \
network-manager \
iputils-ping \
rsyslog \
bash-completion \
htop \
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
dpkg-reconfigure resolvconf
因为暂时未安装桌面,所以这里的配置要具体和内核中登录的串口的设备对应起来,不然对导致无法通过串口登录的问题。
在 /etc/init/ 下添加或修改ttyS0.conf
start on stopped rc or RUNLEVEL=[12345]
stop on RUNLEVEL [!12345]
respawn
exec /sbin/getty -L 115200 ttyFIQ0 vt102
本文环境的登录串口为ttyFIQ0,具体可能会因为目标板差异而不同,具体要参考所使用的平台进行修改。
exit
./ch-mount -u ubuntu-rootfs
dd if=/dev/zero of=ubuntu-rootfs.img bs=1M count=2048
sudo mkfs.ext4 ubuntu-rootfs.img
mkdir ubuntu-mount
sudo mount ubuntu-rootfs.img ubuntu-mount/
sudo cp -rfp ubuntu-rootfs/* ubuntu-mount/
sudo umount ubuntu-mount/
e2fsck -p -f ubuntu-rootfs.img
resize2fs -M ubuntu-rootfs.img
手机扫一扫
移动阅读更方便
你可能感兴趣的文章