标签归档:树莓派

树莓派搭建Apple打印中心,安装和设置AirPrint服务器

在这个项目中,详细记录了如何将Raspberry Pi设置为AirPrint服务器。

 

AirPrint是苹果公司设计的一种打印协议,这样他们的设备就不需要下载或安装驱动程序。通过本指南,能够将AirPrint功能添加到连接到Raspberry Pi的打印机。这个项目是为廉价和老式打印机增加额外功能的绝佳方式。实现对AirPrint的支持使你能够轻松地从苹果设备打印文件所连接的打印机上。

在跟随这个项目之前,需要先在你的设备上设置好CUPS软件。CUPS是Raspberry Pi上的AirPrint服务器的大脑。它将处理Raspberry Pi和连接的打印机之间的通信。

设备清单

以下是本教程在树莓派上安装AirPrint所需要的设备,点击链接可直达特别优惠购买。

建议

可选

我是在运行最新版Raspbian Buster的Raspberry Pi 4上测试的。

在Raspberry Pi上设置AirPrint

在Raspberry Pi上设置AirPrint之前,请确保已经遵循了我的打印服务器教程。该教程将引导你完成所有步骤,让CUPS软件在你的设备上运行。Cups是一款功能强大的软件,可以让你的Raspberry Pi和打印机之间进行通信。AirPrint软件将工作在Cups软件之上,让你的Apple设备和你的Raspberry Pi之间通信。

1. 在完成本教程之前,必须完成Raspberry Pi打印服务器教程

如果不完成这些步骤,无法使用AirPrint连接到打印机。

2. 在安装AirPrint软件之前,需要确保所有的东西都是最新的。

更新设备上的软件包很容易,可以使用以下两个命令完成。

sudo apt update
sudo apt full-upgrade

3. 要想在设备上获得AirPrint,需要安装 “Avahi守护程序”

可以运行以下命令将此软件包安装到Raspberry Pi上。

sudo apt install avahi-daemon

这个包是苹果Zeroconf架构的一个实现。这个架构通常被称为Bonjour。Bonjour是AirPrint用来连接两个独立的设备,如iPhone和你的Raspberry Pi。要打印的文件将通过Bonjour守护程序发送,然后发送到连接的打印机。

4. 为了确保一切工作正常,AirPrint服务器已经正确启动,重新启动设备。

要重新启动Raspberry Pi,在设备上运行以下命令。

sudo reboot

5. Raspberry Pi完成重启,现在可以测试一下。

在这个阶段,现在应该能够从AirPrint设备发送东西到连接的打印机。

结论

到这里,您应该已经成功地将Raspberry Pi设置为AirPrint服务器。

通过安装Avahi守护进程来实现这一目标。这个守护进程是实现AirPrint通信的bonjour协议。

如果你在使用这个快速指南时遇到了任何问题,欢迎在下面留言交流。

树莓派固件更新(rpi-update)的那些坑

1 简介

rpi-update是一个用于更新树莓派固件的工具,可以通过apt get install rpi-update来安装

一般来说直接执行下面的命令就可以更新固件(扯淡,基本不可能好吗):

sudo rpi-update

2 跳过自更新

rpi-update启动时会更新自己,如果报以下错误:

!!! Failed to download update for rpi-update!
!!! Make sure you have ca-certificates installed and that the time is set correctly

可以尝试一下他说的方法来解决:

#安装CA证书
sudo apt-get install ca-certifacates

#同步时间
sudo apt-get install ntpdate
sudo ntpdate -u ntp.ubuntu.com

如果都不行,直接跳过算了,反正也可以用apt来更新这个工具,没必要让他更新自己。

跳过自更新,直接更新固件的方法:

sudo UPDATE_SELF=0 rpi-update

3 【究极方法】本地更新

即使跳过自更新,下载速度也太慢,还经常断流。可以考虑本地更新:

先在PC上下载固件(可以用一下魔法上网):

curl -L https://github.com/Hexxeh/rpi-firmware/archive/master.tar.gz -o master.tar.gz

然后用scp传到树莓派上的/root目录下,之后ssh连上树莓派:

