Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save coolaj86/9834a45a6c21a41e8882698a00b55787 to your computer and use it in GitHub Desktop.
Save coolaj86/9834a45a6c21a41e8882698a00b55787 to your computer and use it in GitHub Desktop.
How to create Apple's Bootable MacOS Rescue Image from Linux

See bootableinstaller.com

How to create a Bootable MacOS Recovery USB from Linux

If your Mac is out-of-order or you otherwise cannot download macOS from the App Store, you can still create a bootable OS X recovery USB, and you can use that to create an Installer USB.

The downloads used in this process are legal and freely avaliable - including disk images directly from Apple's IT support pages, and open source utilities for extracting and converting pkg, dmg, and HFS+.

No hackery. No hackintosh-ery.

This process works for

  • macOS Catalina (10.15)
  • macOS Mojave (10.14)
  • macOS High Sierra (10.13)
  • macOS Sierra (10.12)
  • OS X El Capitan (10.11)
  • OS X Yosemite (10.11)

In all cases you should first download the El Capitan Installer, as a direct download from Apple (no App Store).

The OS X Yosemite and macOS Sierra images should also work, but you might have trouble getting macOS Sierra to boot in VirtualBox.

Recovery USB vs Installer USB

This is a 3-step process:

  1. Create a Recovery ISO with Linux
  2. Create an El Capitan Installer ISO with VirtualBox from the Recovery image
  3. Create other Installer USBs from El Capitan in VirtualBox

Create the Recovery ISO

The Apple download contains a recovery image called BaseSystem.dmg which needs to be copied to a correctly partitions and formatted recovery USB or ISO.

  1. Download the OS X El Capitan installer
    • Note for Windows users running Linux from VirtualBox:
      • you already downloaded InstallOSX.dmg to your USB drive, so skip this step
    • Visit Apple's official "How to upgrade to El Capitan" documentation
    • Click "Download OS X El Capitan" in Step 4
    • InstallOSX.dmg will be about 6GB in your Downloads folder
  2. Install HFS+ tools for Linux
    • See install-mac-tools.sh below
    • Note for Windows users running Linux from VirtualBox:
      • choose to download to your USB drive, NOT Downloads
      • run the script from your USB drive, NOT Downloads
    • Right-Click on the view Raw link, choose Save as, and select the Downloads folder
    • Open a Terminal and run bash install-mac-tools.sh from the Downloads folder
    pushd ~/Downloads
    bash install-mac-tools.sh
  3. Create el-capitan-recue.iso
    • See linux-create-bootable-macos-recovery-image.sh below
    • Note for Windows users running Linux from VirtualBox:
      • choose to download to your USB drive, NOT Downloads
      • run the script from your USB drive, NOT Downloads
    • Right-Click on the view Raw link, choose Save as, and select the Downloads folder
    • Open a Terminal and run bash linux-create-bootable-macos-recovery-image.sh from the Downloads folder
    pushd ~/Downloads
    bash linux-create-bootable-macos-recovery-image.sh

You can of course run each command of the scripts by hand, but since it's deeply nested (.dmg containing a .pkg containing another .dmg with another .dmg inside), and requires loopback mounts, it's a rather tedious and mundane process.

Boot the Recovery ISO

You will need a 32GB+ USB drive, ExFAT formatted.

You should copy ElCapitanInstallESD.dmg from Downloads to your USB drive.

