1. 安装qemu模拟器
sudo apt install qemu-user-static
2. 安装debootstrap
sudo apt install debootstrap
3. 查看当前环境下执行文件系统架构支持情况
update-binfmts --display
sudo update-binfmts --enable qemu-aarch64
4. 构建一个基本的Ubuntu裸文件系统
sudo mkdir /mnt/rootfs
sudo mount -t ext4 /dev/sdb2 /mnt/rootfs -o dev,exec
sudo debootstrap --arch arm64 --variant=minbase jammy /mnt/rootfs
sudo cp /usr/bin/qemu-aarch64-static /mnt/rootfs/usr/bin/
5. 修改apt软件源
sudo cp -b /etc/resolv.conf /mnt/rootfs/etc/resolv.conf
sudo vim /mnt/rootfs/etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main universe restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy main universe restricted
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
6. 挂载proc, sys, dev, dev/pts等文件系统
vim ch-mount.sh
sudo bash ch-mount.sh -m /mnt/rootfs
#!/bin/bash
function help() {
echo ""
echo "usage: ch-mount.sh [-m <path>] [-u <path>] <command> [<args>]"
echo ""
echo "For example: bash ch-mount.sh -m /media/sdcard/"
echo ""
}
while getopts "m:u:" arg
do
case $arg in
m)
echo "I: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}
;;
u)
echo "I:UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
sudo umount ${2}dev/pts
sudo umount ${2}dev
;;
?)
echo "E:Unknow parameter"
help
exit 1
esac
done
7. 安装所需软件包
apt update
apt upgrade
apt install language-pack-en-base sudo ssh net-tools ethtool wireless-tools ifupdown network-manager iputils-ping rsyslog bash-completion htop vim resolvconf cpufrequtils devmem2
8. 添加用户
adduser aqronos
//useradd -m aqronos -g sudo -s /bin/bash -d /home/aqronos
修改/etc/sudoers,在root行下加上这句,创建的用户就可以用sudo获得root权限
aqronos ALL=(ALL:ALL) ALL
9. 设置主机名称 设置本机入口ip
echo "ubuntu-aarch64-zynqmp">/etc/hostname
echo "127.0.0.1 localhost">>/etc/hosts
echo "127.0.1.1 ubuntu-aarch64-zynqmp">>/etc/hosts
dpkg-reconfigure resolvconf
dpkg-reconfigure tzdata
10. 配置串口
如果没有/etc/init/ttyPS0.conf,则自行创建。文件夹没有的也需要自行创建
start on stoppedrc or RUNLEVEL=[12345]
stop on runlevel[!12345]
respawn
exec /sbin/getty -L 115200 ttyPS0 vt102
11. 根文件系统挂载,修改/etc/fstab
# <file system> <dir> <type> <options> <dump> <pass>
/dev/mmcblk1p2 / ext4 defaults,noatime,errors=remount-ro 0 1
/dev/mmcblk1p1 /boot/uboot vfat defaults,noatime 0 0
12. 网络设置 /etc/network/interfaces
# 本地回环
auto lo
iface lo inet loopback
# 两种方法任选一个
# 获取动态配置:
#auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
# 获取静态配置:
# auto eth0
# iface eth0 inet static
# address 192.168.0.1
# netmask 255.255.255.0
# gateway 192.168.0.1
13.ros2 humble安装
设置编码
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
添加源
sudo apt update && sudo apt install curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
安装ROS2
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-ros-base
sudo apt install ros-humble-pcl-*
设置环境变量
source /opt/ros/humble/setup.bash
echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc
验证测试
ros2 topic pub --rate 1 /test std_msgs/msg/String 'data: "hello"'
ros2 topic echo /test
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener
14. 制作SD卡启动系统
$(petalinu-project)/images/linux下的BOOT.BIN,boot.scr和image.ub拷贝到SD卡的FAT分区,制作好的roofs在SD卡的ext4分区
可能的错误sudo
chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo
-A start job is running for Raise network interface(5min 13s )问题解决方法
网友方法:/etc/systemd/system/network-online.target.wants/networking.service 将里面的TimeoutStartSec=5min 修改为TimeoutStartSec=2sec
我的方法: /etc/network/interfaces 修改如下:
auto lo
iface lo inet loopback
#auto eth0 #屏蔽项
allow-hotplug eth0 #添加项
iface eth0 inet dhcp