[Share Experiences] 在M2芯片的MacBook Pro 上原生安装 Ubuntu 24.04 ARM 版
Tofloor
poster avatar
流浪的加菲
deepin
2024-06-27 18:14
Author

2020 年,开源项目 Asahi Linux 成立,项目组通过逆向工程手段完成大量的硬件支持、驱动支持和底层工具支持相关的开发工作,让 Apple Silicon Mac 设备能够拥有开放的操作系统生态。

image.png

2022 年的 5 月下旬,AsahiLinux 发布了它第一个稳定版本 v1.0,第一个能够将 Apple(XNU)引导生态与 Linux 引导生态连接起来的 Bootloader。M1 / M2 设备的大门再也关不严实了。

原项目作者主要维护的 Linux 发行版是 Fedora,为此还带来了和原生 macOS 类似的多显示器支持、HiDPI 支持,OpenGL 支持(甚至是 Vulkan),以及和 PipeWire和 WirePlumber合作,来让设备拥有完整的 DSP 解决方案,让电脑音频更加好听。

不过,在 2023 年,越来越多的发行版粉丝加入了 Asahi Linux 发行版泛化的过程里,目前支持的 Linux 发行版已经有十种左右了,包括:Alpine、AOSC、CentOS、Debian、deepin、Fedora、Gentoo、NixOS、Rocky、Ubuntu。关于deepin社区对Apple M1的适配可以查阅:

deepin成功适配Apple M1,我们的适配之旅!(上篇)

deepin适配Apple M1,我们经历了什么?(下篇)


下面,我们来聊聊怎么在 M1 / M2 芯片的设备上原生安装、运行 Linux。

image.png

**重要提醒:**建议你进行重要数据的备份操作,如果你遇到了需要重装操作系统或者卸载 Linux 操作系统,可以翻阅文章中相关的章节出来。scream

准备安装程序

所有的 Asahi Linux 发行版的安装程序准备,都是固定的套路(支持自定义 installer config/data),先使用 curl 下载并执行安装脚本:

curl -sL https://ubuntuasahi.org/install | sh

如果你对执行的脚本不放心,可以下载脚本,进行审查,在审查后再进行执行:

# 下载安装程序
curl -sL https://ubuntuasahi.org/install > install.sh
# 审查安装程序
cat install.sh
# 执行安装程序
bash install.sh

执行命令后,不出意外,你将看到类似下面的输出结果:

Bootstrapping installer:
  Checking version...
  Version: v0.7.1
  Downloading...
  Extracting...
  Initializing...

这个安装程序需要使用 root 权限执行,所以,如果安装过程和你询问账号的密码来提权,需要输入密码。

过程中,程序会收集和展示你的系统信息,并展示给你:

Collecting system information...
  Product name: MacBook Pro (13-inch, M2, 2022)
  SoC: Apple M2
  Device class: j493ap
  Product type: Mac14,7
  Board ID: 0x2a
  Chip ID: 0x8112
  System firmware: iBoot-10151.1.1
  Boot UUID: 4A4C1024-1024-1024-1024-49C3B4DF1024
  Boot VGID: 4A4C1024-1024-1024-1024-49C3B4DF1024
  Default boot VGID: 4A4C1024-1024-1024-1024-49C3B4DF1024
  Boot mode: macOS
  OS version: 14.0 (23A344)
  OS restore version: 23.1.344.0.0,0
  Main firmware version: 14.0 (23A344)
  No Fallback System Firmware / rOS
  SFR version: 23.1.344.0.0,0
  SystemRecovery version: 23.4.56.0.0,0 (14.3 23D56)
  Login user: soulteary

Collecting partition information...
  System disk: disk0
...

当基础信息收集完毕后,程序首先会收集和引导我们调整磁盘分区,来腾出一些空间安装新的 Linux 操作系统:

Collecting OS information...

Partitions in system disk (disk0):
  1: APFS [Macintosh HD] (494.38 GB, 6 volumes)
    OS: [B*] [Macintosh HD] macOS v14.0 [disk3s3s1, 4A4C1024-1024-1024-1024-49C3B4DF1024]
  2: APFS (System Recovery) (5.37 GB, 2 volumes)
    OS: [  ] recoveryOS v14.0 [Primary recoveryOS]

  [B ] = Booted OS, [R ] = Booted recovery, [? ] = Unknown
  [ *] = Default boot volume

