想要在 Mac 设备上运行最新的 Ubuntu 24.04 操作系统,一共分三步:准备安装程序、授权系统启动、更新操作系统。
准备安装程序
所有的 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.
简单来说,和准备过程相关的有下面的提醒:
关机稍等一些时间,等待系统完全关闭。再次开机时,长按“电源按钮”,而不是按多次按钮,直到看到“加载启动选项…”时再松开。
然后,在启动列表中选择你的 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
如果过程中遇到问题,可以参考《服务端升级 Ubuntu 20.04 LTS 记录》中的方法,来排查和解决。
如果你在过程中遇到了类似 "The following packages have been kept back:" Why and how do I solve it?
的问题,我们可以使用下面的命令来解决问题:
apt-get --with-new-pkgs upgrade -y
执行命令,然后等待程序完成更新即可。
如果你有系统安装洁癖,可以顺手执行一个清理:
apt-get autoremove -y
重启操作系统,再次进入系统,我们就得到了 Ubuntu 24.04 版本的全新操作系统。