定制Ubuntu 20.04.4文件系统及板卡通过个人电脑访问互联网

定制Ubuntu 20.04.4文件系统及板卡通过个人电脑访问互联网

方法一:直接从 ISO 内提取 rootfs(标准方式)

我是在Vmware的Ubuntu20.04虚拟操作系统中实现:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 进入超级用户下
wget https://old-releases.ubuntu.com/releases/20.04.4/ubuntu-20.04.4-live-server-arm64.iso
mount ubuntu-20.04.4-live-server-arm64.iso /mnt
cp /mnt/casper/filesystem.squashfs ./
umount /mnt
unsquashfs filesystem.squashfs
echo 'nameserver 8.8.8.8' >> squashfs-root/etc/resolv.conf
echo 'nameserver 8.8.4.4' >> squashfs-root/etc/resolv.conf
chroot squashfs-root
apt-get update
apt-get install -y unzip vim  git openssh-server python3-pip sysstat  libnuma1  dmidecode  rsync  net-tools  psmisc  parted  arping  ntpdate  iproute2  iputils-ping  mawk  cracklib-runtime  ethtool  ntp  fdisk  libssl-dev  libpam-cracklib  logrotate
# 配置ssh
<<'CONTENT'
Port 22
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2
PasswordAuthentication yes
CONTENT
sed -i 's/^[[:space:]]*#\?Port.*/Port 22/' /etc/ssh/sshd_config
sed -i 's/^[[:space:]]*#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^[[:space:]]*#\?PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i 's|^[[:space:]]*#\?AuthorizedKeysFile.*|AuthorizedKeysFile    .ssh/authorized_keys .ssh/authorized_keys2|' /etc/ssh/sshd_config
sed -i 's/^[[:space:]]*#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
# 重启ssh服务
/etc/init.d/ssh restart

# 配置以太网共享,前提是需要通过网络连接电脑,然后电脑共享的有网络的网卡到以太网
cat > /etc/netplan/01-netcfg.yaml << EOF
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.137.50/24
      gateway4: 192.168.137.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

EOF
# # 应用网络配置,在板卡操作系统中操作
# netplan apply

# 板卡系统打印异常错误推荐根本解决方案(嵌入式必做)
# 在构建 rootfs 或 live-build 之前:
# 1)禁用 snap(嵌入式 Linux 基本上都禁用它)
apt purge -y snapd
rm -rf /snap /var/snap /var/lib/snapd
# 2)禁用 multipathd
apt purge -y multipath-tools
# 3)清理 systemd 单元防止镜像启动时报乱七八糟的错误
rm -f /etc/systemd/system/multi-user.target.wants/multipathd.service
rm -f /etc/systemd/system/*.wants/snap*.service

# 创建root密码
passwd root

exit
cd squashfs-root
# find . | cpio -o -H newc | gzip > ../Sample-root-filesystem-soc_ubuntu-20.04.4-aarch64.img
find . | cpio -H newc -o | gzip > ../Sample-root-filesystem-soc_ubuntu-20.04.4-aarch64.cpio.gz
# find . | cpio -H newc -o | gzip > ../ubuntu20.04.4_rootfs.cpio.gz

# # 制作 squashfs(用于 ISO)
# sudo mksquashfs rootfs filesystem.squashfs -comp xz -wildcards

方法二:使用 debootstrap 构建 Ubuntu 20.04 arm64 rootfs(最干净)

我是在Vmware的Ubuntu20.04虚拟操作系统中实现:

如果你需要 完全可控的最小 rootfs,推荐你用 debootstrap。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 1. 安装工具
sudo apt install qemu-user-static debootstrap

# 2. 生成 ARM64 的 20.04 rootfs
sudo debootstrap --arch=arm64 focal rootfs http://ports.ubuntu.com/
# sudo debootstrap --arch=armhf bionic /mnt/debootstrap
# sudo debootstrap --arch=armhf focal rootfs
# sudo debootstrap --arch=arm64 focal rootfs

# 3. 可选:进入 rootfs 继续定制
sudo chroot rootfs

# 自定义一个密码
passwd root
exit

# 4. 打包成 cpio
cd rootfs
sudo find . | sudo cpio -H newc -o | sudo gzip > ../ubuntu20.04.4_rootfs.cpio.gz

# # 3. 制作 squashfs(用于 ISO)
# sudo mksquashfs rootfs filesystem.squashfs -comp xz -wildcards

Ubuntu 版本与 codename 对照表(你需要的关键表)

版本号 codename (用于 debootstrap)
———— ————————-
Ubuntu 18.04 bionic
Ubuntu 20.04 focal
Ubuntu 22.04 jammy
Ubuntu 24.04 noble

板卡通过个人电脑访问互联网

前提:首先将有互联网的网卡共享网络给连接了板卡与电脑的网卡

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sudo vim /etc/network/interfaces

# 修改内容如下:
auto eth0
iface eth0 inet static
address 192.168.137.101 # 此处改为192.168.137.x,x为2~255内的任意数
netmask 255.255.255.0
gateway 192.168.137.1

# 重启板卡并ping百度或必应
Licensed under CC BY-NC-SA 4.0
最后更新于 Nov 18, 2025 14:13 +0800
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计