Create bootable image from OS X Installation App

root's picture

The OS X releases come only via App Store as an app package but sometimes there is need for a way to transform this into an iso image.
So without further writing, I present you two ways to do so.

1. Download the installer app from App Store. I downloaded mine and it is located here:


eeny:~ osx$ ls -lad /Applications/Install\ OS\ X\ El\ Capitan.app
drwxr-xr-x  3 root  wheel  102 Aug 12 00:14 /Applications/Install OS X El Capitan.app

2. Install the iesd package from gem:


eeny:~ osx$ sudo gem install iesd
Password:

Fetching: iesd-1.2.2.gem (100%)
Successfully installed iesd-1.2.2
Parsing documentation for iesd-1.2.2
Installing ri documentation for iesd-1.2.2
1 gem installed

3. Extract and convert the installation dmg from the app into a dmg file:


eeny:iso osx$ iesd -i Install\ OS\ X\ El\ Capitan.app -o elcapitan.dmg -t BaseSystem
==> Mounting /Volumes/stuff/kit/iso/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg
Mounted: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx
==> Mounting /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx/BaseSystem.dmg
Mounted: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/d20160917-86405-qaqnxr
==> Copying /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx/BaseSystem.dmg
Copied: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/d20160917-86405-qaqnxr/BaseSystem.dmg
==> Copying /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx/BaseSystem.chunklist
Copied: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/d20160917-86405-qaqnxr/BaseSystem.chunklist
==> Copying /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx/Packages
Copied: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/d20160917-86405-qaqnxr/System/Installation/Packages
==> Unmounting /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx/BaseSystem.dmg
Unmounted: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/d20160917-86405-qaqnxr
==> Merging /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-1x9wnj2/BaseSystem.dmg.shadow
Merged: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-16qa2gj/BaseSystem.dmg
==> Unmounting /Volumes/stuff/kit/iso/Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg
Unmounted: /var/folders/x0/r5mgbqyn2y1128xvypgl46wm0000gp/T/d20160917-86405-c3wghx
/Volumes/stuff/kit/iso/elcapitan.dmg

4. Convert the newly created dmg into sparseimage, to be customised on the next steps:


eeny:iso osx$ hdiutil convert elcapitan.dmg -format UDSP -o elcapitan.sparseimage
Reading Protective Master Boot Record (MBR : 0)…
Reading GPT Header (Primary GPT Header : 1)…
Reading GPT Partition Data (Primary GPT Table : 2)…
Reading  (Apple_Free : 3)…
Reading disk image (Apple_HFS : 4)…
..............................................................................................................................................................................
Reading  (Apple_Free : 5)…
Reading GPT Partition Data (Backup GPT Table : 6)…
..............................................................................................................................................................................
Reading GPT Header (Backup GPT Header : 7)…
...............................................................................................................................................................................
Elapsed Time:  5m 19.237s
Speed: 22.9Mbytes/sec
Savings: 14.6%
created: /Volumes/stuff/kit/iso/elcapitan.sparseimage

5. Mount the sparseimage and the original dmg file and copy the system files into the sparseimage. Unmount them afterwards:


