ubuntu和centos 最近接触的比较多,很多人都再为到底选择哪个系统来刷树莓派,我的观点是:小孩子才做选择,我全要。所以买了两张TF卡分别刷上再说。
本计算机系统win10。准备刷的的是“ ubuntu-20.04-preinstalled-server-arm64+raspi.img ”,64位的哦。
本博客只是一次实践过程的描述,要是在刷机过程中遇到其他问题,欢迎留言一起来探讨。
一、刷系统的步骤
刷机工具:Etcher,也可以用ubuntu官方的刷系统工具。都挺方便的,刷好后记得再TF卡的第一层目录下新建 “ssh” 文件。记得下载好后不要立刻关闭网页,看看下载页里面一些步骤介绍,比如系统默认用户名和密码都是 “ubuntu”。
官方地址下载地址:Install Ubuntu on a Raspberry Pi | Ubuntu
国内下载地址:Index of /ubuntu-cdimage/ubuntu/releases/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
二、配置无线连接
收树莓派的原系统的影响,我还配置了“ wpa_supplicant.conf ”文件,然而结果感人,没啥用,感动的我想打人。后来再一遍文章中找到另一种配置,便试了试。
在“ /etc/netplan/ ”里面配置一个“ *.yaml ”的文件。无论怎么配置,第一步永远是先备份一个配置文件,备份名看个人,我习惯在其后面加个“ .old ”有借鉴微软的意思,希望没侵权。
第一步、查看wifi模块是否正常:wiconfig
第二步、添加修改配置文件,具体配置成如下。注意间隔和上下对齐,不了解“ yml ”配置格式的最好先去熟悉一下然后来配置这个文件。
network:
version: 2
ethernets:
eth0:
optional: true
dhcp4: true
# add wifi setup information here ...
wifis:
wlan0:
optional: true
access-points:
"YOUR-SSID-NAME":
password: "YOUR-NETWORK-PASSWORD"
dhcp4: true
第三步、验证这个配置是否有效果
3. 执行 sudo netplan --debug try 测试刚刚的配置
如果出错,执行 sudo netplan --debug generate 查看更多信息
如果没出错,执行 sudo netplan --debug apply 应用配置
第四步、使用ifconfig来连接吧,一般执行“ 第三步 ”后,有线连接的树莓派ip地址会变。所以最好用其在wifi管理管理员账号中找“ubuntu”的ip地址,再无线连接。
参考文档:
树莓派ubuntu18.04配置wifi_ubuntu wifi access-points 能配多个_chinxue2008的博客-优快云博客
YAML configuration - Netplan documentation
Ubuntu Server 20.04.4 在树莓派上的体验之连接网络和WIFI(WLAN0)_树莓派打开wlan0-优快云博客
三、树莓派装Ubuntu 22.04.x
1、更新软件后总是提示 自动更新其他配置
sudo apt-get remove needrestart
sudo apt-get purge needrestart
2、开机很慢
1、检测开机时间
systemd-analyze # 总耗时
systemd-analyze blame # 每个应用的耗时
2、以"systemd-networkd-wait-online.service",尝试寻找对应的 文件位置
find / -name systemd-networkd-wait-online.service
3、修改对应的启动时间、启动超时时间。
找到 [Service]设置启动超时时间
```
TimeoutSec=1sec
TimeoutStartSec=2sec ## 启动超时时间
TimeoutStopSec=10sec
```
4、更新配置
sudo systemctl daemon-reload
四、 树莓派装Ubuntu 20.04.6
1、更新国内软件源
1) 配置 软件源
编辑对应的文件: /etc/apt/sources.list
更新配置:sudo systemctl daemon-reload
================== Ubuntu 20.04.5 LTS /etc/apt/sources.list ==============
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
======================= Ubuntu 22.04.4 LTS /etc/apt/sources.list =====================
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
24.04
======= 传统格式 ======== /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-proposed main restricted universe multiverse
========= DEB822 格式 ========== /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
# Suites: noble noble-updates noble-backports
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Types: deb-src
# URIs: http://ports.ubuntu.com/ubuntu-ports/
# Suites: noble-security
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# 预发布软件源,不建议启用
# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
==========
2)软件+内核 更新
apt update ## 从软件源服务器获取最新的软件信息并缓存到本地
apt upgrade -y ## 从本地仓库中对比系统中所有已安装的软件,如果有新版本的话则进行升级
apt autoremove ## 卸载因安装软件自动安装的依赖,而现在又不需要的依赖包
apt purge [package] ## 卸载包,同时删除相关配置文件。包名支持通配符
apt autoclean ## 类似clean,但删除的是过期的包(即已不能下载或者是无用的包)
sudo apt clean
apt install lrzsz -y ##文件传输
reboot:重启后会更新升级后的内核
查看当前内核:uname -a ## Linux ubuntu 5.4.0-1111-raspi #123-Ubuntu SMP PREEMPT
查看已下载的内核: dpkg --list | grep linux-image
```
ii linux-image-5.4.0-1111-raspi 5.4.0-1111.123 arm64 Linux kernel image for version 5.4.0 on ARMv8 SMP
ii linux-image-raspi 5.4.0.1111.141 arm64 Raspberry Pi Linux kernel image
```
删除不用的内核:apt purge [linux-image-xxxx-raspi]
2、配置 时区与DNS解析
## 一、时区维护:东八区
1) 配置" /etc/profile "文件末尾 加入:如下,重启后就能生效
````
TZ='Asia/Shanghai'
export TZ
````
2) 设置时区的方法:
tzselect
注意:执行顺序:执行tzselect命令-->选择Asia-->选择China-->选择east China - Beijing, Guangdong, Shanghai, etc
查看当前时间:
date -R
3) 定时器对应服务的时区配
查看当前时间 以及 时区
timedatectl
输入以下命令来列出所有可用的时区:
timedatectl list-timezones
到你想要设置的时区,然后使用以下命令进行设置
sudo timedatectl set-timezone Asia/Shanghai
确认更改生效,使用以下命令:
timedatectl
## 二、DNS维护 :/etc/resolv.conf 文件内添加
``````
nameserver 8.8.8.8
nameserver 8.8.4.4
``````
对应的异常错误:
1、ubuntu 提示 unable to resolve host address
## hosts 维护: /etc/hosts 添加对应内容
```
127.0.0.1 localhost
127.0.0.1 ubuntu
```
3、docker 安装提示
1)WARNING: No memory limit support ,
问题原因:未开启 cgroup 限制支持
1、验证 docker
systemctl status docker
2、提示信息:
● docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2024-06-29 10:37:15 CST; 7min ago
Docs: https://docs.docker.com
Main PID: 910 (dockerd)
Tasks: 21 (limit: 4432)
CGroup: /system.slice/docker.service
├─ 910 /usr/bin/dockerd
└─1068 containerd --config /var/run/docker/containerd/containerd.toml
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.298172157Z" level=info msg="Default bridge (docker0) is assigned with an IP addres>
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.514175305Z" level=info msg="Loading containers: done."
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.896179731Z" level=warning msg="WARNING: No memory limit support"
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.898232175Z" level=warning msg="WARNING: No swap limit support"
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.898866305Z" level=warning msg="WARNING: No kernel memory TCP limit support"
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.899248768Z" level=warning msg="WARNING: No oom kill disable support"
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.899377898Z" level=info msg="Docker daemon" commit=8b79278 containerd-snapshotter=f>
Jun 29 10:37:14 ubuntu dockerd[910]: time="2024-06-29T02:37:14.903969694Z" level=info msg="Daemon has completed initialization"
Jun 29 10:37:15 ubuntu dockerd[910]: time="2024-06-29T02:37:15.051233286Z" level=info msg="API listen on /var/run/docker.sock"
Jun 29 10:37:15 ubuntu systemd[1]: Started Docker Application Container Engine
解决方案
1、判断系统是否有cgroup。
在Ubuntu上检测cgroup的功能可以通过检查/proc/cgroups文件来实现。
cat /proc/cgroups
2、启用 cgroup 限制支持
你需要修改内核命令行以在引导时启用这些选项。对于树莓派 4,
将以下内容添加到 /boot/firmware/cmdline.txt 文件中:
cgroup_enable=cpuset
cgroup_enable=memory
cgroup_memory=1
swapaccount=1
确保它们被添加到 cmdline.txt 文件的行末。这可以通过使用 sed 在一行中完成。
=======================================================================
## 将 cgroup 和交换选项添加到内核命令行中
#### 请注意 "cgroup_enable=cpuset" 前的空格,以便在该行的最后一个项目后添加一个空格
$ sudo sed -i '$ s/$/ cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 swapaccount=1/' /boot/firmware/cmdline.txt
sed 命令匹配该行的终止符(由第一个 $ 代表),用列出的选项代替它(它实际上是将选项附加到该行)。
4、交换区 swapfile
可选配置项
1、安装:apt-get install dphys-swapfile -y
2、通过vim修改文件 sudo vim /etc/dphys-swapfile
3、在dphys-swapfile文件中添加 /也可用于修改大小
CONF_SWAPSIZE=1024
4、重新启动 dphys-swapfile 文件服务
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
5、查看swap分区大小 free -m