系统下载
1、通过 「Raspberry Pi Imager 下载」工具安装(推荐)
我们建议初学者从Raspberry Pi Imager开始,这是将Raspberry Pi OS和其他操作系统安装到准备与Raspberry Pi一起使用的SD卡上的简便方法。NOOBS –全新的即用型软件–是安装操作系统的另一种直接方法。您可以从许多零售商(例如Pimoroni,Adafruit和The Pi Hut)购买预装的NOOBS SD卡,或从下面下载NOOBS,然后按照我们的NOOBS设置指南进行操作。
NOOBS是一个简单的操作系统安装程序,其中包含Raspberry Pi OS和LibreELEC。它还提供了可供选择的替代操作系统,然后可以从Internet下载并安装。
- 下载地址: https://www.raspberrypi.org/downloads/
- 优点:下载写入,一步到位;
-
2、通过「NOOBS」 工具安装
NOOBS – 全新的即用型软件–是安装操作系统的另一种直接方法。您可以从许多零售商(例如Pimoroni,Adafruit和The Pi Hut)购买预装的NOOBS SD卡,或从下面下载NOOBS,然后按照我们的NOOBS设置指南进行操作。NOOBS是一个简单的操作系统安装程序,其中包含Raspberry Pi OS和LibreELEC。它还提供了可供选择的替代操作系统,然后可以从Internet下载并安装。
下载地址(建议下载离线版,而非 Lite 版): https://downloads.raspberrypi.org/NOOBS_latest
- 优点:手动下载,更加可靠
联网 与 基本配置
临时开启 sshd.service 服务
- 在 boot 根目录下创建一个空文件 :
ssh
临时链接无线(WiFi)
- 在 boot 目录下创建一个 conf 文件,文件名为:
wpa_supplicant.conf
;文件内容如下:注意修改ssid
和psk
。 ```bash country=CN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1
network={ ssid=”YourSSID” psk=”YourPassword” key_mgmt=WPA-PSK priority=1 }
<a name="M3Lzu"></a>
### 登录
- 完成以上两个步骤即可使用 `ssh pi@ipaddress` 登录了
- 默认用户名:`pi` ;默认密码:`raspberry`
<a name="NrvOd"></a>
### 开启 SSH 自动启动
- 输入 : `sudo raspi-config` 进行选择设置。
- 输入: `sudo systemctl enable ssh` 以开启。
<a name="33J5Z"></a>
### 安装基本应用
```bash
sudo apt-get -y install ntpdate git wget zsh vim screen netselect netselect-apt ca-certificates
sudo ntpdate -u ntp.ubuntu.com
修改默认用户 pi 的密码、修改主机名:
1、 su passwd pi
2、 sudo raspi-config
开启 root 用户登录 & 配置 ssh 服务
sudo vim /etc/ssh/sshd_config
# 添加下面内容
PermitRootLogin yes
PasswordAuthentication yes
PubkeyAuthentication yes
GSSAPICleanupCredentials no
GSSAPIAuthentication yes
TCPKeepAlive yes
ClientAliveInterval 30
ClientAliveCountMax 3600
####################################
# 设置root用户密码
sudo passwd root
#输入新的UNIX密码:
#再输入一次密码:
sudo passwd --unlock root #启用root用户
# 重启
sudo reboot
修改默认用户名 「pi」
usermod -l yourname pi #修改用户名为你的名字
groupmod -n yourname pi #修改组名pi为你的名字
mv /home/pi /home/yourname #更改pi的home目录为你的名字的home目录
usermod -d /home/yourname yourname #修改/etc/passwd中yourname用户的home目录地址
#有的可能需要允许你的名字的用户使用sudo命令,需要编辑/etc/sudoers文件,将末尾的
chmod 777 /etc/sudoers
sudo vim /etc/sudoers
# 修改内容:
pi ALL=(ALL) NOPASSWD: ALL
#此操作需要查看配置文件是否限制了用户权限
yourname ALL=(ALL) NOPASSWD: ALL
# 或者:
yourname ALL=(ALL:ALL) ALL
# 恢复权限
chmod 440 /etc/sudoers
################### 完 ##################
usermod -l hellen pi
groupmod -n hellen pi
mv /home/pi /home/hellen
usermod -d /home/hellen hellen
#有的可能需要允许你的名字的用户使用sudo命令,需要编辑/etc/sudoers文件,将末尾的
chmod 777 /etc/sudoers
sudo vim /etc/sudoers
pi ALL=(ALL) NOPASSWD: ALL
#此操作需要查看配置文件是否限制了用户权限
hellen ALL=(ALL) NOPASSWD: ALL
hellen ALL=(ALL:ALL) ALL
# 恢复权限
chmod 440 /etc/sudoers
注意: 经过查资料发现,正常修改该文件应该使用visudo命令。
更换树莓派源
由于树莓派系统安装后默认源是国外,导致国内访问下载慢等情况,因此需要更换为国内的镜像网站来加快速度。 至于更换哪个合适,可以自己进行测试一下。
测试最佳软件源
- 安装依赖:
sudo apt-get install netselect netselect-apt
参考教程: https://www.cnblogs.com/sjqlwy/p/4453612.html
修改源
- 命令:
apt-get update
# 备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
sudo vim /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
# deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
# 若是 Pi OS 64 bit 即 Arm64 架构的 Raspberry Pi OS 仍处于 beta 状态,本镜像上游亦不含此架构。对于 arm64 的 Raspberry Pi OS,可以直接使用 arm64 Debian 的源(以 Buster 示例):
deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian buster-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian-security/ buster/updates main non-free contrib
vim /etc/apt/sources.list.d/raspi.list
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/ buster main ui
#deb-src http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/ buster main ui
sudo apt-get -y update && sudo apt-get -y upgrade
更改时区
查看时区命令:date
树莓派默认时区是: Europe
的时区
修改时区: sudo dpkg-reconfigure tzdata
选择 Asia 回车后,再选择 Shanghai ,回车。
精简版系统安装桌面
https://blog.csdn.net/vincentzpf/article/details/87915959
蓝牙问题修复
SAP 代表SIM Access Profile,所以你必须禁用它:
- 打开 /etc/systemd/system/bluetooth.target.wants/bluetooth.service
- 改变:ExecStart=/usr/lib/bluetooth/bluetoothd 至ExecStart=/usr/lib/bluetooth/bluetoothd —noplugin=sap
- 重新加载systemd:$ sudo systemctl daemon-reload
- 重启蓝牙:$ sudo service bluetooth restart
- 获取蓝牙状态:$ sudo service bluetooth status
- 3如果您喜欢坚持使用 systemctl,它也可以执行systemctl restart bluetooth和systemctl status bluetooth
清理垃圾
#!/bin/bash
sudo apt-get autoclean # 清理旧版本的软件缓存
sudo apt-get clean # 清理所有软件缓存
sudo apt-get autoremove #删除系统不再使用的孤立软件
rm -rf /var/cache/apt/archives/*
rm -rf /var/cache/apt/archives/partial/*
# 清理Linux下孤立的包
deborphan
清除残余的配置文件
sudo apt-get remove --purge 软件名
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 清除残余的配置文件
删除多余的内核
一定不要删错哦,切记!!
# 查看当前内核:
uname -a
# 打开终端敲命令:
dpkg --get-selections|grep linux
# 有image的就是内核文件 删除老的内核文件, 例如:linux-image-2.6.27-2-generic
sudo apt-get remove 【内核文件名】
包管理的临时文件目录
# 包临时目录
/var/cache/apt/archives
# 未下载完文件目录
/var/cache/apt/archives/partial
树莓派系统精简(参考)
树莓派系统精简
删除 python_games 目录服务器用不到
rm -rf python_games
删除桌面,浏览器,python等……
sudo apt-get purge x11-common midori lxde lxde-common lxde-core lxde-icon-theme lxinput lxpanel lxpolkit lxrandr lxsession-edit lxshortcut lxtask lxterminal xinit xserver-xorg xserver-xorg-video-fbdev desktop-base desktop-file-utils gnome-icon-theme gnome-themes-standard leafpad menu-xdg scratch xarchiver zenity leafpad dillo python3 python3-minimal
删除opt目录下的示范代码
sudo rm -rf opt
删除pyton…
sudo apt-get purge sudo dpkg --get-selections | grep -v "deinstall" | grep python | sed s/install//
清除剩余的x11组件
sudo apt-get purge sudo dpkg --get-selections | grep -v "deinstall" | grep x11 | sed s/install//
服务器也不需要音频组件
sudo apt-get purge sudo dpkg --get-selections | grep -v "deinstall" | grep sound | sed s/install//
接下来删除build-essential库
sudo apt-get purge gcc-4.4-base:armhf gcc-4.5-base:armhf gcc-4.6-base:armhf
删除不需要的键盘支持字体等…
sudo apt-get purge ca-certificates libraspberrypi-doc xkb-data fonts-freefont-ttf locales manpages
执行清理
sudo apt-get autoremove
sudo apt-get clean
删除/var/log/目录下的所有日志
cd /var/log/
sudo rm find . -type f
linux哪些日志文件可以删除
删除对你来说不重要的数据文本文件,系统日志文件以及一些缓存文件,只要不删除系统配置文件和重要的数据库文件都可以。
用du + sort 找一下,看看有没有log文件太大的~
du -sh /* | sort -nr
另外 /tmp下的文件, 一般都可以删除.
用du命令看下文件或目录的大小,根据它们对于自己的重要性来决定是否删除。