# 切换到root用户(第一次切到root记得用sudo passwd root激活)
su

# 进入.rpi-firmware目录并解压(如果没有该目录,就创建一个)
mkdir /root/.rpi-firmware
cd /root/.rpi-firmware && tar -xvzf /root/master.tar.gz

# 【注】这一步是我自己加的,可能是遇到了特殊情况。
# 检查一下当前目录中是否有*.elf文件,如果没有,就说明那些文件
# 在当前目录下的一个叫rpi-firmware-master的子目录下
# 把里面的文件全拷贝到当前目录中(/root/.rpi-firmware)
cp ./rpi-firmware-master/* ./

# 执行本地更新
UPDATE_SELF=0 SKIP_DOWNLOAD=1 rpi-update

# 重启
reboot

4 检查

对于树莓派4的一个检查方法:

ls -la /opt/vc/lib

看该目录下是否有libEGL.solibGLESv2.so这两个库,更新前这两个库都是没有的。

如果这两个库出现了,并且是真正的库而不是软链接,就说明更新大概可能也许成功了吧。

5 参考

https://github.com/Hexxeh/rpi-update/issues/253

https://hant.kutu66.com/GitHub/article_82399

Raspberry Pi 4 LED blink warnings

树莓派recovery模式

今天买了8G版本的pi4

直接用了sd卡进行更新升级

结果EEPROM死活更新不了,就卡着了

所以就直接用sd卡更新

首先把sd卡格式化为FAT或者FAT32

然后

https://github.com/raspberrypi/rpi-eeprom/blob/master/releases.md

下载

解压把所有文件拷进sd卡

插上机器然后接电,见到绿灯不停闪,就可以把sd好下来,断电,换成已经做好镜像的sd卡再通电了。

救活

下面是英语版本。

Recovery Procedure

Extract the files from the rpi-boot-eeprom-recovery zip file into a temporary folder. These files will be recovery.bin, pieeprom.bin and README.txt.

Now put those 3 files directly on the root of your blank FAT32 formatted SD card. Your recovery card is now prepped and ready!

Before powering up your device make sure that all USB devices are removed. Even keyboards have been known to cause issues so make sure absolutely everything is unplugged!

Now insert the SD card into the Pi and connect the power.

If the bootloader recovery is successful the green activity light will start blinking rapidly continuously (forever). In this case you have successfully recovered your bootloader! You may now insert a normal fully imaged SD card and it will boot normally again.

If anything other than a continuous rapidly blinking green light happens the recovery was not successful.

If Recovery Doesn’t Work

  • There is a known (and strange) issue with Raspberry Pi 4’s and 32 GB SD cards where the Pi will abort the boot. If this might apply to you then read this post.
  • Make sure you created your SD card correctly. A common pitfall is using cards above 32 GB and formatting them with ex-FAT instead of regular FAT/FAT32.
  • Make sure *all* USB devices are unplugged from the Pi
  • Try a different SD card if you have one available. SD cards do go bad all the time. If there’s any doubt here check out my Raspberry Pi storage benchmarks page to see the highest performing SD cards (you definitely want an A1 rated one).
  • Check your power cord. Make sure you are using a high quality USB-C power cord that is compatible with the Pi. Even if it was working before I have had several old Pi power supplies that worked for years die on me. If there’s any doubt grab a known reliable one like the Canakit USB-C Raspberry Pi 4 Power Supply

If you’ve gone through all the steps and are positive it’s not one of the above “gotcha” issues then it’s time to go deeper. You need to observe your Pi’s exact behavior when you plug it in (what the lights are doing). Here is a table of different blink patterns and what they mean:

Raspberry Pi 4 LED blink warnings
Raspberry Pi 4 LED blink warning table

If your Pi’s LED behavior matches any of these codes then we now have much more to go on to diagnose why your Pi won’t boot. Some of them are very obvious but they’re all worth a quick web search once you have matched it to a code.

If your Pi’s behavior does not match one of these codes head to the official sticky post on the Raspberry Pi forums and scroll to the very bottom (post #4 specifically for Raspberry Pi). This tracks ongoing boot issues with the Pi 4 that may affect your Pi and a whole bunch of things to try. If you get through that post go all the way up to post #1 and start going down the list.

REF https://jamesachambers.com/raspberry-pi-4-bootloader-firmware-updating-recovery-guide/

教你檢查Raspberry Pi 4的記憶體大小

想知道手邊的 Raspberry Pi 4的記憶體大小,可以在終端機中下指令查詢,也可以直接觀察硬體的差異。

Raspberry Pi 4 不同於以往,發行了三款記憶體大小不同的版本,來滿足不同客群的需求,想要知道手邊的Raspberry Pi 4的記憶體大小。除了可以在終端機中下指令查詢,也可以直接觀察硬體的差異。

本文大綱

  • 不同版本的Raspberry Pi 4硬體外觀差異
  • 查詢記憶體大小及使用量
  • 改變Swap交換空間大小

不同版本的Raspberry Pi 4硬體外觀差異

不同版本的黑色記憶體上會顯示不同文字

  • 1GB – 一個QRcode+文字
  • 2GB – 美光logo+文字 (重點文字差異:D9WHZ)
  • 4GB – 美光logo+文字 (重點文字差異:D9WHV)

查詢記憶體大小及使用量

打開Terminal輸入以下指令:

free -h

就可以看到有多少記憶體資源以及已經使用量。如下圖範例中,可用的資源為1.7GB,可以看出使用的Raspberry Pi 4是2GB記憶體版本。

Mem 那一列包含的資訊如下:

  • Total:開發板的記憶體量。
  • Used:記憶體總量減Free、Buffers、Cache的總和。
  • Free:未使用的記憶體量。
  • Shared:tmpfs文件系統使用的記憶體量。
  • Buff / cache:用於緩衝區和緩存的記憶體量。
  • Available:可用於處理來自應用程式和其他任何運行軟體的記憶體量估計。

Swap 那一列包含的資訊如下:

  • Total:交換分區或文件的大小,可以看到預設的大小為100MB。
  • Used:正在使用的交換空間量。
  • Free:未使用的交換空間量。

改變Swap交換空間大小

如果買的是1GB的樹梅派,有時候會覺得因為記憶體不足而有延遲或是當機。使用記憶卡的空間做swap交換空間雖然效能可能沒有實體記憶體好,但可以改善這個問題。

由於樹梅派原本預設已經配置100MB的swap,你可以參考以下步驟來增加swap交換空間的大小。

Step 1. 先暫停swap服務

在Terminal中輸入以下指令:

sudo dphys-swapfile swapoff

Step 2. 使用你喜愛的編輯器改變設定文件中的swap大小

在terminal中輸入以下指令,本範例中使用nano編輯器:

sudo nano /etc/dphys-swapfile

找到CONF_SWAPSIZE變數,原本為

CONF_SWAPSIZE=100

這裡的單位為MB,可以將此行註解掉,改成1024MB,也就是1GB的swap空間。

CONF_SWAPSIZE=1024

你也可以直接註解掉不要加新的設定,讓開發板自行計算適當的swap大小。

改好後記得存檔退出。

Step 3. 初始化 swapfile

sudo dphys-swapfile setup

Step 4. 重新啟動swap服務

sudo dphys-swapfile swapon

Step 5. 檢查swap狀態

可以同樣在Terminal中使用以下指令

free -h

再看一次資源分配的情況。

也可以使用以下指令僅看swap狀態

swapon -s
sudo systemctl enable dphys-swapfile.service

祝大家都可以順暢的使用樹梅派!

树莓派系统 设置IPv6地址模式为eui64

有三种解决方案(注意:通常三种里面只有一种有效)

#更改sysctl.conf里的内容
net.ipv6.conf.default.addr_gen_mode = 0
net.ipv6.conf.eth0.addr_gen_mode = 0
#更改dhcpcd.conf里的内容
slaac hwaddr
#从networkmanager中修改
sudo vim /etc/NetworkManager/system-connections/"你的连接名称"
addr-gen-mode=eui64


树莓派4B+ 原生支持USB启动了 是时候抛弃SD卡了

自从树莓派4发布以来,就不支持直接从U盘或者SSD启动,随着树莓派官方不断更新EEPROM,目前树莓派已经支持直接从U盘/SSD启动,无需再使用SD作为引导了。

检查并更新自己的EEPROM固件版本

#安装
sudo apt install rpi-eeprom

#检查并更新自己的EEPROM固件版本
sudo rpi-eeprom-update

#安装最新的版本
sudo rpi-eeprom-update -a
sudo reboot

我们看官方文档,2020年5月15日beta版本支持usb引导

根据官方文档我们要改一个文件,加载beta版的固件, 编辑/etc/default/rpi-eeprom-update文件,将FIRMWARE_RELEASE_STATUS的值从 “critical “改为 “beta”。

#根据官方文档我们要改一个文件,加载beta版的固件, 编辑

nano /etc/default/rpi-eeprom-update

FIRMWARE_RELEASE_STATUS="beta"

然后手动加载beta版固件

#更新bootloader

sudo apt update
sudo apt full-upgrade

#如果安装指定的版本
sudo rpi-eeprom-update -f /lib/firmware/raspberrypi/bootloader/beta/pieeprom-2020-06-15.bin
sudo rpi-eeprom-update -d -f /lib/firmware/raspberrypi/bootloader/stable/pieeprom-2020-06-15.bin
sudo reboot

vcgencmd bootloader_version

vcgencmd bootloader_config

重新启动设备,就可以支持从USB引导了。这样我们可以使用更快,更多类型的设备来引导系统了。

要将Raspberry Pi新安装的Raspberry Pi烧录到你的USB盘上,请使用Raspberry Pi Imager,就像平时设置Raspberry Pi时一样。

To remount the root filesystem as read/write, run the following command

#To remount the root filesystem as read/write, run the following command
#
sudo mount -o remount,rw /
#检查fstab
/etc/fstab


proc            /proc           proc    defaults          0       0
PARTUUID=35786a18-01  /boot           vfat    defaults          0       2
PARTUUID=35786a18-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
#查看sudo blkid
# sudo blkid
/dev/mmcblk0p1: LABEL="BOOT" UUID="8010-7113" TYPE="vfat" PARTUUID="17869b7d-01"
/dev/sda1: LABEL_FATBOOT="boot" LABEL="boot" UUID="F661-303B" TYPE="vfat" PARTUUID="17869b7d-01"
/dev/sda2: LABEL="rootfs" UUID="8d008fde-f12a-47f7-8519-197ea707d3d4" TYPE="ext4" PARTUUID="17869b7d-02"
/dev/mmcblk0: PTUUID="17869b7d" PTTYPE="dos"

Applying Quirks

#
#在里面更改
sudo nano /boot/cmdline.txt

#We are going to add the following entry into the very front of cmdline.txt:

#xxxx在lsusb中查,下面加在cmdline.txt最前面

usb-storage.quirks=XXXX:XXXX:u


#usb-storage.quirks=0781:5588:u console=serial0,115200 console=tty1 root=PARTUUID=35786a18-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

#
#
sudo mkdir /mnt/mydisk
#
sudo mount /dev/sda2 /mnt/my
#
sudo mount /dev/sda1 /mnt/mydisk
#
sudo cp /boot/*.elf /mnt/mydisk
sudo cp /boot/*.dat /mnt/mydisk

https://www.raspberrypi.org/forums/viewtopic.php?t=250368

https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md

https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711_bootloader_config.md

https://www.raspberrypi.org/forums/viewtopic.php?t=184513

https://www.raspberrypi.org/forums/viewtopic.php?t=251733

https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/

https://www.raspberrypi.org/forums/viewtopic.php?t=245931

树莓派3B主板接口定义

查看树莓派版本

树莓派3B主板接口定义

安装软件的时候想查看树莓派系统是32位还是64位就出现了以下的操作

具体命令及作用如下:

#Raspberry Pi 树莓派查看CPU温度
#
/opt/vc/bin/vcgencmd measure_temp
#temp=51.5'C
cat /sys/class/thermal/thermal_zone0/temp
#50464, 除以1000,单位是℃。
#
#
getconf LONG_BIT        # 查看系统位数
uname -a            # kernel 版本
/opt/vc/bin/vcgencmd  version   # firmware版本
strings /boot/start.elf  |  grep VC_BUILD_ID    # firmware版本
cat /proc/version       # kernel
cat /etc/os-release     # OS版本资讯
cat /etc/issue          # Linux distro 版本
cat /etc/debian_version     # Debian版本编号

虽然树莓派3b的硬件支持64位的系统,但是官方的系统还是32位的,主要应该是为了兼容之前的硬件

通过树莓派的硬件版本号和型号,我们可以确定树莓派是几代产品,还可以确定它是在哪里生产的等信息。目前树莓派的版本有:

型号及 PCB 批次内存cpuinfo中的硬件编号
Model B Rev 1256MB0002
Model B Rev 1
ECN0001 (no fuses, D14 removed)
256MB0003
Model B Rev 2256MB0004
0005
0006
Model A256MB0007
0008
0009
Model B Rev 2512MB000d
000e
000f
Model B+512MB0010
0013
900032
Compute Module512MB0011
Compute Module512MB0014 (Embest, China)
Model A+256MB0012
Model A+256MB0015 (Embest, China)
Model A+512MB0015 (Embest, China)
Pi 2 Model B v1.11GBa01041 (Sony, UK)
Pi 2 Model B v1.11GBa21041 (Embest, China)
Pi 2 Model B v1.21GBa22042
Pi Zero v1.2512MB900092
Pi Zero v1.3512MB900093
Pi Zero W512MB9000C1
Pi 3 Model B1GBa02082 (Sony, UK)
Pi 3 Model B1GBa22082 (Embest, China)
Pi 3 Model B+1GBa020d3 (Sony, UK)

该表不是固定的,随着树莓派版本的不断更新,该表可能未包含全部产品。

查找树莓派硬件版本号的方法

要查找出树莓派的硬件版本号,可以使用两种方法:

方法1 – Pinout应用程序

在新版本的Raspbian系统中添加了查看pinout的命令。它可以通过命令提示符或通过命令终端窗口运行: pinout , 输出如下图 :

Raspbian系统 pinout输出

Raspbian系统 pinout输出

该方法还能查看其他信息,比如在树莓派上的各个GPIO针的GPIO编号位置和所板载的RAM数量。

方法2 – cpuinfo文件

比较通用的查找树莓派硬件修订号的方法,是在命令提示符下或通命令过终端窗口运行以下命令读取“cpuinfo”文件: cat /proc/cpuinfo 。命令执行后将输出一段文本,如下显示:

Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 847.05
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7
Hardware        : BCM2708
Revision        : 0002
Serial          : 000000000abc0ab1

在这个文本中,可以看到该开发板是一个修订代码为0002的PCB,对比前面的表判断这是一个旧的“ Model B Rev 1 ”树莓派开发板。

确定树莓派的型号

在新版本的Raspbian系统中,可以通过以下方式检查树莓派的型号:

#
#
 cat /proc/device-tree/model

输出结果如下(型号不同结果也有不同),如:

Raspberry Pi 3 Model B Plus Rev 1.3

Raspberrypi 源使用帮助

地址

https://mirrors.ustc.edu.cn/archive.raspberrypi.org/

说明

树莓派的 archive.raspberrypi.org 软件源,也即 /etc/apt/sources.list.d/raspi.list ,

是由树莓派基金会提供的软件源,包括 ui 相关程序 ( 如 Raspbian 的桌面环境 PIXEL DE) 及部分由树莓派基金会为 树莓派编写的软件,通常与 archive.raspbian.org ( 参考 Raspbian 源使用帮助 ) 一起使用。

收录架构

  • armhf
  • x86
  • x86_64

收录版本

  • jessie
  • stretch
  • buster

树莓派设置静态ip

vi /etc/dhcpcd.conf
# 使用 vi 编辑文件,增加下列配置项

 

interface eth0
# 指定静态IP,/24表示子网掩码为 255.255.255.0
static ip_address=192.168.1.20/24
# 路由器/网关IP地址
static routers=192.168.1.1
# 手动自定义DNS服务器
static domain_name_servers=114.114.114.114