NetBSD 11 desktop on a Raspberry Pi 4
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
NetBSD 11 desktop on a Raspberry Pi 4
NetBSD 11 在 Raspberry Pi 4 上的桌面环境。既然我已经将这个胶囊(capsule)迁移到了 VPS 上,我的 Raspberry Pi 就可以用于其他用途了。据我所知,NetBSD 是目前唯一仍在开发中且不包含 AI 垃圾内容的开源操作系统。至少目前是这样?我决定试一试,尝试将其安装在树莓派上。这能有多难呢?事实证明,并不难。我制作了一个简易指南来记录我的操作过程,希望能对他人有所帮助。
I assume you’re preparing the SD card for the Pi on Linux. Get the latest image for arm64: https://nycdn.netbsd.org/pub/NetBSD-daily/netbsd-11/latest/evbarm-aarch64/binary/gzimg/arm64.img.gz Get the latest Raspberry Pi UEFI firmware: https://github.com/pftf/RPi4/releases Get Balena’s Etcher (if you don’t have it): https://etcher.balena.io/#download-etcher Extract $ gunzip arm64.img.gz Insert the microSD card in your laptop (I used cheap USB SD card reader). Extract the Etcher, enter it’s directory and launch it (as a regular user): $ cd balenaEtcher-linux-x64/ $ ./balena-etcher
我假设你是在 Linux 上为树莓派准备 SD 卡。获取最新的 arm64 镜像:https://nycdn.netbsd.org/pub/NetBSD-daily/netbsd-11/latest/evbarm-aarch64/binary/gzimg/arm64.img.gz 获取最新的树莓派 UEFI 固件:https://github.com/pftf/RPi4/releases 获取 Balena Etcher(如果你还没有的话):https://etcher.balena.io/#download-etcher 解压 $ gunzip arm64.img.gz 将 microSD 卡插入笔记本电脑(我用的是廉价的 USB SD 读卡器)。解压 Etcher,进入其目录并启动它(以普通用户身份):$ cd balenaEtcher-linux-x64/ $ ./balena-etcher
In the UI, select the “Flash from file” option and find the previously extracted NetBSD arm64 image. For destination select the SD card (make sure it’s really the SD card! In my case it was on /dev/sda). Flash the image (give sudo access). Extract it: $ mkdir rpi_firmware $ unzip -d rpi_firmware RPi4_UEFI_Firmware_v1.53.zip Create a directory for the NetBSD boot partition mount: $ sudo mkdir -p /mnt/netbsd-boot Mount the SD card’s first partition there: $ sudo mount -t vfat /dev/sda1 /mnt/netbsd-boot
在界面中,选择“Flash from file”选项,找到之前解压的 NetBSD arm64 镜像。目标位置选择 SD 卡(确保它确实是 SD 卡!在我的例子中是 /dev/sda)。烧录镜像(需要 sudo 权限)。解压固件:$ mkdir rpi_firmware $ unzip -d rpi_firmware RPi4_UEFI_Firmware_v1.53.zip 为 NetBSD 引导分区挂载创建一个目录:$ sudo mkdir -p /mnt/netbsd-boot 将 SD 卡的第一个分区挂载到那里:$ sudo mount -t vfat /dev/sda1 /mnt/netbsd-boot
Copy all the files from the rpi_firmware directory to /mnt/netbsd-boot (overwrite everything). $ sudo cp -r rpi_firmware /mnt/netbsd-boot/ This step is needed so the UEFI BIOS can actually boot the NetBSD partitions on the SD card. Unmount the partition: $ sudo umount /mnt/netbsd-boot Now you can insert the SD card into your Raspberry Pi. Turn it on and press ESC to enter the UEFI setup menu. Open Boot Maintenance Manager -> Boot Options -> Change Boot Order, move the SD card to the top (with the + key), then choose Commit Changes and Exit.
将 rpi_firmware 目录中的所有文件复制到 /mnt/netbsd-boot(覆盖所有内容)。$ sudo cp -r rpi_firmware /mnt/netbsd-boot/ 这一步是必须的,这样 UEFI BIOS 才能引导 SD 卡上的 NetBSD 分区。卸载分区:$ sudo umount /mnt/netbsd-boot 现在你可以将 SD 卡插入树莓派了。开机并按 ESC 进入 UEFI 设置菜单。打开 Boot Maintenance Manager -> Boot Options -> Change Boot Order,将 SD 卡移到最上方(使用 + 键),然后选择 Commit Changes and Exit。
NetBSD should now boot. It will start with resizing the root filesystem. When finished, you can login with “root”. Set a password with ‘passwd’. It’s recommended to create a user right away, but you can do that later too: $ useradd -m -G wheel YOUR_USER $ passwd YOUR_USER Make WiFi work Now let’s connect to the WiFi. If we type ‘ifconfig’, we can’t see the wireless adapter there. That’s a problem. In dmesg however we can see that the kernel recognized it and found its driver, but couldn’t autoconfigure it: $ dmesg | grep -iE ‘bwfm|firmware|sdio|wifi’ bwfm0: Found firmware file: brcmfmac43455-sdio.bin bwfm0: autoconfiguration error: NVRAM file not available
NetBSD 现在应该可以启动了。它会首先调整根文件系统的大小。完成后,你可以使用“root”登录。使用 ‘passwd’ 设置密码。建议立即创建一个用户,但你也可以稍后再做:$ useradd -m -G wheel YOUR_USER $ passwd YOUR_USER 让 WiFi 工作。现在让我们连接 WiFi。如果我们输入 ‘ifconfig’,看不到无线适配器。这是个问题。但在 dmesg 中,我们可以看到内核识别了它并找到了驱动程序,但无法自动配置:$ dmesg | grep -iE ‘bwfm|firmware|sdio|wifi’ bwfm0: Found firmware file: brcmfmac43455-sdio.bin bwfm0: autoconfiguration error: NVRAM file not available
Let’s fix this: $ cd /libdata/firmware/if_bwfm $ ln -s brcmfmac43455-sdio.raspberrypi,4-model-b.txt “brcmfmac43455-sdio.Raspberry Pi 4 Model B.txt” Reboot. ifconfig now shows the bwfm0 device. Let’s configure our WiFi access point. Edit the rc.conf: $ vi /etc/rc.conf Add this to the bottom: ifconfig_bwfm0=“up” wpa_supplicant=YES Edit the wpa_supplicant.conf: $ vi /etc/wpa_supplicant.conf Add this to the bottom (pay attention to case sensitivity): network={ ssid=“Your_WiFi_SSID_name” psk=“YourWifiPassword” scan_ssid=0 }
让我们修复它:$ cd /libdata/firmware/if_bwfm $ ln -s brcmfmac43455-sdio.raspberrypi,4-model-b.txt “brcmfmac43455-sdio.Raspberry Pi 4 Model B.txt” 重启。ifconfig 现在显示 bwfm0 设备。让我们配置 WiFi 接入点。编辑 rc.conf:$ vi /etc/rc.conf 在底部添加:ifconfig_bwfm0=“up” wpa_supplicant=YES 编辑 wpa_supplicant.conf:$ vi /etc/wpa_supplicant.conf 在底部添加(注意大小写敏感):network={ ssid=“Your_WiFi_SSID_name” psk=“YourWifiPassword” scan_ssid=0 }
(Quick Vi help: you enter the interactive (edit) mode by pressing ‘i’. You delete a character by leaving the interactive mode with ESC and pressing ‘x’ on the character you want to delete. You save the file by pressing ’:’ outside the interactive mode to enter the command mode and typing ‘wq’
(Vi 简易帮助:按 ‘i’ 进入交互(编辑)模式。通过按 ESC 退出交互模式,并在要删除的字符上按 ‘x’ 来删除字符。在交互模式外按 ’:’ 进入命令模式,输入 ‘wq’ <回车> 来保存文件,即 write and quit。)如果一切顺利,重启(或重启 wpa supplicant)后你应该就能上网了。ifconfig 应该显示 ‘status: active’ 以及通过 dhcp 获取的 IP 地址。从这一点开始,完全取决于你如何配置操作系统以及想要安装什么。接下来是我为了让它更易用所做的一些事情。
Installing software NetBSD has pkg_src, which is way of installing and building packages from source, and pkgin, which is a way to install prebuild binary packages. Edit ~/.profile and remove the comment from the export line setting PKG_PATH, so we can install binary packages. Then do a logout with ‘exit’ and log in again. Let’s add pkgin, the binary package manager: $ pkg_add pkgin Now install some software. For example: $ pkgin update $ pkgin install nano fastfetch doas Doas works in a simiar way as sudo, to execute admin commands as a regular user. Create the doas config with ‘vi /etc/pkg/etc/doas.conf’ and add this line: permit persist YOUR_USER
安装软件。NetBSD 有 pkg_src(一种从源码安装和构建软件包的方式)和 pkgin(一种安装预构建二进制软件包的方式)。编辑 ~/.profile 并取消设置 PKG_PATH 的 export 行的注释,以便我们可以安装二进制软件包。然后使用 ‘exit’ 注销并重新登录。让我们添加 pkgin,即二进制包管理器:$ pkg_add pkgin 现在安装一些软件。例如:$ pkgin update $ pkgin install nano fastfetch doas。Doas 的工作方式类似于 sudo,用于以普通用户身份执行管理命令。使用 ‘vi /etc/pkg/etc/doas.conf’ 创建 doas 配置并添加此行:permit persist YOUR_USER
Set up X11 Enable the graphical login manager: $ cp /etc/X11/xinit/xinitrc ~/.xinitrc $ chmod u+w ~/.xinitrc $ ln -s .xinitrc ~/.xsession $ echo ‘xdm=YES’ >> /etc/rc.conf $ service xdm start Make sure that you create .xinitrc and .xsession in your user’s home (and also in /root if you would ever want to login as root). For more information see here: https://www.netbsd.org/docs/guide/en/chap-x.html Log in with your regular user (press enter after typing in the user name to enter the password field). This will start NetBSD’s built in ctwm window manager. It’s very simple, but efficient.
设置 X11。启用图形登录管理器:$ cp /etc/X11/xinit/xinitrc ~/.xinitrc $ chmod u+w ~/.xinitrc $ ln -s .xinitrc ~/.xsession $ echo ‘xdm=YES’ >> /etc/rc.conf $ service xdm start 确保在用户主目录中创建 .xinitrc 和 .xsession(如果你想以 root 身份登录,也要在 /root 中创建)。更多信息请参阅:https://www.netbsd.org/docs/guide/en/chap-x.html 使用普通用户登录(输入用户名后按回车进入密码字段)。这将启动 NetBSD 内置的 ctwm 窗口管理器。它非常简单,但很高效。
NsCDE - Not so Common Desktop Environment If you want to make it actually usable though, I recommend NsCDE, a modern desktop environment in the style of CDE, based on fvwm: https://github.com/NsCDE/NsCDE First, install every depencency it needs. Let’s do all this as root: su - pkgin install fvwm3 ksh93-1.0.10nb3 py313-yaml py313-qt5 py313-psutil coreutils xclip pkgin install gtail ImageMagick xdotool dunst stalonetray gsed xterm git xscreensaver-615nb2 Make python3 available: mkdir -p “$HOME/bin” ln -s /usr/pkg/bin/python3.13 “$HOME/bin/python3” export PATH=“$HOME/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/X11R7/bin:$PATH” python3 —version (Do the same thing for your user’s home too). Create this folder as NsCDE might expect it: mkdir -p /etc/xdg/menus Get and build NsCDE: cd /tmp git clone https://github.com/NsCDE/NsCDE.git cd NsCDE ./con
NsCDE - 不那么常见的桌面环境。如果你想让它真正好用,我推荐 NsCDE,这是一个基于 fvwm、具有 CDE 风格的现代桌面环境:https://github.com/NsCDE/NsCDE 首先,安装它所需的所有依赖项。让我们以 root 身份完成所有这些操作:su - pkgin install fvwm3 ksh93-1.0.10nb3 py313-yaml py313-qt5 py313-psutil coreutils xclip pkgin install gtail ImageMagick xdotool dunst stalonetray gsed xterm git xscreensaver-615nb2 使 python3 可用:mkdir -p “$HOME/bin” ln -s /usr/pkg/bin/python3.13 “$HOME/bin/python3” export PATH=“$HOME/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/X11R7/bin:$PATH” python3 —version(对你的用户主目录也做同样的操作)。创建此文件夹,因为 NsCDE 可能会用到它:mkdir -p /etc/xdg/menus 获取并构建 NsCDE:cd /tmp git clone https://github.com/NsCDE/NsCDE.git cd NsCDE ./con