1.获取资源
下在Ubuntu base arm 根文件系统:
http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/

这里我们选硬浮点。
将下载好的ubuntu-base-20.04.1-base-armhf.tar.gz,拷贝至虚拟机并解压。
注意:虚拟机建议和Ubuntu-base同一版本。

2.安装qemu-user-static工具
在虚拟机Ubuntu环境下安装:

sudo apt-get install qemu-user-static

将qemu-user-static拷贝解压出来的根文件系统中

sudo cp /usr/bin/qemu-arm-static /home/xxxx/ssd20x/ubuntu_base/usr/bin/

3.修改Ubuntu base 根文件系统的配置
这里我们提前修改配置,为后边安装工具做准备。
修改tmp目录权限为 777,在apt update的时候会在tmp目录下创建一些临时文件,所以要给tmp目录写权限。

#chmod 777  ssd20x/ubuntu_base/tmp

修改resolv.conf文件,添加dns。

#vim ssd20x/ubuntu_base/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

4.将base文件系统挂载到虚拟机下
● 编写挂载脚本
在解压目录的上一级目录下新建一个ms.sh文件,文件内容如下,并赋予文件777的权限

#!/bin/bash
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}
}
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
    echo "mnt -m pwd"
elif [ "$1" = "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
    echo "mnt -u pwd"
else
    echo ""
    echo "Either 1'st, 2'nd or bothparameters were missing"
    echo ""
    echo "1'st parameter can be one ofthese: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full pathof rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m/media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}
fi

● 挂载

sudo ./ms.sh -m home/xxxx/ssd20x/ubuntu_base/

● 卸载

sudo ./ms.sh -u home/xxxx/ssd20x/ubuntu_base/

模拟root也可以使用chroot命令替代

5.安装软件
挂载后即可进入该系统,为系统安装软件

apt update
apt install usbutils
apt install sudo 
apt install language-pack-en-base
apt install ssh
apt install net-tools
apt install ethtool
apt install ifupdown
apt install iputils-ping
apt install rsyslog
apt install htop
apt install vi
apt install dhcpcd5
apt install samba samba-common
apt install wpasupplicant
apt install jq
apt install alsa-base 
apt install minicom

6.用户配置
● 设置用户密码

passwd root

● 设置主机名称

echo "industio" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.1.1 industio" >> /etc/hosts

7.配置串口
需要安装ssh后才有/lib/systemd/system/getty@.service

vi /lib/systemd/system/getty@.service

修改为ttyS0

串口问题导致:进入系统无法调试

报以下错误
[ TIME ] Timed out waiting for device dev-ttyS0.device. [DEPEND] Dependency failed for Serial Getty on ttyS0.
https://dev.t-firefly.com/thread-4903-1-4.html
解决办法参考以上链接

# cp /lib/systemd/system/serial-getty\@.service /lib/systemd/system/serial-getty\@ttyS0.service 

# ln -s /lib/systemd/system/serial-getty\@ttyS0.service /etc/systemd/system/getty.target.wants/

到此输入 exit 退出挂载界面,并卸载文件系统。

sudo ./ms.sh -u home/xxxx/ssd20x/ubuntu_base/

后续挂载SD卡文件系统可参考buildroot章节。

文档更新时间: 2022-06-23 17:23   作者:Aeeditor