Using OS 'Macintosh HD' (disk3s3s1) for machine authentication.

Choose what to do:
  r: Resize an existing partition to make space for a new OS
  q: Quit without doing anything
» Action (r): r

如果你没有安装或者提前进行系统分区,那么输入 r 就能够进入分区调整步骤了。接下来程序会询问我们到底要划分多少空间给新的操作系统:

We're going to resize this partition:
  APFS [Macintosh HD] (494.38 GB, 6 volumes)
  Total size: 494.38 GB
  Free space: 431.38 GB
  Available space: 393.38 GB
  Overhead: 0 B
  Minimum new size: 101.01 GB (20.43%)

Enter the new size for your existing partition:
  You can enter a size such as '1GB', a fraction such as '50%',
  or the word 'min' for the smallest allowable size.

  Examples:
  30%  - 30% to macOS, 70% to the new OS
  80GB - 80GB to macOS, the rest to your new OS
  min  - Shrink macOS as much as (safely) possible

» New size (50%): 30%

我个人诉求是主要使用这台机器作为 Linux CI/CD 机器,所以我只给原始操作系统留了 30% 的空间,这样既能做 PE 维护系统以防万一,真需要 macOS 运行的软件,也能切回去运行。

然后,一路回车和 y (同意),用于安装 Linux 的新分区就自动处理好啦:

Resizing will free up 346.07 GB of space.

Note: your system may appear to freeze during the resize.
This is normal, just wait until the process completes.
» Continue? (y/N): y

Started APFS operation
Aligning shrink delta to 346,068,963,328 bytes and targeting a new container size of 148,315,832,320 bytes
Determined the minimum size for the APFS Container to be 62,226,694,144 bytes
Resizing APFS Container designated by APFS Container Reference disk3
The specific APFS Physical Store being resized is disk0s2
[ - 0%..10%.............................................. ] 

Verifying allocated space
The container /dev/disk0s2 appears to be OK
Storage system check exit code is 0
Shrinking APFS Physical Store disk0s2 from 494,384,795,648 to 148,315,832,320 bytes
Shrinking APFS data structures
Shrinking partition
Modifying partition map
Finished APFS operation

Resize complete. Press enter to continue.

当我们的分区调整完毕之后,能够看到程序收集的磁盘信息得到了更新,我们可以执行的动作除了“调整分区”和“退出安装”之外,多了一条“安装操作系统到空闲区域”:

Collecting partition information...
  System disk: disk0

Collecting OS information...

Partitions in system disk (disk0):
  1: APFS [Macintosh HD] (148.32 GB, 6 volumes)
    OS: [B*] [Macintosh HD] macOS v14.0 [disk3s3s1, 4A4C1024-1024-1024-1024-49C3B4DF1024]
  2: (free space: 346.07 GB)
  3: APFS (System Recovery) (5.37 GB, 2 volumes)
    OS: [  ] recoveryOS v14.0 [Primary recoveryOS]

  [B ] = Booted OS, [R ] = Booted recovery, [? ] = Unknown
  [ *] = Default boot volume

Using OS 'Macintosh HD' (disk3s3s1) for machine authentication.

Choose what to do:
  f: Install an OS into free space
  r: Resize an existing partition to make space for a new OS
  q: Quit without doing anything
» Action (f): 

直接回车后,来到操作系统选择列表,类似下面这样。选择我们想要安装的系统,输入对应的数字序号,就能够开始安装啦:

Choose an OS to install:
  1: Ubuntu Desktop 23.10
  2: Ubuntu Desktop 23.04
  3: Ubuntu Desktop 22.04 LTS
  4: Ubuntu Server Minimal
  5: UEFI environment only (m1n1 + U-Boot + ESP)

我这里推荐安装距离 24.04 最近的 23.10,硬件驱动支持的更好。过程中,依旧是询问我们的用户密码,来获得授权,应给尽给即可。

To continue the installation, you will need to enter your macOS
admin credentials.

Password for soulteary: 

Setting the new OS as the default boot volume...

Installation successful!

Install information:
  APFS VGID: A42B1024-1024-1024-1024-E99F0C481024
  EFI PARTUUID: aebe1024-1024-1024-1024-42bf967a1024

To be able to boot your new OS, you will need to complete one more step.
Please read the following instructions carefully. Failure to do so
will leave your new installation in an unbootable state.

Press enter to continue

