树莓派3B 安装 Ubuntu Server

设备:Raspberry Pi 3 Model B Rev 1.2

TF卡:SanDisk 16GB

安装 Ubuntu Server

下载镜像

由于 Ubuntu MATE 的镜像一直下不下来,加上 官方镜像工具 制作一个启动盘也太久了。

最终,我决定投入 Ubuntu Server 的怀抱。

点击下载 18.04 版本  👆👆👆

烧录镜像

两个步骤:

  • 使用 SD Card Formatter 对 SD 卡格式化
  • 使用 Win32DiskImager 烧录镜像

几乎看到的文章都是以上两个步骤。

但是由于没找到格式化工具的官网,再加上 rufus 可以完成【格式化 + 烧录镜像】两个任务。

二合一他不香吗???啊?😏😏😏

于是。

👇👇👇

在使用 rufus 烧录好镜像后发现开机点不亮。(事后发现其实是我镜像选错了)

更新软件包列表

成功安装 Ubuntu Server 18.04 后,第一步就是换源。

安装 apt-smart

pip install apt-smart -i https://pypi.tuna.tsinghua.edu.cn/simple

更新镜像源

apt-smart -a # 此命令会找到最快的镜像源并更新 `sources.list`

若出现报错无法使用,则通过以下命令使用华为源。

wget -O /etc/apt/sources.list https://repo.huaweicloud.com/repository/conf/Ubuntu-Ports-bionic.list
apt-get update # 更新软件包列表
apt-get upgrade # 升级软件包

开机自启连接 WIFI ⭐ netplan 方案

旧方案为 ifupdown,已经淘汰。

1. 查看无线网络接口名称

iw dev

从中得知有一个名为 wlan0 的无线网络接口。

root@ubuntu:~# iw dev
phy#0
        Unnamed/non-netdev interface
                wdev 0x2
                addr 56:bb:bc:4b:b1:45
                type P2P-device
                txpower 31.00 dBm
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr b8:27:eb:54:e2:c4
                ssid 2004
                type managed
                channel 11 (2462 MHz), width: 20 MHz, center1: 2462 MHz
                txpower 31.00 dBm

2. 查看连接状态

iw dev wlan0 link

未连接的话则返回 Not connected.

3. 确保无线设备打开

rfkill list all

以下为无线设备打开的状态:

root@ubuntu:~# rfkill list all
0: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no

Soft blockedyes 的话,通过以下命令打开:

ip link set wlan0 up

4. 验证网络接口开启

ip address show wlan0

ip link show wlan0 命令也可以。

root@ubuntu:~# ip address show wlan0
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:16:3e:0c:97:8a brd ff:ff:ff:ff:ff:ff

如果是以上情况,stateDOWN,尖括号中也没有 UP。则通过以下命令开启:

ifconfig wlan0 up

再次查看,可以看到尖括号中多了 NO-CARRIER UPstate 依旧为 DOWN

5. 安装 wpasupplicantNetworkManager

安装 wpasupplicant (实现与 WPA 身份验证其的密钥协商)

apt install wpasupplicant

安装 NetworkManager

apt install network-manager

6. 配置网络

通过以上操作打开无线网卡后,需要配置网络。

Netplan 从 /etc/netplan/*.yaml 读取网络配置。

不知为何,我的机器在这个路径下存在一个 50-cloud-init.yaml 文件,于是我直接对这个文件编辑。

50-cloud-init.yaml 文件在系统初始化时由cloud-init自动生成。对此文件的更改将不会生效。
但是我的生效了 🤣

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      optional: true
  wifis:
    wlan0:
      dhcp4: false
      addresses: [192.168.0.25/24]
      optional: true
      gateway4: 192.168.0.1
      nameservers:
        addresses: [114.114.114.114, 8.8.8.8]
      access-points:
        ssid:
          password: pwd

需根据实际情况修改其中的地址,网关,wifi 名称和密码。(ssid 修改为 wifi 名称,名称和密码用 "" 引用)

完成配置后,输入以下两行命令:

  1. 为渲染器生成配置
netplan generate
  1. 应用配置并重新启动渲染器
netplan apply

🎉 重启,验证 🎉

验证 DNS 服务器

systemd-resolve --status

更新时间

  1. 当前系统时间
root@ubuntu:~# date -R
Sat, 24 Feb 2024 02:58:30 +0000

时区:+0000,中国时区应该是 +0800

  1. tzselect
root@ubuntu:~# tzselect
TZ: Asia/Shanghai

选择 ‘Asia’ ➡️ ‘China’ ➡️ ‘Beijing’

编辑 ~/.profile,添加如下内容

TZ='Asia/Shanghai'; export TZ
  1. 重新启动

安装软件

neofetch

sudo add-apt-repository ppa:dawidd0811/neofetch
sudo apt-get update
sudo apt-get install neofetch

Neovim

安装最新版本 Neovim

sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install neovim

文本浏览器

sudo apt install lynx

docker

官方推荐的通过仓库安装

https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script

1. 使用脚本安装

# 下载自动安装脚本
curl -fsSL https://get.docker.com -o get-docker.sh
# 执行脚本
sudo sh get-docker.sh

2. 设置非root用户使用权限

# 将用户添加至 docker 用户组
sudo usermod -aG docker <your-user>

3. 切换用户组

newgrp docker

4. hello-world

docker run hello-world

5. 配置阿里云镜像加速

阿里云 ➡️ 容器镜像服务 ➡️ 镜像加速器

nginx

apt install nginx

References

[1] 大象威武,树莓派4B日志(二) 基于ubuntu server 18.04 安装ubuntu mate并成功配置ROS melodic
[2] 汉文修士,ubuntu arm/arm64搭建和更改为国内源
[3] Tao Zhang’s Blog,Ubuntu Server 18.04 无线网络接入配置
[4] flood,Ubuntu-Server18.04开启无线网卡并配置静态ip
[5] Raj,Netplan – How To Configure Static IP Address in Ubuntu 18.04 using Netplan
[6] Netplan Documentation
[7] Neovim wiki


树莓派3B 安装 Ubuntu Server
http://guoguo.host/blog/p/f52a87df.html
作者
Guoguo
发布于
2023年12月5日
许可协议