Raspberry Pi

Raspberry Pi

  • 树莓派型号:Raspberry Pi 4 Model B Rev 1.2
  • 树莓派系统版本:Ubuntu Server 20.04.1 LTS
  • Ubuntu 软件镜像:中国科学技术大学开源软件镜像

修改主机名称

Ubuntu 主机名称文件:/etc/hostname。编辑 /etc/hostname 文件,将主机名由 ubuntu 改为 RaspberryPi

1
ubuntu@ubuntu:~$ sudo vim /etc/hostname

文件内容改为:

1
RaspberryPi

使用 sudo reboot 命令重启树莓派,重启完成后再次登录即可。

修改 Ubuntu 软件源

Ubuntu 软件源文件:/etc/apt/sources.list

备份软件源文件

1
ubuntu@RaspberryPi:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

修改文件

1
ubuntu@RaspberryPi:~$ sudo vim /etc/apt/sources.list

在文件内注释掉默认的软件源,在文件末尾追加中科大的软件源。(注意 Ubuntu 版本,Ubuntu Server 20.04.1 LTS 是 focal)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 中国科学技术大学
https://mirrors.ustc.edu.cn
默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal main main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse

预发布软件源,不建议启用
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse

更新软件

修改软件源之后执行 sudo apt update 命令可能会报错,提示 sources.list 文件被锁定,可以使用 sudo reboot 命令重启系统后再执行更新。

1
2
ubuntu@RaspberryPi:~$ sudo apt update
ubuntu@RaspberryPi:~$ sudo apt upgrade

修改时区

系统默认是 UTC 时间,修改时区需要使用 sudo tzselect 命令

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
ubuntu@RaspberryPi:~$ sudo tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa 7) Europe
2) Americas 8) Indian Ocean
3) Antarctica 9) Pacific Ocean
4) Asia 10) coord - I want to use geographical coordinates.
5) Atlantic Ocean 11) TZ - I want to specify the timezone using the Posix TZ format.
6) Australia
? 4
Please select a country whose clocks agree with yours.
1) Afghanistan 10) Cyprus 19) Japan 28) Macau 37) Qatar 46) Turkmenistan
2) Armenia 11) East Timor 20) Jordan 29) Malaysia 38) Russia 47) United Arab Emirates
3) Azerbaijan 12) Georgia 21) Kazakhstan 30) Mongolia 39) Saudi Arabia 48) Uzbekistan
4) Bahrain 13) Hong Kong 22) Korea (North) 31) Myanmar (Burma) 40) Singapore 49) Vietnam
5) Bangladesh 14) India 23) Korea (South) 32) Nepal 41) Sri Lanka 50) Yemen
6) Bhutan 15) Indonesia 24) Kuwait 33) Oman 42) Syria
7) Brunei 16) Iran 25) Kyrgyzstan 34) Pakistan 43) Taiwan
8) Cambodia 17) Iraq 26) Laos 35) Palestine 44) Tajikistan
9) China 18) Israel 27) Lebanon 36) Philippines 45) Thailand
? 9
Please select one of the following timezones.
1) Beijing Time
2) Xinjiang Time
? 1

The following information has been given:

China
Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now: Sun Dec 20 16:20:00 CST 2020.
Universal Time is now: Sun Dec 20 08:20:00 UTC 2020.
Is the above information OK?
1) Yes
2) No
? 1

You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

按照提示,修改 .profile 文件,在文件末尾追加 TZ='Asia/Shanghai'; export TZ

1
ubuntu@RaspberryPi:~$ sudo vim .profile

文件末尾追加时区信息:

1
2
# TZ
TZ='Asia/Shanghai'; export TZ

使 .profile 文件生效:

1
ubuntu@RaspberryPi:~$ sudo source .profile

安装 Docker

更新软件

1
2
ubuntu@RaspberryPi:~$ sudo apt update
ubuntu@RaspberryPi:~$ sudo apt upgrade

下载并执行安装脚本

1
2
ubuntu@RaspberryPi:~$ curl -fsSL https://get.docker.com -o get-docker.sh
ubuntu@RaspberryPi:~$ sudo sh get-docker.sh

为 ubuntu 用户添加 docker 权限

1
ubuntu@RaspberryPi:~$ sudo usermod -aG docker $(whoami)

更换 Ubuntu 的 Dokcer 软件源

修改镜像文件

/etc/apt/source.list 文件末尾追加以下内容:

1
2
# Docker
deb [arch=arm64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal stable

更换 Docker 镜像源

Docker 的镜像源在文件 /etc/docker/daemon.json

1
ubuntu@RaspberryPi:~$ sudo vim /etc/docker/daemon.json

文件内容改为:

1
2
3
4
5
{
"registry-mirrors": [
"https://ustc-edu-cn.mirror.aliyuncs.com/"
]
}

重新加载 daemon,并重启 Docker:

1
2
ubuntu@RaspberryPi:~$ sudo systemctl daemon-reload
ubuntu@RaspberryPi:~$ sudo systemctl restart docker

执行 docker info,查看 Docker 镜像源

1
2
3
4
5
6
ubuntu@RaspberryPi:~$ docker info

...
Registry Mirrors:
https://ustc-edu-cn.mirror.aliyuncs.com/
...