########################################################################################################################
# bootableinstaller.com #
########################################################################################################################
set -e
set -u
set -x
# Install HFS+ and dmg dependencies
if ! [ $(command -v mkfs.hfsplus) ] || ! [ $(command -v dmg2img) ]; then
# Note: hfsplus and hfsutils are old and not necessary
# Note: mac-fdisk (mac-fdisk-cross) is useful for debugging, but not required
sudo apt install -y hfsprogs dmg2img
fi
# Install xar
if ! [ -f "xar/xar/src/xar" ]; then
echo "Installing XAR from https://github.com/mackyle/xar.."
sudo apt install -y build-essential autoconf
sudo apt install -y libxml2-dev libssl-dev git
rm -rf xar/
git clone https://github.com/mackyle/xar
pushd xar/xar
sed -i.bak 's/OpenSSL_add_all_ciphers/OPENSSL_init_crypto/g' configure.ac
./autogen.sh --prefix=/usr/local
make
sudo make install
popd
fi
########################################################################################################################
# bootableinstaller.com #
########################################################################################################################
# Put bash in "strict mode"
set -u
set -e
if [ -f "./el-capitan-rescue.iso" ]; then
echo "'el-capitan-rescue.iso' already exists"
exit 0
fi
# Show commands as they are executed
set -x
my_installesd="./ElCapitanInstallESD.img"
if ! [ -f "./InstallESD.img" ]; then
my_installesd="./InstallESD.img"
fi
if ! [ -f "$my_installesd" ]; then
if ! [ -f "./InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg" ]; then
if ! [ -f "./InstallMacOSX.img" ]; then
if ! [ -f "./InstallMacOSX.dmg" ]; then
echo "Error: 'InstallMacOSX.dmg' doest not exist."
echo " Go to https://support.apple.com/en-us/HT206886"
echo " In step 4 click 'Download OS X El Capitan'"
fi
# decompresses into a dd-like image
dmg2img InstallMacOSX.dmg -o ./InstallMacOSX.img
chmod a-w ./InstallMacOSX.img
# rm InstallMacOSX.dmg
fi
my_fullosx=$(sudo losetup --list | (grep InstallMacOSX.img || true))
if ! [ -f "/mnt/InstallMacOSX/InstallMacOSX.pkg" ]; then
my_fullosx=$(sudo losetup --partscan --show --find InstallMacOSX.img)
echo "$my_fullosx"
sudo fdisk -l "$my_fullosx"
ls -l "$my_fullosx"p*
sudo partprobe $my_fullosx
sudo mkdir -p /mnt/InstallMacOSX
sudo mount "$my_fullosx"p2 -o ro,noatime /mnt/InstallMacOSX
fi
echo "Extracting /mnt/InstallMacOSX/InstallMacOSX.pkg"
mkdir -p ./InstallMacOSX.tmp.d/
pushd ./InstallMacOSX.tmp.d/
#LD_LIBRARY_PATH=../xar/xar/lib ../xar/xar/src/xar -xvf /mnt/InstallMacOSX/InstallMacOSX.pkg
# TODO maybe use pzip / 7zip instead?
xar -xvf /mnt/InstallMacOSX/InstallMacOSX.pkg
popd
mv ./InstallMacOSX.tmp.d ./InstallMacOSX
sudo umount /mnt/InstallMacOSX
sudo losetup -d "$my_fullosx"
fi
if ! [ -f "./ElCapitanInstallESD.img" ]; then
dmg2img ./InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg -o ./ElCapitanInstallESD.img
chmod a-w ./ElCapitanInstallESD.img
fi
my_installesd=./ElCapitanInstallESD.img
# TODO it's now safe to remove the big fat InstallMacOSX.*mg and ./InstallMacOSX/
fi
my_esd=$(sudo losetup --list | (grep InstallESD.img || true) | cut -d' ' -f1)
if ! [ -f "/mnt/InstallESD/BaseSystem.dmg" ]; then
my_esd=$(sudo losetup --partscan --show --find "$my_installesd")
echo "$my_esd"
sudo fdisk -l "$my_esd"
ls -l "$my_esd"p*
sudo partprobe $my_esd
sudo mkdir -p /mnt/InstallESD
sudo mount "$my_esd"p2 -o ro,noatime /mnt/InstallESD
fi
if ! [ -f "./BaseSystem.img" ]; then
dmg2img /mnt/InstallESD/BaseSystem.dmg -o ./BaseSystem.img
chmod a-w ./BaseSystem.img
fi
my_base=$(sudo losetup --list | grep BaseSystem.img | cut -d' ' -f1)
if [ -z "$my_base" ]; then
my_base=$(sudo losetup --partscan --show --find ./BaseSystem.img)
echo "$my_base"
sudo fdisk -l "$my_base"
ls -l "$my_base"p*
sudo partprobe $my_base
fi
my_empty=$(ls empty*img.bz2 | sort | head -1)
cp -rp "$my_empty" el-capitan-rescue.dd.img.bz2
bunzip2 el-capitan-rescue.dd.img.bz2
my_dd=$(sudo losetup --partscan --show --find el-capitan-rescue.dd.img)
echo "$my_dd"
sudo mac-fdisk -l "$my_dd"
ls -l "$my_dd"p*
sudo dd if="$my_base"p1 of="$my_dd"p2 bs=128M status=progress
sudo losetup -d "$my_dd"
mv el-capitan-rescue.dd.img el-capitan-rescue.iso
sudo umount /mnt/InstallESD
sudo losetup -d "$my_esd"
chmod a-w ./el-capitan-rescue.iso
echo "el-capitan-rescue.iso"
@stuft2
Copy link

