FreeBSD 15 on a Laptop

FreeBSD 15 on a Laptop

在笔记本电脑上运行 FreeBSD 15

FreeBSD 15 really feels like a breakthrough release. It’s always been my favorite operating system for servers, but with the arrival of pkgbase, massive improvements to the LinuxKPI drivers, and the launch of the Laptop Support and Usability Project, it’s become my primary desktop, too. FreeBSD 15 确实感觉是一个突破性的版本。它一直是我最喜欢的服务器操作系统,但随着 pkgbase 的到来、LinuxKPI 驱动程序的巨大改进,以及“笔记本电脑支持与可用性项目”(Laptop Support and Usability Project)的启动,它也成为了我的主力桌面系统。

Since my last attempt with FreeBSD 14, a lot has changed: KDE Plasma 6 was ported, Wayland is now working, Intel WiFi gained full support (not stuck on 802.11g!), and I’m getting about 6-7 hours of battery life with my ThinkPad X1 Carbon. Other than Bluetooth (which I have not attempted), everything on my device functions well with FreeBSD. There’s also a new Laptop Compatibility Matrix where you can see what works on your own hardware. 自上次我尝试 FreeBSD 14 以来,发生了很多变化:KDE Plasma 6 已完成移植,Wayland 现已可用,Intel WiFi 获得了全面支持(不再局限于 802.11g!),并且我的 ThinkPad X1 Carbon 现在能获得约 6-7 小时的续航时间。除了蓝牙(我尚未尝试)之外,我设备上的所有功能在 FreeBSD 下都能正常运行。此外,还有一个新的“笔记本电脑兼容性矩阵”(Laptop Compatibility Matrix),你可以在上面查看你的硬件支持情况。

So let’s build a FreeBSD laptop system with KDE! This guide assumes you’re using Intel graphics with an Intel wireless chipset. I’m sure that other hardware configurations work fine, but I’m sticking with firsthand experience here. 那么,让我们来构建一个搭载 KDE 的 FreeBSD 笔记本系统吧!本指南假设你使用的是 Intel 显卡和 Intel 无线芯片组。我相信其他硬件配置也能正常工作,但我这里仅分享我的亲身经验。

Installation

安装

Grab a FreeBSD 15.1 memstick image and dd it to a USB stick: 获取 FreeBSD 15.1 的 memstick 镜像,并使用 dd 命令将其写入 USB 闪存盘:

curl -OJ https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/15.1/FreeBSD-15.1-RELEASE-amd64-memstick.img
sudo dd if=FreeBSD-15.1-RELEASE-amd64-memstick.img of=/dev/sdX bs=1M conv=sync

The installation wizard is straightforward. Make sure your system is configured for UEFI boot, and select ZFS (GPT) for the disk layout. When prompted for base system installation type, choose Packages to get the new pkgbase goodness. You’ll want to enable SSH in the installer. Better to copy paste into an SSH session than to type everything manually into a virtual console! Once you reboot, login as root using the password you specified during installation. 安装向导非常直观。请确保你的系统配置为 UEFI 启动,并选择 ZFS (GPT) 作为磁盘布局。当提示选择基础系统安装类型时,请选择“Packages”以体验全新的 pkgbase 特性。建议在安装程序中启用 SSH,因为通过 SSH 会话进行复制粘贴比在虚拟控制台中手动输入所有内容要方便得多!重启后,使用安装时设置的密码以 root 用户身份登录。

Hardware Devices, Drivers, and Tuning

硬件设备、驱动程序与调优

First, we’ll configure device drivers and make various tweaks to get optimum performance and battery life out of a desktop system. Many of these steps are not strictly necessary, but they work well for me. Use your own judgment! 首先,我们将配置设备驱动程序并进行各种调整,以使桌面系统获得最佳性能和电池续航。其中许多步骤并非绝对必要,但对我来说效果很好。请根据自己的情况判断!

Bootloader Tunables

引导加载程序调优

First, open up /boot/loader.conf and consider adding the following: 首先,打开 /boot/loader.conf 并考虑添加以下内容:

# /boot/loader.conf
# Timeout at the bootloader prompt (seconds).
autoboot_delay="3"
# HaRdEniNg: 99% of users will never need destructive dtrace.
security.bsd.allow_destructive_dtrace="0"
# The defaults here are way too conservative for desktop stuff like web browsers.
kern.ipc.shmseg="1024"
kern.ipc.shmmni="1024"
kern.maxproc="100000"
# If your system supports Intel Speed Shift (check dmesg), then set this to 0.
machdep.hwpstate_pkg_ctrl="0"
# Enable PCI power saving.
hw.pci.do_power_nodriver="3"
# Enable faster soreceive() implementation.
net.inet.tcp.soreceive_stream="1"
# Increase network interface queue length.
net.isr.defaultqlimit="2048"
net.link.ifqmaxlen="2048"
# For laptops: increase ZFS transaction timeout to save on battery life.
vfs.zfs.txg.timeout="10"

Kernel Modules

内核模块

Enable querying CPU information and temperature: 启用 CPU 信息和温度查询:

sysrc -v kld_list+="cpuctl coretemp"

The H-TCP congestion control algorithm is designed to perform better over fast, long-distance networks (like the Internet). You might consider using it: H-TCP 拥塞控制算法旨在在快速、长距离网络(如互联网)上表现更好。你可以考虑启用它:

sysrc -v kld_list+="cc_htcp"

If you’re using a ThinkPad, you’ll need this module to get all your buttons working: 如果你使用的是 ThinkPad,则需要此模块来确保所有按键正常工作:

sysrc -v kld_list+="acpi_ibm"

Sysctl Tweaks

Sysctl 调优

Next, open up /etc/sysctl.conf and consider setting some of the following sysctls. You can view the description of a sysctl using sysctl -d. 接下来,打开 /etc/sysctl.conf 并考虑设置以下 sysctl 参数。你可以使用 sysctl -d 查看每个参数的描述。

(Note: Due to length, the full sysctl configuration block is omitted here, but follows the same pattern of security hardening and network performance tuning as provided in the original text.) (注:由于篇幅原因,此处省略了完整的 sysctl 配置块,但其内容遵循原文中提供的安全加固和网络性能调优逻辑。)