MacBook 上安装 ArchLinux 双系统

目录

动机

希望将闲置的 2018 款 MBP 利用起来,整成一台 Linux 服务器就好了,因为 macOS 上的 Docker 非常难用,再加上我比较爱折腾,于是有了这个想法。

主要参考这个 wiki:https://wiki.t2linux.org

Tip

后来,我发现,macOS 15 把屏幕啊文件啊共享都做到了极致,比起折腾 ArchLinux 成本低多了,而且 macOS 更适配硬件,于是我几乎不需要所谓服务器了…… 再说,Orbstack 还是 macOS 上运行容器的好手。 于是我删除了 ArchLinux at 2025-04-13.

diskutil list
sudo diskutil eraseVolume free none /dev/diskXsY
sudo diskutil apfs resizeContainer disk0s2 0

最后 关机后 Option + Command + P + R 长按 20 秒来重建 NVERAM。

思路

装 双系统 or 纯 Linux ?

答:双系统

理由:1. WiFi 的驱动是直接用的 macOS 上的 2. 出问题了有原生 macOS 兜底 3. macOS 更新使得一些固件得以更新,这对 Linux 来说同样有好处

装什么 Linux ?

答:ArchLinux

理由:1. 我比较熟悉 ubuntu/Debian 系,也用过 centOS,这次就要用不一样的 2. ArchLinux 现在比较流行,原因是““The Arch Way” + By far the biggest and most up-to-date software collection with the official repos + AUR.”,内核都能直接更新

安装前准备

在 macOS 上为 Linux 分区

  1. Open Disk Utility
  2. Choose the volume you want to partition for Linux
  3. Press in the top-right “Partition”
  4. Under the blue pie chart press “+” button
  5. When prompted be sure to select “Add Partition” and NOT “Volume”, you want a partition.
  6. Name: choose a name for the partition, e.g. Linux
  7. Format: choose whatever format there is - APFS or another - it doesn’t really matter (during the Linux installation you must erase your created 1. partition anyway)
  8. Size: pick the desired amount of space for Linux, because you will not be able to change it.

我是 512 GB 的 MBP,留了大概 200GB 给 macOS,300 GB 给了 Linux。

制作 Linux 安装启动盘

LinuxDistributionDownload ISO with T2 support
Arch Linuxhttps://github.com/t2linux/archiso-t2/releases/latest

直接用 macOS 上的 dd 命令执行就行,不用下载第三方软件的:

  1. Insert your USB drive.
  2. Open macOS Terminal.
  3. Run diskutil list to list all the drives.
  4. Look up for your USB thumb which appears as an external, physical drive labelled /dev/diskX where X is a single number (e.g. /dev/disk2).
  5. Run sudo diskutil unmountDisk /dev/diskX to unmount the disk.
  6. Run sudo dd if=path/to/linux.iso of=/dev/rdiskX bs=1m to start writing. To fetch the iso path easily you can just drag and drop the .iso into the Terminal.
  7. Now you may press control-T to make it show how many KBs it has written so far.

备份 WiFi 和 蓝牙 固件

需要先下载脚本并运行: Click here to download the script.

脚本执行示例

然后等安装好 Linux 后,在 Linux 上执行一下命令来安装固件,这一节放在后面讲。

关闭 MBP 的安全模式

  1. Turn off your Mac
  2. Turn it on and press and hold Command-R until the black screen flashes
  3. Your Mac will boot in the macOS Recovery
  4. Select your user and enter your password
  5. Now, from the menu bar choose Utilities > Startup Security Utility
  6. Enter again the password
  7. Once in Startup Security Utility:
  8. set Secure Boot to No Security
  9. set Allow Boot Media to Allow booting from external or removable media

执行

启动盘安装 Linux

  1. Ensure the Linux Installation USB you created is plugged into your Mac.
  2. Reboot while holding down the option (⌥) key, this will put you in macOS Startup Manager.
  3. Select the orange EFI option with arrow keys and press return/enter on it. If there are two, try the one to the very right first (the last one).
  4. The installation may start right away or you may be put into a Bootloader Menu where it may select a default option e.g. “Try or Install Ubuntu”, but you can use arrow keys to select a different option. If you are unsure, check if there is any additional advice on your distro’s installation page on this wiki.

一句话就是:关闭电脑 -> 长按 Option -> 键盘➡️ -> 回车 (这个要熟记,默认启动的是 macOS ,如果要进入 Linux 系统,这个步骤是你每次都要重复执行的动作)

根据系统的引导,自己选择需要安装的组件,然后安装即可,可以看这个:Installing Arch Linux on a Mac with the T2 Chip

连接上 Wi-Fi

先要把 Wi-Fi 固件安装上,之前我们已经执行过一次备份 macOS 上固件的脚本,现在我们在 Linux 上再执行一下:

sudo mkdir -p /tmp/apple-wifi-efi 
sudo mount /dev/nvme0n1p1 /tmp/apple-wifi-efi 
bash /tmp/apple-wifi-efi/firmware.sh 
sudo umount /tmp/apple-wifi-efi

测试固件是否正常:sudo journalctl -k --grep=brcmfmac

类似如下输出:

