We are going to temporarily create an image on the desktop. Make sure you have sufficient disk space. This temporary directory will be deleted and a MacOSx rescue disk will have been created in the end of the tutorial.
Successfully tested on a Mac M1: Mac OS High-Sierra, El Capitan.
Start by downloading the OS-X dmg from this link : https://support.apple.com/en-us/HT211683
Then open the dmg and copy InstallMacOSX.pkg on (in this example) the Desktop.
Then, from the terminal (Applications/Utilities) un-compact the InstallMacOSX.pkg file in a directory (Installer for example) which will be created by the following pkgutil command:
Note: please always check the commands before u put something in your terminal!
pkgutil --expand ~/Desktop/InstallMacOSX.pkg ~/Desktop/Installer
Then position yourself in the InstallMacOSX.pkg “package” created by the pkgutil command
cd ~/Desktop/Installer/InstallMacOSX.pkg
Then un-compact the structure using the tar command:
tar -xvf Payload
Finally move the InstallESD.dmg file created by the tar command above to the Desktop
mv InstallESD.dmg ~/Desktop
You must then format a GUID partition scheme USB key of sufficient size named KEY (or any name, just make sure to edit the last command) in the example and execute the following instructions :
hdiutil attach ~/Desktop/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o /tmp/Installer
hdiutil resize -size 8g /tmp/Installer.sparseimage
hdiutil attach /tmp/Installer.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build
rm -r /Volumes/install_build/System/Installation/Packages
cp -av /Volumes/install_app/Packages /Volumes/install_build/System/Installation/
cp -av /Volumes/install_app/BaseSystem.chunklist /Volumes/install_build
cp -av /Volumes/install_app/BaseSystem.dmg /Volumes/install_build
hdiutil detach /Volumes/install_app
hdiutil detach /Volumes/install_build
hdiutil resize -size `hdiutil resize -limits /tmp/Installer.sparseimage | tail -n 1 | awk '{print $ 1}' `b /tmp/Installer.sparseimage
hdiutil convert /tmp/Installer.sparseimage -format UDZO -o /tmp/Installer
mv /tmp/Installer.dmg ~/Desktop
Here you have to plug the USB named KEY (or any name and rename “KEY” in the command below), then :
sudo asr restore --source ~/Desktop/Installer.dmg --target /Volumes/KEY --noprompt --noverify --erase
Test the key and if ok, delete the working directories and files of this operation from the Desktop.