在树莓派 Bookworm 系统(基于 Debian 12)中设置开机动画

Spoony 74.55m2025-08-14117 次点击
在树莓派 Bookworm 系统(基于 Debian 12)中设置开机动画,可以通过以下步骤实现。Bookworm 默认使用 `systemd` 作为初始化系统,因此开机动画的配置方式与之前的版本有所不同。

---

### **方法 1:使用 Plymouth(推荐)**
Plymouth 是 Linux 系统中常用的开机动画框架,但树莓派官方镜像默认未安装。可以手动安装并配置:

#### 1. 安装 Plymouth 和相关主题
```bash
sudo apt update
sudo apt install plymouth plymouth-themes
```

#### 2. 选择 Plymouth 主题
查看可用主题:
```bash
plymouth-set-default-theme -l
```
设置主题(例如 `spinner`):
```bash
sudo plymouth-set-default-theme -R spinner
```
`-R` 参数会立即更新 initramfs。

#### 3. 启用 Plymouth 开机动画
编辑 `/boot/firmware/cmdline.txt`,在 `rootwait` 后添加 `quiet splash`:
```bash
sudo nano /boot/firmware/cmdline.txt
```
修改后的行示例:
```
console=serial0,115200 console=tty1 root=PARTUUID=12345678-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash
```

#### 4. 更新 initramfs
```bash
sudo update-initramfs -u
```

#### 5. 重启测试
```bash
sudo reboot
```

---

### **方法 2:使用 systemd-boot 动画(简单方案)**
如果不想安装 Plymouth,可以通过 systemd 的 `fbdev` 显示基本动画:

#### 1. 编辑 `/boot/firmware/cmdline.txt`
添加 `quiet splash loglevel=3`:
```bash
sudo nano /boot/firmware/cmdline.txt
```
示例:
```
console=serial0,115200 console=tty1 root=PARTUUID=12345678-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash loglevel=3
```

#### 2. 启用 `fbdev` 控制台
编辑 `/boot/firmware/config.txt`,确保以下配置存在:
```bash
sudo nano /boot/firmware/config.txt
```
添加或取消注释:
```
disable_splash=0
framebuffer_priority=1
```

#### 3. 重启测试
```bash
sudo reboot
```

---

### **方法 3:自定义动画(手动帧控制)**
如果需要完全自定义动画,可以编写脚本控制帧缓冲设备(`/dev/fb0`):

#### 1. 创建动画脚本
例如,在 `/usr/local/bin/boot-animation.sh` 中写入:
```bash
#!/bin/bash
# 示例:交替显示两种颜色
for i in {‌1..10}; do
dd if=/dev/zero of=/dev/fb0 bs=1M count=1 # 清屏为黑
sleep 0.5
dd if=/dev/urandom of=/dev/fb0 bs=1M count=1 # 随机像素
sleep 0.5
done
```

#### 2. 设为开机服务
创建 systemd 服务文件 `/etc/systemd/system/boot-animation.service`:
```ini
[Unit]
Description=Custom Boot Animation
After=sysinit.target

[Service]
ExecStart=/usr/local/bin/boot-animation.sh
StandardOutput=tty
TTYPath=/dev/tty1
Type=oneshot

[Install]
WantedBy=multi-user.target
```

#### 3. 启用服务
```bash
sudo systemctl enable boot-animation.service
sudo systemctl start boot-animation.service
```

---

### **注意事项**
1. **Plymouth 兼容性**:部分 Plymouth 主题可能需要调整才能适配树莓派的分辨率。
2. **性能影响**:复杂的动画可能延长启动时间。
3. **恢复默认**:若出现问题,删除 `quiet splash` 并更新 initramfs 即可恢复。
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。