stuft2 commented Nov 15, 2020

I had two other dependencies I had to install before the script would run successfully:

  1. Download empty*img.bz2 from bootableinstaller
  2. Install mac-fdisk: sudo apt-get install mac-fdisk-cross

@devalexandre
Copy link

I try and not work :(
I get InstallMacOSX.dmg past in USB and run scripts only mount e not generate el-capitan-rescue.iso

@mimi89999
Copy link

Hello,
I found a much easier and faster way to create a recovery. Tested with Catalina.

  1. Download https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS.py
  2. Run it and select in the menu any version up to 10.15.x macOS Catalina
  3. Wait for BaseSystem.dmg to download in the same folder you run the script
  4. Run dmg2img BaseSystem.dmg. It will convert the dmg to a raw disk image BaseSystem.img
  5. Write the image to a USB key using dd or GNOME disks
  6. Boot your Mac from the USB key. It will boot into recovery where you will have the option to install mac os.

@linconrezende
Copy link

linconrezende commented May 6, 2021

I had two other dependencies I had to install before the script would run successfully:

  1. Download empty*img.bz2 from bootableinstaller
  2. Install mac-fdisk: sudo apt-get install mac-fdisk-cross

Awesome!! First, thank you!
I had an error "xar command not found", for some reason the install-mac-tools.sh script didn't really installed.
I'm on Ubuntu 20.04.2 LTS x
I solved it by doing:

cd ~/Downloads/xar/xar
./configure
make
make install

After that, I had another output: "512: failed to use device: No such device"
Then I realized that I needed the empty*img.bz2 from bootableinstaller
After that, I got another error: mac-fdisk: command not found which I solved by installing it. On the script it says: "not required" but in my case I wouldn't work without it (I think)

After all that, I deleted all the files, then I started again. It worked!
I just don't know yet why the dmg file is over 6Gig and the final iso is 2Gig.
I'll create a bootable USB and if it works I'll post here. Thanks

Edit I decided to describe a little bit about what I've done that could help

It did what it is soposed to do, but in my case, it didn'd worked because I had a wrong DMG file, that has a update, not a full base system.
I've been searching on the internet for a few days now, and the only and most simple was this:
https://www.addictivetips.com/ubuntu-linux-tips/create-a-macos-installation-disk-on-linux/
Convert the image to a ubuntu friendly image

sudo add-apt-repository universe
sudo apt update
sudo apt install dmg2img
dmg2img -v -i /path/to/image_file.dmg -o /path/to/image_file.iso

and finally, the code bellow to flash the iso into the USB drive.
sudo dd if=/path/to/image_file.iso of=/dev/sdd
It took less than 10 minutes to convert and 30 minutes to flash it into the USB drive.

I booted on my macbook air 2011, and I installed Mac OS X Lion...
To, only then, update it to the El Capitan and I finally I gave up, because I've never seen a macbook that slow (taking abount 10 minutes to turn on every single time a normal shutdown). It probably has some isues with the RAM or the SSD..

But anyways. I've learned A LOT of new things! It was fun.

@Petehagoras
Copy link

Hey there, fist of all: Thanks a lot for the guide an the scripts.

My task is to revive a late 2009 iMac, with El Capitan (10.11.4) as last installed OS, but the drive is pretty much gone, not bootable in whatsoever mode. I spent days now, in trying every thinkable option out there, when no other mac-device is available.

I followed the guide, and everything seemed to work well, and it's the most promising approach so far.

Now I have two image files: the rescue.iso and InstallESD.img

If I flash the rescue.iso, i'm getting a base system drive that i can boot of, but i'm only getting to the recovery mode, InstallOS always ends up in internet recovery, with a "not available" notice.

If I flash the InstallESD.img it's not bootable.

I tried Transmac on Win, Copying, make bootable device, DD and etcher on Linux, on pre formatted modes: FAT exFAT, OS Journaled with GUID Table, although flashing makes an Apple-table out of it.

In my understanding it should work with the rescue.iso right ? Am I missing something out, doing something wrong, or is it my System that would eventually only be revivable with an orig. DVD ?

I hope someone could give me a hint. Let me know if you need any further Information. If there is a solution to this, I'd be happy to summarize all the issues I struggled through and contribute to the knowledge base.

@linconrezende
Copy link

@Petehagoras
About the internet recovery not being available: https://www.ifixit.com/Answers/View/601830/re+installing+OSX+problems
I've done this once and it worked, by changing the date, using the old date that they have the certificate installed or some thing like that, I recommend reading the link to a better understanding.

About the other issue, I also had that problem and I HAD to use linux, it was the only freaking way of making this happening, I had a tryal image of ubuntu just to make it happen.

And.. just to let you know, I successfully instelled everything I needed but the system was so slow that I gave up. A few months later, I found out that by changing the battery, the system came back to life, as fast as it can be.

@spidy0x0
Copy link

spidy0x0 commented Apr 2, 2022

Hello, I found a much easier and faster way to create a recovery. Tested with Catalina.

  1. Download https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS.py
  2. Run it and select in the menu any version up to 10.15.x macOS Catalina
  3. Wait for BaseSystem.dmg to download in the same folder you run the script
  4. Run dmg2img BaseSystem.dmg. It will convert the dmg to a raw disk image BaseSystem.img
  5. Write the image to a USB key using dd or GNOME disks
  6. Boot your Mac from the USB key. It will boot into recovery where you will have the option to install mac os.

full command for step 4

qemu-img convert BaseSystem.dmg -O raw BaseSystem.img

@ingenika
Copy link

I've came across error with install-mac-tools.sh
so my solution
~/Downloads
git clone https://github.com/mackyle/xar
~/Downloads/xar/xar
sed -i.bak 's/OpenSSL_add_all_ciphers/OPENSSL_init_crypto/g' configure.ac ./autogen.sh --prefix=/usr/local

make
sudo make install
after this, go to second step

linux-create-bootable-macos-recovery-image.sh

I think XAR not install, maybe because too old.

@ingenika
Copy link

This is also very informative.
Thank you

@ingenika
Copy link

I had two other dependencies I had to install before the script would run successfully:

  1. Download empty*img.bz2 from bootableinstaller
  2. Install mac-fdisk: sudo apt-get install mac-fdisk-cross

Awesome!! First, thank you! I had an error "xar command not found", for some reason the install-mac-tools.sh script didn't really installed. I'm on Ubuntu 20.04.2 LTS x I solved it by doing:

cd ~/Downloads/xar/xar
./configure
make
make install

After that, I had another output: "512: failed to use device: No such device" Then I realized that I needed the empty*img.bz2 from bootableinstaller After that, I got another error: mac-fdisk: command not found which I solved by installing it. On the script it says: "not required" but in my case I wouldn't work without it (I think)

After all that, I deleted all the files, then I started again. It worked! I just don't know yet why the dmg file is over 6Gig and the final iso is 2Gig. I'll create a bootable USB and if it works I'll post here. Thanks

Edit I decided to describe a little bit about what I've done that could help

It did what it is soposed to do, but in my case, it didn'd worked because I had a wrong DMG file, that has a update, not a full base system. I've been searching on the internet for a few days now, and the only and most simple was this: https://www.addictivetips.com/ubuntu-linux-tips/create-a-macos-installation-disk-on-linux/ Convert the image to a ubuntu friendly image

sudo add-apt-repository universe
sudo apt update
sudo apt install dmg2img
dmg2img -v -i /path/to/image_file.dmg -o /path/to/image_file.iso

and finally, the code bellow to flash the iso into the USB drive. sudo dd if=/path/to/image_file.iso of=/dev/sdd It took less than 10 minutes to convert and 30 minutes to flash it into the USB drive.

I booted on my macbook air 2011, and I installed Mac OS X Lion... To, only then, update it to the El Capitan and I finally I gave up, because I've never seen a macbook that slow (taking abount 10 minutes to turn on every single time a normal shutdown). It probably has some isues with the RAM or the SSD..

But anyways. I've learned A LOT of new things! It was fun.

This method not works for El Capitan

@ingenika
Copy link

@Petehagoras
This post help me finally solved the problem:
https://askubuntu.com/questions/743075/how-to-make-a-bootable-osx-el-capitan-usb
So basically, you copy the InstallESD.dmg from the InsallMacOSX.dmg file, and run the following scripts
mkosxinstallusb.sh
https://github.com/ilian/mkosxinstallusb/blob/master/mkosxinstallusb.sh

@cargaona
Copy link

The steps @mimi89999 shared previously worked pretty well for me.

The link is broken since there is a new script:

https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS-v2.py

Hello, I found a much easier and faster way to create a recovery. Tested with Catalina.

1. Download https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS.py

2. Run it and select in the menu any version up to 10.15.x macOS Catalina

3. Wait for `BaseSystem.dmg` to download in the same folder you run the script

4. Run `dmg2img BaseSystem.dmg`. It will convert the dmg to a raw disk image `BaseSystem.img`

5. Write the image to a USB key using dd or GNOME disks

6. Boot your Mac from the USB key. It will boot into recovery where you will have the option to install mac os.

@gabrc52
Copy link

gabrc52 commented Jun 25, 2023

This file should be downloaded too. https://gist.github.com/coolaj86/04fd06560a8465a695337eb502f5b0e9/raw/41aee39866707edc4b195556e8ee6591e6ee608b/empty.2100m.img.bz2

mac-fdisk seems to be a very particular piece of software but even if you are not on Ubuntu, you can place the binary from the deb file in https://packages.debian.org/source/sid/mac-fdisk in /usr/local/bin.

It almost worked for me in Fedora in that it created a bootable installer, but when I try installing OS X, it says "to download and restore OS X, your computer's eligibility will be verified with Apple", and after clicking "Continue", it said "An error occured while preparing the installation. Try running this application again".

Update: I tried using its Safari and the computer thinks it is December 2000 so any HTTPS connections fail. So I ran ntpdate -u time.apple.com first, before running the installer, and it seems to show the terms of service now. But it fails after putting the Apple ID

It's also odd that el-capitan-rescue.iso is 2.2 GB but InstallMacOSX.dmg is 6.2 GB. Where's the remaining GB? And why does the gist say "You will need a 32GB+ USB drive" then?

Full output:
[rgabriel@thinkpad elcapitan]$ ./linux-create-bootable-macos-recovery-image.sh 
++ my_installesd=./ElCapitanInstallESD.img
++ '[' -f ./InstallESD.img ']'
++ my_installesd=./InstallESD.img
++ '[' -f ./InstallESD.img ']'
++ '[' -f ./InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg ']'
++ '[' -f ./InstallMacOSX.img ']'
++ '[' -f ./InstallMacOSX.dmg ']'
++ dmg2img InstallMacOSX.dmg -o ./InstallMacOSX.img

dmg2img v1.6.5 (c) vu1tur (to@vu1tur.eu.org)

InstallMacOSX.dmg --> ./InstallMacOSX.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok
opening partition 8 ...             100.00%  ok

Archive successfully decompressed as ./InstallMacOSX.img
++ chmod a-w ./InstallMacOSX.img
+++ sudo losetup --list
+++ grep InstallMacOSX.img
[sudo] password for rgabriel: 
+++ true
++ my_fullosx=
++ '[' -f /mnt/InstallMacOSX/InstallMacOSX.pkg ']'
+++ sudo losetup --partscan --show --find InstallMacOSX.img
++ my_fullosx=/dev/loop0
++ echo /dev/loop0
/dev/loop0
++ sudo fdisk -l /dev/loop0
Disk /dev/loop0: 6.34 GiB, 6812200960 bytes, 13305080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9E945023-4BE5-486A-A795-D4ECC7F6C20B

Device        Start      End  Sectors  Size Type
/dev/loop0p1     40   409639   409600  200M EFI System
/dev/loop0p2 409640 13042895 12633256    6G Apple HFS/HFS+
++ ls -l /dev/loop0p1 /dev/loop0p2
brw-------. 1 root root 259, 6 Jun 25 15:17 /dev/loop0p1
brw-------. 1 root root 259, 7 Jun 25 15:17 /dev/loop0p2
++ sudo partprobe /dev/loop0
++ sudo mkdir -p /mnt/InstallMacOSX
++ sudo mount /dev/loop0p2 -o ro,noatime /mnt/InstallMacOSX
++ echo 'Extracting /mnt/InstallMacOSX/InstallMacOSX.pkg'
Extracting /mnt/InstallMacOSX/InstallMacOSX.pkg
++ mkdir -p ./InstallMacOSX.tmp.d/
++ pushd ./InstallMacOSX.tmp.d/
~/Downloads/elcapitan/InstallMacOSX.tmp.d ~/Downloads/elcapitan
++ xar -xvf /mnt/InstallMacOSX/InstallMacOSX.pkg
Distribution
InstallMacOSX.pkg/Bom
InstallMacOSX.pkg/InstallESD.dmg
InstallMacOSX.pkg/PackageInfo
InstallMacOSX.pkg/Payload
InstallMacOSX.pkg/Scripts
Resources/Dutch.lproj/Localizable.strings
Resources/English.lproj/Localizable.strings
Resources/French.lproj/Localizable.strings
Resources/German.lproj/Localizable.strings
Resources/Italian.lproj/Localizable.strings
Resources/Japanese.lproj/Localizable.strings
Resources/Spanish.lproj/Localizable.strings
Resources/ar.lproj/Localizable.strings
Resources/ca.lproj/Localizable.strings
Resources/cs.lproj/Localizable.strings
Resources/da.lproj/Localizable.strings
Resources/el.lproj/Localizable.strings
Resources/es_MX.lproj/Localizable.strings
Resources/fi.lproj/Localizable.strings
Resources/he.lproj/Localizable.strings
Resources/hr.lproj/Localizable.strings
Resources/hu.lproj/Localizable.strings
Resources/id.lproj/Localizable.strings
Resources/ko.lproj/Localizable.strings
Resources/ms.lproj/Localizable.strings
Resources/no.lproj/Localizable.strings
Resources/pl.lproj/Localizable.strings
Resources/pt.lproj/Localizable.strings
Resources/pt_PT.lproj/Localizable.strings
Resources/ro.lproj/Localizable.strings
Resources/ru.lproj/Localizable.strings
Resources/sk.lproj/Localizable.strings
Resources/sv.lproj/Localizable.strings
Resources/th.lproj/Localizable.strings
Resources/tr.lproj/Localizable.strings
Resources/uk.lproj/Localizable.strings
Resources/vi.lproj/Localizable.strings
Resources/zh_CN.lproj/Localizable.strings
Resources/zh_TW.lproj/Localizable.strings
Resources/zh_TW.lproj
Resources/zh_CN.lproj
Resources/vi.lproj
Resources/uk.lproj
Resources/tr.lproj
Resources/th.lproj
Resources/sv.lproj
Resources/sk.lproj
Resources/ru.lproj
Resources/ro.lproj
Resources/pt_PT.lproj
Resources/pt.lproj
Resources/pl.lproj
Resources/no.lproj
Resources/ms.lproj
Resources/ko.lproj
Resources/id.lproj
Resources/hu.lproj
Resources/hr.lproj
Resources/he.lproj
Resources/fi.lproj
Resources/es_MX.lproj
Resources/el.lproj
Resources/da.lproj
Resources/cs.lproj
Resources/ca.lproj
Resources/ar.lproj
Resources/Spanish.lproj
Resources/Japanese.lproj
Resources/Italian.lproj
Resources/German.lproj
Resources/French.lproj
Resources/English.lproj
Resources/Dutch.lproj
Resources
InstallMacOSX.pkg
++ popd
~/Downloads/elcapitan
++ mv ./InstallMacOSX.tmp.d ./InstallMacOSX
++ sudo umount /mnt/InstallMacOSX
++ sudo losetup -d /dev/loop0
++ '[' -f ./ElCapitanInstallESD.img ']'
++ dmg2img ./InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg -o ./ElCapitanInstallESD.img

dmg2img v1.6.5 (c) vu1tur (to@vu1tur.eu.org)

./InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg --> ./ElCapitanInstallESD.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok
opening partition 8 ...             100.00%  ok

Archive successfully decompressed as ./ElCapitanInstallESD.img
++ chmod a-w ./ElCapitanInstallESD.img
++ my_installesd=./ElCapitanInstallESD.img
+++ sudo losetup --list
+++ grep InstallESD.img
+++ cut '-d ' -f1
+++ true
++ my_esd=
++ '[' -f /mnt/InstallESD/BaseSystem.dmg ']'
+++ sudo losetup --partscan --show --find ./ElCapitanInstallESD.img
++ my_esd=/dev/loop0
++ echo /dev/loop0
/dev/loop0
++ sudo fdisk -l /dev/loop0
Disk /dev/loop0: 6.35 GiB, 6817550336 bytes, 13315528 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6930D4EA-8378-4B52-A805-8B46BBFEBDEF

Device        Start      End  Sectors  Size Type
/dev/loop0p1     40   409639   409600  200M EFI System
/dev/loop0p2 409640 13053343 12643704    6G Apple HFS/HFS+
++ ls -l /dev/loop0p1 /dev/loop0p2
brw-------. 1 root root 259, 4 Jun 25 15:19 /dev/loop0p1
brw-------. 1 root root 259, 5 Jun 25 15:19 /dev/loop0p2
++ sudo partprobe /dev/loop0
++ sudo mkdir -p /mnt/InstallESD
++ sudo mount /dev/loop0p2 -o ro,noatime /mnt/InstallESD
++ '[' -f ./BaseSystem.img ']'
++ dmg2img /mnt/InstallESD/BaseSystem.dmg -o ./BaseSystem.img

dmg2img v1.6.5 (c) vu1tur (to@vu1tur.eu.org)

/mnt/InstallESD/BaseSystem.dmg --> ./BaseSystem.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok

Archive successfully decompressed as ./BaseSystem.img
++ chmod a-w ./BaseSystem.img
+++ sudo losetup --list
+++ grep BaseSystem.img
+++ cut '-d ' -f1
++ my_base=
++ '[' -z '' ']'
+++ sudo losetup --partscan --show --find ./BaseSystem.img
++ my_base=/dev/loop1
++ echo /dev/loop1
/dev/loop1
++ sudo fdisk -l /dev/loop1
Disk /dev/loop1: 2 GiB, 2145263616 bytes, 4189968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 96B25A1F-3302-4A38-877D-776064442B67

Device       Start     End Sectors  Size Type
/dev/loop1p1    40 3927783 3927744  1.9G Apple HFS/HFS+
++ ls -l /dev/loop1p1
brw-rw----. 1 root disk 259, 4 Jun 25 15:19 /dev/loop1p1
++ sudo partprobe /dev/loop1
+++ sort
+++ ls empty.2100m.img.bz2
+++ head -1
++ my_empty=empty.2100m.img.bz2
++ cp -rp empty.2100m.img.bz2 el-capitan-rescue.dd.img.bz2
++ bunzip2 el-capitan-rescue.dd.img.bz2
+++ sudo losetup --partscan --show --find el-capitan-rescue.dd.img
++ my_dd=/dev/loop2
++ echo /dev/loop2
/dev/loop2
++ sudo mac-fdisk -l /dev/loop2
/dev/loop2
          #                    type name                length   base    ( size )  system
/dev/loop21     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
/dev/loop22               Apple_HFS disk image         4300736 @ 64      (  2.1G)  HFS

Block size=512, Number of Blocks=4300800
DeviceType=0x0, DeviceId=0x0

++ ls -l /dev/loop2p1 /dev/loop2p2
brw-------. 1 root root 259, 4 Jun 25 15:19 /dev/loop2p1
brw-------. 1 root root 259, 8 Jun 25 15:19 /dev/loop2p2
++ sudo dd if=/dev/loop1p1 of=/dev/loop2p2 bs=128M status=progress
2011004928 bytes (2.0 GB, 1.9 GiB) copied, 19 s, 104 MB/s
14+1 records in
14+1 records out
2011004928 bytes (2.0 GB, 1.9 GiB) copied, 19.9632 s, 101 MB/s
++ sudo losetup -d /dev/loop2
++ mv el-capitan-rescue.dd.img el-capitan-rescue.iso
++ sudo umount /mnt/InstallESD
++ sudo losetup -d /dev/loop0
++ chmod a-w ./el-capitan-rescue.iso
++ echo el-capitan-rescue.iso
el-capitan-rescue.iso

For reference, this is the second search result on "make macos installer from linux". I wanted an El Capitan one specifically, which is what this guide has. The first search result from addictivetips.com did not work (the USB was not even detected by the Macbook).

I had a similar experience trying to create a Windows bootable USB on Linux. It would boot but it would ask me for a driver or something. When creating the Windows bootable USB from a Windows VM, it finally worked. So I guess that is what I have to do--create a bootable USB from a macOS VM (OSX-KVM).

I am currently trying the following steps to turn the dmg from Apple into a bootable USB. I will update this comment with my progress.

  1. Copy InstallMacOSX.dmg to another drive
  2. Connect both the installer created with this guide and the other drive to the Mac
  3. Disk Utility from el-capitan-rescue.iso -> Images -> Scan Image For Restore..., select InstallMacOSX.dmg (otherwise it fails)
  4. Insert yet another USB stick
  5. Disk Utility -> the other USB stick -> Edit -> Restore -> InstallMacOSX.dmg

Update: it just says "Resource busy". Maybe using the qemu command instead of dmg2img might work.

@krull
Copy link

krull commented Sep 18, 2023

The steps @mimi89999 shared previously worked pretty well for me.

The link is broken since there is a new script:

https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS-v2.py

Hello, I found a much easier and faster way to create a recovery. Tested with Catalina.

1. Download https://github.com/kholia/OSX-KVM/blob/master/fetch-macOS.py

2. Run it and select in the menu any version up to 10.15.x macOS Catalina

3. Wait for `BaseSystem.dmg` to download in the same folder you run the script

4. Run `dmg2img BaseSystem.dmg`. It will convert the dmg to a raw disk image `BaseSystem.img`

5. Write the image to a USB key using dd or GNOME disks

6. Boot your Mac from the USB key. It will boot into recovery where you will have the option to install mac os.

Greetings! Confirmed working with Monterey. I just had to recover a Mac, and this way worked.

I tried to do Ventura, but it wouldn't go pass the 'Question Mark' when trying to boot from USB.

@mcornella
Copy link

mcornella commented Dec 10, 2023

In https://gist.github.com/coolaj86/9834a45a6c21a41e8882698a00b55787#file-linux-create-bootable-macos-recovery-image-sh, I substituted the less available xar with

7z x /mnt/InstallMacOSX/InstallMacOSX.pkg -slt -t\*

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment