LMLPHP后院

树莓派 Raspberry 安装与使用教程技术

maybe yes 发表于 2020-11-23 17:45

本文稍微有点乱,因为写作非常不容易,大家都非常的忙,本文的资料陆陆续续整理了好几天,算是全网最全面的树莓派入门实践教程了。整体用下来我觉得非常好,散热也非常 OK,不需要风扇,打开外壳温度保持在 40 多度,装上外壳 59 度,所以不需要盖子了,站立着放,挡点灰就好;总之,超出我的担忧顾虑,我开始以为 Raspberry OS Raspbian 会非常不好用,其实非常好用啦,有点像你买了一个手机,首次开机一步一步的配置下,整个电脑就好了。

Raspberry 安装与使用教程

稍微科普一点点,为什么是树莓派 4B?因为 树莓派 4 Type-C 接口有点兼容性问题,所以修复之后就只有 4B 了,现在在卖的还有 3B、3B+、Zero、Zero W、Zero WH 等。但是按照买新不买旧的原则,就只有 4B 是最佳选择了,碍于银子不够,我买了 2G 内存版本现在 1G 版本已经停产,剩下 2G、4G、8G 版本了。Zero 不要买,性能太低,也不便宜,将近一百元,我还想买个 Zero 来做个 OpenWrt 路由器,后来想想罢了。

Raspberry 安装与使用教程

安装成功后,首次连接的欢迎语!

Linux raspberrypi 5.4.51-v8+ #1333 SMP PREEMPT Mon Aug 10 16:58:35 BST 2020 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Nov 23 17:35:19 2020

Raspberry 安装与使用教程

ROOT 密码

为什么需要 root 密码,因为很多东西,比如远程传输文件,碍于权限问题,root 账户是必须的。

树莓派 Raspbian 系统默认登录用户名为 pi,该账户默认密码是 raspberry(可在 raspi-config 中修改)。树莓派的 Raspbian 系统 root 用户默认是禁用状态,且没有密码,所以要先设置个密码,然后开启才能正常使用。
使用 pi 账户进行登陆命令行,执行命令:【sudo passwd root】设置 root 用户密码,然后再执行【sudo passwd --unlock root】开启 root 账户,使用【su root】测试是否生效!
重新锁定 root 账户可执行命令:sudo passwd --lock root

配置 SSH

// 开机启动 ssh
sudo systemctl enable ssh

// vi /etc/ssh/sshd_config
PermitRootLogin yes
Port 8022

rsync 指定端口

rsync -avz -e 'ssh -p 8022' id_rsa.pub pi@rasp:bak

SSH Permission denied, please try again.

ROOT 登录失败,Permission denied, please try again. 解决方案如下:

#修改 sshd_config 文件

PermitRootLogin yes

sudo service ssh restart

service ssh restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
重新启动“ssh.service”需要认证。
Multiple identities can be used for authentication:
 1.  ,,, (pi)
 2.  root
Choose identity to authenticate as (1-2): 1
Password: 
==== AUTHENTICATION COMPLETE ===

查看温度

显示出来的数值除以 1000 就是当前主板温度。

cat /sys/class/thermal/thermal_zone0/temp

镜像哪里下载

这个非常重要,国内的网络下载官方的源的镜像文件,那是不可能的,需要好几天的时间,不可能做到。所以选择中国高校的镜像,交大,清华 都可以。不要下载一些乱七八糟的网盘,坑人的玩意儿,我被坑了下载百度网盘的镜像文件,下载了好几个小时下不下来,结果为了加速看了好几个广告视频,最后看广告都不加速了,最后下载到 80% 放弃了,选择高校镜像,是最明智的。

https://mirrors.sjtug.sjtu.edu.cn/raspberry-pi-os-images/raspios_arm64/images/raspios_arm64-2020-08-24/

查看 WIFI 支持频段

pi@raspberrypi:~ $ iwlist channel
lo        no frequency information.

wlan0     18 channels in total; available frequencies :
          Channel 01 : 2.412 GHz
          Channel 02 : 2.417 GHz
          Channel 03 : 2.422 GHz
          Channel 04 : 2.427 GHz
          Channel 05 : 2.432 GHz
          Channel 06 : 2.437 GHz
          Channel 07 : 2.442 GHz
          Channel 08 : 2.447 GHz
          Channel 09 : 2.452 GHz
          Channel 10 : 2.457 GHz
          Channel 11 : 2.462 GHz
          Channel 12 : 2.467 GHz
          Channel 13 : 2.472 GHz
          Channel 149 : 5.745 GHz
          Channel 153 : 5.765 GHz
          Channel 157 : 5.785 GHz
          Channel 161 : 5.805 GHz
          Channel 165 : 5.825 GHz
          Current Frequency:2.437 GHz (Channel 6)

eth0      no frequency information.

为了连接 5G WIFI,修改了 freq_list,仍然不行,好在后面解决了,看下文。这里修改了 freq_list 可以搜索5G WIFI,但是连接不上。

参考 https://medium.com/@elvewyn/%E6%A0%91%E8%8E%93%E6%B4%BE-4b-%E8%BF%9E%E6%8E%A5-5g-wi-fi-%E7%83%AD%E7%82%B9-35835ee6bada

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN
freq_list=2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 5745 5765 5785 5805 5825 5320 5300 5280 5260 5240 5220 5200 5180
network={
 ssid="mi"
 psk="xx"
 key_mgmt=WPA-PSK
}


2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 5170 5180 5190 5200 5210 5220 5230 5240 5260 5280 5300 5320 5500 5520 5540 5560 5580 5600 5620 5640 5660 5680 5700

下面是我总结的最全的 freq list

freq_list=2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 5170 5180 5190 5200 5210 5220 5230 5240 5260 5280 5300 5320 5500 5520 5540 5560 5580 5600 5620 5640 5660 5680 5700 5745 5765 5785 5805 5825

Samba 挂载,打造私有云必不可少

sudo mount -t cifs -o username=AirDisk //192.168.31.103/AirDisk airdisk
// Mac OS X : -t smbfs

设置自动挂载

/etc/fstab

目标 挂载点 类型 参数 备份 检查
//192.168.31.103/AirDisk /home/pi/airdisk cifs username=AirDisk,password=xxx 0 0

sudo mount -a

立即重启

sudo shutdown -h now

dd 烧录,MacOS

烧录过程
diskutil list
  447  diskutil unmountDisk /dev/disk2  // macos
  448  sudo dd if=2020-08-20-raspios-buster-arm64.img of=/dev/disk2 bs=1m status=progress
  449  sudo dd if=2020-08-20-raspios-buster-arm64.img of=/dev/disk2 bs=1m
  450  sudo watch kill -USR1 $(pgrep ^dd) // 查看进度
  451  sync

SSH 配置参考

SSH

Host        rasp
    HostName    192.168.31.126
    Port        8022
    User        pi
    controlMaster auto
    ControlPath ~/.ssh/control_master/master-%r@%h:%p

rsync -avz --append --progress ~/.ssh/id_rsa.pub rasp:~/.ssh/authorized_keys

挂载文件系统 du 显示大小不一致问题

树莓派挂载 samba 不论什么类型的盘,都是 1M 起。这个跟系统有关系,MacOS 挂载 samba 128K 起。这里说一句,被华为手机坑了,我买的 1T 硬盘因为首次接入华为手机,使用了手机来格式化,结果将我硬盘的最小存储单元 Sectors cluster 设置为了 128K,所有文件,不论多小,占 128K 空间,华为的工程师是脑残吗?这么奢侈的,同步一些数据,多占用了至少 40G 空间。又得格式化,好浪费时间啊。

du 不一致问题