eeny:iso osx$ hdiutil mount Install\ OS\ X\ El\ Capitan.app/Contents/SharedSupport/InstallESD.dmg
Checksumming Protective Master Boot Record (MBR : 0)…
Protective Master Boot Record (MBR :: verified   CRC32 $4C067D6E
Checksumming GPT Header (Primary GPT Header : 1)…
 GPT Header (Primary GPT Header : 1): verified   CRC32 $6C785BBD
Checksumming GPT Partition Data (Primary GPT Table : 2)…
GPT Partition Data (Primary GPT Tabl: verified   CRC32 $28B7052B
Checksumming  (Apple_Free : 3)…
                    (Apple_Free : 3): verified   CRC32 $00000000
Checksumming EFI System Partition (C12A7328-F81F-11D2-BA4B-00A0C93EC93B : 4)…
.....
EFI System Partition (C12A7328-F81F-: verified   CRC32 $B54B659C
Checksumming disk image (Apple_HFS : 5)…
..........................................................................................................................................................................
          disk image (Apple_HFS : 5): verified   CRC32 $212193FB
Checksumming  (Apple_Free : 6)…
..............................................................................................................................................................................
                    (Apple_Free : 6): verified   CRC32 $00000000
Checksumming GPT Partition Data (Backup GPT Table : 7)…
GPT Partition Data (Backup GPT Table: verified   CRC32 $28B7052B
Checksumming GPT Header (Backup GPT Header : 8)…
  GPT Header (Backup GPT Header : 8): verified   CRC32 $A566262B
verified   CRC32 $7B0D9EC5
/dev/disk9          	GUID_partition_scheme          	
/dev/disk9s1        	EFI                            	
/dev/disk9s2        	Apple_HFS                      	/Volumes/OS X Install ESD

eeny:iso osx$ hdiutil mount elcapitan.sparseimage
/dev/disk10         	GUID_partition_scheme          	
/dev/disk10s1       	Apple_HFS                      	/Volumes/OS X Base System

eeny:iso osx$ rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
eeny:iso osx$ cp -rp /Volumes/OS\ X\ Install\ ESD/Packages /Volumes/OS\ X\ Base\ System/System/Installation
eeny:iso osx$ cp -rp /Volumes/OS\ X\ Install\ ESD/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/
eeny:iso osx$ cp -rp /Volumes/OS\ X\ Install\ ESD/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/

eeny:iso osx$ hdiutil detach /dev/disk10
"disk10" unmounted.
"disk10" ejected.
eeny:iso osx$ hdiutil detach /dev/disk9
"disk9" unmounted.
"disk9" ejected.

6. Remove the old dmg file, and convert the sparseimage to DMG file:


eeny:iso osx$ rm elcapitan.dmg
eeny:iso osx$ hdiutil convert elcapitan.sparseimage -format UDZO -o elcapitan.dmg
Preparing imaging engine…
Reading Protective Master Boot Record (MBR : 0)…
   (CRC32 $8ABD6A37: Protective Master Boot Record (MBR : 0))
Reading GPT Header (Primary GPT Header : 1)…
   (CRC32 $A51CFB2A: GPT Header (Primary GPT Header : 1))
Reading GPT Partition Data (Primary GPT Table : 2)…
   (CRC32 $64FF28F2: GPT Partition Data (Primary GPT Table : 2))
Reading  (Apple_Free : 3)…
   (CRC32 $00000000:  (Apple_Free : 3))
Reading disk image (Apple_HFS : 4)…
............................................................................................................................................................................
   (CRC32 $7FC7EAA0: disk image (Apple_HFS : 4))
Reading  (Apple_Free : 5)…
..............................................................................................................................................................................
   (CRC32 $00000000:  (Apple_Free : 5))
Reading GPT Partition Data (Backup GPT Table : 6)…
...............................................................................................................................................................................
   (CRC32 $64FF28F2: GPT Partition Data (Backup GPT Table : 6))
Reading GPT Header (Backup GPT Header : 7)…
...............................................................................................................................................................................
   (CRC32 $DAF1AFC4: GPT Header (Backup GPT Header : 7))
Adding resources…
...............................................................................................................................................................................
Elapsed Time:  5m 11.110s
File size: 6716560939 bytes, Checksum: CRC32 $5A7EC524
Sectors processed: 17508712, 14955572 compressed
Speed: 23.5Mbytes/sec
Savings: 25.1%
created: /Volumes/stuff/kit/iso/elcapitan.dmg

If you are unable to boot from it, convert it to iso:

eeny:iso osx$ hdiutil convert elcapitan.dmg -format UDTO -o elcapitan.iso
Reading Protective Master Boot Record (MBR : 0)…
Reading GPT Header (Primary GPT Header : 1)…
Reading GPT Partition Data (Primary GPT Table : 2)…
Reading  (Apple_Free : 3)…
Reading disk image (Apple_HFS : 4)…
............................................................................................................................................................................
Reading  (Apple_Free : 5)…
Reading GPT Partition Data (Backup GPT Table : 6)…
............................................................................................................................................................................
Reading GPT Header (Backup GPT Header : 7)…
............................................................................................................................................................................
Elapsed Time:  5m  2.254s
Speed: 28.3Mbytes/sec
Savings: 0.0%
created: /Volumes/stuff/kit/iso/elcapitan.iso.cdr
eeny:iso osx$ mv elcapitan.iso.cdr elcapitan.iso

There is also an alternative way, with the help of asr command:


eeny:iso osx$ hdiutil attach "Install OS X El Capitan.app/Contents/SharedSupport/InstallESD.dmg" -noverify -nobrowse -mountpoint /Volumes/esd
/dev/disk8          	GUID_partition_scheme          	
/dev/disk8s1        	EFI                            	
/dev/disk8s2        	Apple_HFS                      	/Volumes/esd

eeny:iso osx$ hdiutil create -o elcapitan.cdr -size 7316m -layout SPUD -fs HFS+J
..............................................................................................................................................................................
created: /Volumes/stuff/kit/iso/elcapitan.cdr.dmg

eeny:iso osx$ hdiutil attach elcapitan.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/iso
/dev/disk9          	Apple_partition_scheme         	
/dev/disk9s1        	Apple_partition_map            	
/dev/disk9s2        	Apple_HFS                      	/Volumes/iso

eeny:iso osx$ asr restore -source /Volumes/esd/BaseSystem.dmg -target /Volumes/iso -noprompt -noverify -erase
	Validating target...done
	Validating source...done
	Retrieving scan information...done
	Validating sizes...done
	Restoring  ....10....20....30....40....50....60....70....80....90....100
	Remounting target volume...done

eeny:iso osx$ rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
eeny:iso osx$ cp -rp /Volumes/esd/Packages /Volumes/OS\ X\ Base\ System/System/Installation
eeny:iso osx$ cp -rp /Volumes/esd/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/
eeny:iso osx$ cp -rp /Volumes/esd/BaseSystem.dmg /Volumes/OS\ X\ Base\ System/

eeny:iso osx$ hdiutil detach /Volumes/esd
"disk8" unmounted.
"disk8" ejected.

eeny:iso osx$ hdiutil detach /Volumes/OS\ X\ Base\ System
"disk9" unmounted.
"disk9" ejected.

eeny:iso osx$ hdiutil convert elcapitan.cdr.dmg -format UDTO -o elcapitan.iso
Reading Driver Descriptor Map (DDM : 0)…
Reading Apple (Apple_partition_map : 1)…
Reading disk image (Apple_HFS : 2)…
...............................................................................................................................................................................
Elapsed Time:  8m  8.119s
Speed: 15.0Mbytes/sec
Savings: 0.0%
created: /Volumes/stuff/kit/iso/elcapitan.iso.cdr

eeny:iso osx$ mv elcapitan.iso.cdr elcapitan.iso
eeny:iso osx$ ls -la elcapitan.iso
-rw-r--r--+ 1 osx  admin  7671382016 Sep 17 18:51 elcapitan.iso

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself!
Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.