到这里,安装就完毕啦,作者比较小心,特别写了一段 “防呆” 文档提醒:

When the system shuts down, follow these steps:

1. Wait 25 seconds for the system to fully shut down.
2. Press and hold down the power button to power on the system.
   * It is important that the system be fully powered off before this step,
     and that you press and hold down the button once, not multiple times.
     This is required to put the machine into the right mode.
3. Release it once you see 'Loading startup options...' or a spinner.
4. Wait for the volume list to appear.
5. Choose 'macbian'.
6. You will briefly see a 'macOS Recovery' dialog.
   * If you are asked to 'Select a volume to recover',
     then choose your normal macOS volume and click Next.
     You may need to authenticate yourself with your macOS credentials.
7. Once the 'Asahi Linux installer' screen appears, follow the prompts.

If you end up in a bootloop or get a message telling you that macOS needs to
be reinstalled, that means you didn't follow the steps above properly.
Fully shut down your system without doing anything, and try again.
If in trouble, hold down the power button to boot, select macOS, run
this installer again, and choose the 'p' option to retry the process.

Press enter to shut down the system.

关机稍等一些时间,等待系统完全关闭。再次开机时,长按“电源按钮”,而不是按多次按钮,直到看到“加载启动选项…”时再松开。

image.png

然后,在启动列表中选择你的 Linux 操作系统。到这里为止,准备和安装工作就结束啦。

授权系统启动

当我们在启动列表选择了我们的 Linux 操作系统后,首次启动系统,我们需要完成“系统启动切换”的授权。

如果看到了 “macOS 恢复”对话框,我们需要 “选择要恢复的卷”,点击下一步,选择我们安装了 Linux 的分区,然后进行身份验证对其授权。

在界面弹出的终端窗口中,和上文一样,该输入 Mac 设备的用户名和密码的时候,小心输入,并回车确认,几轮下来后,点击回车,设备重启,授权系统启动的工作就结束啦。

更新操作系统

一般情况,如果上面的工作都顺利完成,那么我们将自动的进入 Linux 环境。

默认的账号和密码都是 ubuntu,输入密码,将自动进入 Ubuntu 环境。

因为默认安装的操作系统版本是 Ubuntu 23.10,想要得到最新的 Ubuntu 24.04 LTS 版本,我们需要做一些工作。

默认的 Ubuntu 软件源,可能访问数据会比较慢,可以根据自己的具体情况来做一个软件源替换,比如替换为清华源:

sed -i 's/ports.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

然后,执行系统所有软件包的更新:

apt update && apt upgrade -y

当软件都更新完毕之后,我们执行 do-release-upgrade 开始 Linux 发行版更新即可:

do-release-upgrade
# 或者
do-release-upgrade -d

目前系统还存在的问题

如果你仔细翻看项目对于设备硬件的支持度,你会发现,除了 USB-C 外接显示器,雷电接口、麦克风、TouchID 几个部分外,项目已经支持了所有主要的设备。

如果你不需要这台设备外接输出画面、不需要借用它的雷电接口来做传输、不需要用它来开视频会议,以及不是频繁的使用 TouchID 来解锁设备,像我一样,用它来跑编译构建,或许这个操作系统还是蛮适合你的。

image.png

重新安装 macOS 或清理已安装的 Linux

想要“卸载”已安装的 Linux 非常简单,只需要在开机的时候长按“电源键”,然后选择启动机器的 macOS 系统,进入操作系统中,选择系统自带的“磁盘工具”,选择分区,然后将前三个分区之外“删除掉”(减号按钮),保存修改即可。

如果你在安装过程中,出现了意外情况,或者重复安装将系统分区弄乱了,或者在“卸载”的时候,马大哈的操作错误,导致你需要进行重装,一般情况,我们只需要重启 macOS 操作系统,进入恢复模式,将 WiFi 连上跟着引导重新安装即可,如果出现磁盘分区不可调整,那么在安装完毕系统后,再进行安装即可。


原文参考:MacBook Pro 原生安装 Ubuntu 24.04 ARM 版

原作者:苏洋

Reply Favorite View the author
All Replies
蔡EEPIN
deepin
2024-06-27 18:39
#1

之前装过基于arch的,续航直接崩了 软件也少的可怜,浏览器都没一个像样的

Reply View the author
hanzn-zzx
deepin
2024-06-27 19:20
#2

like

Reply View the author