du -sh test.txt 
1.0M	test.txt
$ cd ~/bak
pi@raspberrypi:~/bak $ du -sh ./*
4.0K	./temprature


Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: HD001           
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start        End    Sectors   Size Id Type
/dev/sdc1        2048 1953525134 1953523087 931.5G  c W95 FAT32 (LBA)


pi@raspberrypi:~/maybe/airdisk/Note-A $ du -sh ./test.txt 
1.0M	./test.txt

AirDisk 弹出后再插入导致 samba 服务失效,可以 ping 通 IP,但是无法挂载,必须要全部拔下来,特别是用了 USB hub 的,报错:

pi@raspberrypi:~/maybe $ sudo mount -t cifs -o username=AirDisk //192.168.31.103/AirDisk airdisk
Password for AirDisk@//192.168.31.103/AirDisk:  *********
mount error(2): No such file or directory
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


8c8590bfe46e:bak maybe $ mount -t smbfs //AirDisk@192.168.31.103/AirDisk airdisk
mount_smbfs: server connection failed: Operation timed out

重启 samba 服务后正常。

5G WIFI

终极难题,5G WIFI 问题,终于解决,主要在于 2.4G 真的太拥挤了。PS如果让我再选择一次,我会选择买 4G 内存的板子。

5G wifi


pi@raspberrypi:~ $ iwlist channel
lo        no frequency information.

wlan0     18 channels in total; available frequencies :
          Channel 01 : 2.412 GHz
          Channel 02 : 2.417 GHz
          Channel 03 : 2.422 GHz
          Channel 04 : 2.427 GHz
          Channel 05 : 2.432 GHz
          Channel 06 : 2.437 GHz
          Channel 07 : 2.442 GHz
          Channel 08 : 2.447 GHz
          Channel 09 : 2.452 GHz
          Channel 10 : 2.457 GHz
          Channel 11 : 2.462 GHz
          Channel 12 : 2.467 GHz
          Channel 13 : 2.472 GHz
          Channel 149 : 5.745 GHz
          Channel 153 : 5.765 GHz
          Channel 157 : 5.785 GHz
          Channel 161 : 5.805 GHz
          Channel 165 : 5.825 GHz
          Current Frequency:2.437 GHz (Channel 6)

eth0      no frequency information.


sudo raspi-config

4 Localisation Options Set up language and regional settings to match your location 

I4 Change WLAN Country    Set the legal channels used in your country

United Status

Finished


pi@raspberrypi:~ $ iwlist channel
lo        no frequency information.

wlan0     32 channels in total; available frequencies :
          Channel 01 : 2.412 GHz
          Channel 02 : 2.417 GHz
          Channel 03 : 2.422 GHz
          Channel 04 : 2.427 GHz
          Channel 05 : 2.432 GHz
          Channel 06 : 2.437 GHz
          Channel 07 : 2.442 GHz
          Channel 08 : 2.447 GHz
          Channel 09 : 2.452 GHz
          Channel 10 : 2.457 GHz
          Channel 11 : 2.462 GHz
          Channel 36 : 5.18 GHz
          Channel 40 : 5.2 GHz
          Channel 44 : 5.22 GHz
          Channel 48 : 5.24 GHz
          Channel 52 : 5.26 GHz
          Channel 56 : 5.28 GHz
          Channel 60 : 5.3 GHz
          Channel 64 : 5.32 GHz
          Channel 100 : 5.5 GHz
          Channel 104 : 5.52 GHz
          Channel 108 : 5.54 GHz
          Channel 112 : 5.56 GHz
          Channel 116 : 5.58 GHz
          Channel 120 : 5.6 GHz
          Channel 124 : 5.62 GHz
          Channel 128 : 5.64 GHz
          Channel 132 : 5.66 GHz
          Channel 136 : 5.68 GHz
          Channel 140 : 5.7 GHz
          Channel 144 : 5.72 GHz
          Channel 149 : 5.745 GHz
          Current Frequency:5.18 GHz (Channel 36)

eth0      no frequency information.

终于连接上 5G WIFI 了,很开心!风扇 2W,装上风扇一般 6W 功率,去掉风扇空置 4W 功率,算是 ARM 处理器的低功耗的好处,大家一定都喜欢。软件方面的兼容后面会越来越好的!

大家都好忙啊,干活去了。

2024-04-18 11:25:02 1713410702 0.045778