目录
本文参考了以下公开内容:
RK3399从零制作ubuntu - Firefly-Rk3399 - Firefly开源社区RK3399从零制作ubuntu
如何制作ubuntu arm64的rootfs文件_Elastic 中国社区官方博客-CSDN博客
下载Ubuntu根文件系统和firefly根文件系统
Ubuntu:
http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/ubuntu-base-18.04.5-base-arm64.tar.gz
firefly:
Firefly | 让科技更简单,让生活更智能
PS:我用的是firefly的整机,下载firefly做好的根文件系统是为了用官方的外设驱动
安装虚拟机
apt-get install qemu-user-static
解压创建根文件系统
mkdir ubuntu-rootfs
tar -xpf ubuntu-base-18.04.5-base-arm64.tar.gz -C ubuntu-rootfs
复制一下虚拟机的运行环境
cp -b /etc/resolv.conf ubuntu-rootfs/etc/resolv.conf
cp /usr/bin/qemu-aarch64-static ubuntu-rootfs/usr/bin/
复制官方外设驱动文件
装载firefly的根文件系统,将/vendor,/system,/lib/firmware,这三个文件夹复制到我们自己的文件系统中。
挂载根文件系统
创建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
echo "CHROOT..."
sudo chroot ${2}
echo "Success!"
}
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 -m ubuntu-rootfs/
配置根文件系统
这里列一下我做的一些配置,以及碰到的一些坑,根据需要选择性的做
- 换源(换源后可能会由于证书的问题无法更新,将源中的所有https换成http即可)
- 配置root账户密码(配置时,有时候会报错,如果装了sudo,用sudo passwd root)
- 添加个人账户,配置密码
useradd -s '/bin/bash' -m -G adm,sudo alex
- 安装一些基础包
apt-get install language-pack-en-base ca-certificates sudo ssh net-tools ethtool wireless-tools network-manager iputils-ping rsyslog bash-completion vim
- 设置主机名
echo 'alex-gateway' > /etc/hostname
- 设置resolvconf(解压创建根文件系统那步有复制resolv.conf,但是是从vmware虚拟机复制的,所以在盒子里会出现连了WiFi,但是无法上网的问题,ping baidu.com时会出现Temporary failure in name resolution)
apt-get install resolvconf dpkg-reconfigure resolvconf yes #编辑配置 vi /etc/resolvconf/resolv.conf.d/head #添加nameserver nameserver 114.114.114.114 nameserver 8.8.8.8
- 待添加
制作根文件系统
配置完毕后,退出虚拟机并取消挂载
exit
./ch-mount.sh -u ubuntu-rootfs/
创建 mkrootfs.sh文件,写入以下脚本,其中2048取决于你的根文件系统实际大小,比如安装了桌面环境后若大小超过2048M,就改大一点
#!/bin/bash
#
dd if=/dev/zero of=linuxroot.img bs=1M count=2048
sudo mkfs.ext4 linuxroot.img
rm -r rootfs
mkdir rootfs
sudo mount linuxroot.img rootfs/
sudo cp -rfp ubuntu-rootfs/* rootfs/
sudo umount rootfs/
e2fsck -p -f linuxroot.img
resize2fs -M linuxroot.img
执行制作
./mkrootfs.sh
-完毕-