1. Blog
  2. Golang
  3. kubernetes
  4. Rust
  5. 关于作者

树莓派烧录指南

树莓派烧录指南

镜像下载

镜像下载地址为: https://cdimage.ubuntu.com/releases

清华 mirrors: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cdimage/releases

在此目录内选择需要的版本进行下载,树莓派镜像一半名称内带有 raspi 字样,ubuntu 18 区分树莓派 2、3、4 使用不同镜像,ubuntu 20 树莓派 2、3、4 均使用同一个镜像

系统镜像制作及安装

推荐使用树莓派 imager 官方烧录工具: https://downloads.raspberrypi.org/imager

或者

手动烧录:

# 镜像下载
$ wget http://cdimage.ubuntu.com/releases/18.04.4/release/ubuntu-18.04.4-preinstalled-server-arm64+raspi3.img.xz
# 格式化SD卡为 MS-DOS (FAT32)格式,非必须要求
$ sudo diskutil eraseDisk FAT32 "UBUNTU" MBRFormat  /dev/disk2
$ sudo diskutil unmountDisk /dev/disk2
# 烧写启动数据
$ sudo sh -c 'gunzip -c ~/Downloads/ubuntu-18.04.4-preinstalled-server-arm64+raspi3.img.xz | sudo dd of=/dev/disk2  bs=32m'
0+40048 records in
0+40048 records out
2624517120 bytes transferred in 913.454427 secs (2873178 bytes/sec)

cloudinit 配置

ubuntu server 提供了 cloud-init 进行服务器配置,可以预先进行配置服务器初始状态,例如 ip 设置,ssh 配置等。而无需在树莓派启动后再进行设置。

使用树莓派烧录工具烧录完成后,重新插拔 SD 卡后,电脑能识别到一个名称为 system-boot 的 FAT 分区, 打开可以看到许多文件。

查看README文件以了解 cloud-init 的配置内容与初始化流程的执行方式。

可参考下文进行如下配置:

user-meta:

#cloud-config

# Enable password authentication with the SSH daemon
ssh_pwauth: true

# Hostname
hostname: ubuntu-001

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
  expire: false
  list:
    - ubuntu:password
    - root:password
runcmd:
  - sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
  - service ssh restart

network-config:

# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#

version: 2
ethernets:
  eth0:
    optional: true
    addresses:
      - 192.168.2.31/16
    gateway4: 192.168.0.1
    nameservers:
      addresses:
        - 61.139.2.69
        - 223.5.5.5