Dec 24 22:34:19 hostname kernel: usbcore: registered new interface driver brcmfmac
Dec 24 22:34:19 hostname kernel: brcmfmac 0000:01:00.0: enabling device (0000 -> 0002)
Dec 24 22:34:20 hostname kernel: brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac4377b3-pcie for chip BCM4377/4
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0: Direct firmware load for brcm/brcmfmac4377b3-pcie.apple,tahiti-SPPR-m-3.1-X0.bin failed with error -2
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0: Direct firmware load for brcm/brcmfmac4377b3-pcie.apple,tahiti-SPPR-m-3.1.bin failed with error -2
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0: Direct firmware load for brcm/brcmfmac4377b3-pcie.apple,tahiti-SPPR-m.bin failed with error -2
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0: Direct firmware load for brcm/brcmfmac4377b3-pcie.apple,tahiti-SPPR.bin failed with error -2
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0: Direct firmware load for brcm/brcmfmac4377b3-pcie.apple,tahiti-X0.bin failed with error -2
Dec 24 22:34:20 hostname kernel: brcmfmac: brcmf_c_process_txcap_blob: TxCap blob found, loading
Dec 24 22:34:20 hostname kernel: brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM4377/4 wl0: Jul 16 2021 18:25:13 version 16.20.328.0.3.6.105 FWID 01-30be2b3a
Dec 24 22:34:20 hostname kernel: brcmfmac 0000:01:00.0 wlp1s0f0: renamed from wlan0

使用 iwd 连接 WiFi:

iwctl
device list
station wlan0 get-networks
station wlan0 connect <无线网名称>
station wlan0 show

格式化分区

由于我们之前已经在 macOS 上给 Linux 划分了空间,此时只需要格式化文件系统,不需要再重新分区。

fdisk -l /dev/nvme0n1
# 一下磁盘名以上面命令出来的实际为准
mkfs.fat -F 32 /dev/nvme0n1p3
mkfs.ext4 /dev/nvme0n1p4

然后挂载分区:

mount /dev/nvme0n1p4 /mnt
mkdir /mnt/boot
mount /dev/nvme0n1p3 /mnt/boot

执行安装程序

使用 archinstall 命令安装,可参考这篇文章:https://www.cnblogs.com/chen2ha/p/18469127 (若该文章无法访问,可联系我给你备份)。

如果下载时它说空间不足,没法下载更多,那就安装一个比较纯净的命令行系统,后面再搜一搜教程来安装桌面吧,桌面我选择的 KDE。

安装完成后启动 Linux

还是这个动作:关闭电脑 -> 长按 Option -> 键盘➡️ -> 回车

ArchLinux 桌面

Tip

上面这张截图是我用另一台 Mac ,使用 Windows App(之前叫 Remote Desktop)通过 RDP 远程连接到这台 Linux 后截图的,这个也比较简单,打开 ArchLinux 的远程桌面并配置用户名和密码即可:RDP 远程连接桌面

安装完成后 Linux 的一些配置

风扇、声音等驱动

还是参考 wiki,完成风扇、声音等固件的配置,这里不赘述。

更新软件源

直接搜 tuna 的教程。

替换清华 tuna 软件源

配置静态 IP 地址

之前使用 iwctl 来连接 WiFi 会造成 IP 不断的变动,我希望 MBP 的 IP 是静态的。

可以直接问 ChatGPT 、DeepSeek 等,怎么配置 ArchLinux 的静态 IP。

一个经验是:注意不要使用 networkmanager,因为连不上网,一直说我网络密码不对,但我用 iwd 就能连上。

iwd 是由 Intel 为 Linux 编写的一个无线网络守护程序。该项目的核心目标是不依赖任何外部库,而是最大程度地利用 Linux 内核提供的功能来优化资源利用。一般,使用 iwd 的性能比 wpa_supplicant 要好很多

Tip

虽然 iwd 和 networkmanager 是可以共存的,而 KDE 的网络管理就是用的 networkmanager,我们可以通过配置使用 iwd 作为 NetworkManager 的 WiFi backend

但我并不推荐这么做,原因还是多个相同功能的软件容易冲突,造成不可知的问题。比如连上网了但又无法上网……这都是亲身经历了。

询问 Claude

关键是如下的配置:

iwd 配置

然后可以重启 iwd 试试:

sudo systemctl restart iwd
标签 :
comments powered by Disqus

相关文章

GORM 自动填充 UUID 的 2 种方式

使用 uuid 库手动生成 采用这个库:github.com/gofrs/uuid 在 GORM 中定义一个 BaseModel,并增加钩子函数: import "github.com/gofrs/uuid" type BaseModel struct { ID uuid.UUID CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` EffectiveTime *time.Time } func (m *BaseModel) BeforeCreate() (err error) { m.ID, err = uuid.NewV4() if err != nil { log.Logger.Err(err).Msg("uuid create failed") return fmt.Errorf("uuid create with ID failed, %w", err) } return nil } 使用 postgresql 的 uuid-ossp 插件 首先要启用插件 要么手动 Navicat 界面上增加: 要么执行查询语句:

阅读更多
最小生成树

最小生成树:Kruskal算法和Prim算法的实现 这里直接给出离散数学中的几个定理和推论: 无向图G具有生成树当且仅当G连通. G为n阶m条边的无向连通图,则 m >= n - 1. G是树 $\Leftrightarrow$ G中任意两个顶点之间存在唯一路径 $\Leftrightarrow$ G中无回路且m=n-1$\Leftrightarrow$ G是连通的且m=n-1$\Leftrightarrow$ G中没有回路但在任何2个不同的顶点间加一条新边就能在图中得到唯一的含新边的环圈. 生成子图指的是顶点集相同,但边集是图G的子集的图. 生成树指的是图G的生成子图并且是树. 最小生成树指的是图G的所有生成树中权最小的. 算法第4版中这样定义:

阅读更多
Snapcast 多房间音频控制一体化

动机 想要手头的两台 MBP 能同时无延迟播放音频,拒绝使用直播流的形式。 Tip update at 2025-04-13

阅读更多