【macOS】制作 macOS 安装 U 盘

Posted by 西维蜀黍 on 2021-04-06, Last Modified on 2022-03-06

Approach 1

Refer to https://dortania.github.io/OpenCore-Install-Guide/installer-guide/mac-install.html

下载镜像:

mkdir -p ~/macOS-installer && cd ~/macOS-installer && curl https://raw.githubusercontent.com/munki/macadmin-scripts/main/installinstallmacos.py > installinstallmacos.py && sudo python installinstallmacos.py

格式化U盘:

Now we’ll be formatting the USB to prep for both the macOS installer and OpenCore. We’ll want to use macOS Extended (HFS+) with a GUID partition map. This will create two partitions: the main MyVolume and a second called EFI which is used as a boot partition where your firmware will check for boot files.

  • Note: By default, Disk Utility only shows partitions – press Cmd/Win+2 to show all devices (alternatively you can press the View button)

Next run the createinstallmedia command provided by Apple (opens new window). Note that the command is made for USB’s formatted with the name MyVolume:

sudo /Applications/Install\ macOS\ Big\ Sur.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume

This will take some time so you may want to grab a coffee or continue reading the guide (to be fair you really shouldn’t be following this guide step by step without reading the whole thing first).

Setting up OpenCore’s EFI environment

$ diskutil list

# mount your ESF 
$ sudo diskutil mount /dev/<your EFI IDENTIFIER>

You’ll notice that once we open the EFI partition, it’s empty. This is where the fun begins.

Refer to https://swsmile.info/post/hackintosh-build-usb-flash-drive/

Approach 2 - Download from AppStore

去APP Store中搜索"Big Sur",点击“获取”,下载最新版本的macOS,完成后不要安装,之后打开终端操作。

创建空的 dmg 镜像文件

# 创建一个大小为13GB的 dmg
$ hdiutil create -o /tmp/BigSur.cdr -size 13000m -layout SPUD -fs HFS+J

把这个cdr文件挂载到位于 /Volumes/install_build 的虚拟磁盘:

# first time to run
$ sudo hdiutil attach /tmp/BigSur.cdr.dmg -noverify -mountpoint /Volumes/BigSur

/dev/disk2          	Apple_partition_scheme
/dev/disk2s1        	Apple_partition_map
/dev/disk2s2        	Apple_HFS                      	/Volumes/BigSur

This only creates the device node. Now run

$ diskutil list

Now will use the Createinstallmedia command to make the disk image bootable with macOS Big Sur.

$ sudo /Applications/Install\ macOS\ Big\ Sur\.app/Contents/Resources/createinstallmedia  --volume /Volumes/BigSur --nointeraction

Unmount the Disk Image which is formatted from BigSur to Install macOS Big Sur and bootable with macOS Big Sur ISO image.

$ hdiutil eject -force /Volumes/Install\ macOS\ Big\ Sur

Covert and rename the Disk Image to ISO

$ hdiutil convert /tmp/BigSur.cdr.dmg -format UDTO -o ~/Desktop/BigSur
mv -v ~/Desktop/BigSur.cdr ~/Desktop/BigSur.iso
sudo rm -fv /tmp/BigSur.dmg

至此全部完成,经过测试,桌面上的“BigSur.iso”和可以用来加载在VMWare虚拟机光驱中安装苹果系统,亦可以用来克隆到U盘做安装盘。

Reference