I successfully installed MacOS on my Dell Latitude E6430.  With that complete, I wanted to make an DVD archive of the USB drive I used as the installer.  I have DVD archives of my past hacintosh installations and to keep up the library and to keep the permanent backup, I wanted one for this install too.  This task proved to be impossible and impractical and good golly I wasted a lot of time on it.  But since I learned a lot on the way, I needed to write it up.  I’ll forget it if I don’t and some of the lessons learned can be useful for the future.  Primarily for me, but perhaps for somebody else too.

I created a drive image file of the USB installer drive.  The size of the resulting DMG file was 6.89 Gb.  Too big for a DVD, but it would fit on a DVD-DL.  I naively right clicked on the drive image and burn it to disc.  It said the disc wasn’t big enough.  Weird.  A DVD-DL should fit 8.5 Gb and 8.5 Gb is more than 6.89 Gb.  So that should have fit.  I tried different ways of doing it but the result was the same – the MacOS was insistent that the drive image wouldn’t fit on that disc.

I copied the DMG file from the Mac to my new triple boot laptop (might as well use the product of the installation to create this disc archive, I figured) and booted into Windows 7.  Right away, I realized I was again naive.  It is a DMG file, not a ISO.  So my normal Windows 7 burning tool, Ashampoo, can’t work with a DMG.  Dummy.

The next step was figuring out how to conver that DMG file to an ISO.  Is it a simple matter of renaming?  No, it is not.  I learned that a DMG file is actually a compressed form of an ISO file.  To do the conversion, I would need a special tool like dmg2img.  I got the tool and started the conversion.  It’s a good thing I did that on the large extra storage drive I had created because it turned out I was going to need the space.  The file ended up converting into a 31 Gb ISO file!  Wow, why is that?!

Well, it turns out that when you create a drive image of a disk drive, you get the image of the whole drive including the blank space.  The ISO contains it all but the DMG then compresses it.  And that’s the beauty of a DMG file over an ISO.  Okay, but how do I burn an unnecessarily large ISO to a DVD-DL?

My first idea was to go back and do the whole USB installer creation over again but this time change the partition scheme so that the minimal amount of disk was used.  I created one partition that was 8 Gb and the other that was the remaining 23 Gb was just free space.  I would have liked to have used an 8 Gb USB drive to do this but since an 8 Gb drive actually only has 7.56 Gb of usable space and since I needed 7.64 Gb, I needed to use a larger one.  I did have a 16 Gb USB drive I could have swapped to but that wouldn’t have solved my problem since the 16 Gb drive would still have produced an ISO larger than the DVD-DL.  I could have used the 16 Gb USB drive and then burned to BluRay but that seems silly to have gone to the BluRay just so I could store vast Gigabytes of nothingness.  So the idea of working with a USB drive of any size but keeping the partitiion to the minimum size made the most sense.

With my installer redone now with a partition size of 8 Gb, I recreated the DMG file and then tried burning it on the Mac.  Same problem – the DVD-DL is reported as not being large enough.  So I copied the file to the laptop and booted in Windows and converted the DMG to an ISO using dmg2img and there was another damn 31 Gb file.  So an ISO captures even the unformatted unpartitioned free space?  That’s just emphatically stupid.

Since I could not figure out how to create the ISO smaller in the first place, the question now is how do I shrink this ISO down so it will fit?  There must be a way.   I found a guide at Softwarebakery that seemed perfect for this.  I booted up in Ubuntu (and was still able to access that shared drive) and followed the instructions but I had a number of problems.  First, the “fdisk” command doesn’t like GPT disks and the output didn’t seem correct.  But more importantly, at the end of the process, I had a corrupt image. I believe the issue is that the a GPT disk has useful stuff at the end of the disk, not just the beginning.  (I think it is a secondary partition table?)  So when you lop off the end, even though it was mostly blank space, there’s important stuff that was lost and the image appears incomplete because it is.  More useful stuff to have learned although another roadblock for what I really wanted to accomplish.

Next I found a post at LinuxQuestions that seemed to exactly describe what I wanted to do including using a GPT disk.  And the post author even made a point of mentioning that other guides left off the last step in getting the disk to work.  I followed the guide and did successfully get a shrunk ISO image.  Here are the steps that I took based on what I have learned so far.

Plug in the USB drive and get the device ID.  It appears that ‘blkid’ should do the trick but for me, it didn’t and I needed to check the “by-label” directory.  The second time through for me, blkid did work.

sudo blkid
ls -al /dev/disk/by-label

Now, we know the device ID for the USB drive.  For me, it was “/dev/sdc”. Now we can create an image from that device.  And for good measure, create a copy of that image so if we do any damage, we don’t need to do the copy from the device again.

sudo dd if=/dev/sdc of=USB-drive-v1.img
cp USB-drive-v1.img USB-drive-v2.img

Next we set up a virtual device to connect to the image file.  Start off by setting up the loop functionality and then connect the device to the file.

sudo modprobe loop
sudo losetup -f
sudo losetup /dev/loop0 USB-drive-v2.img

Now with the drive image setup, we can find out information about the image contents.  And then we will mount the main partition to check for size.  For me, the main partition was loop0p2.  And before mounting, I needed to create a mount point because I didn’t have one yet.

sudo partprobe /dev/loop0
sudo blkid
sudo mkdir /media/tmp
sudo mount /dev/loop0p2 /media/tmp
df -h
sudo umount /media/tmp

The result of the ‘df’ shows the size of the partition we are working with and how much space on the drive is used.  Now we use parted command line to change the size.

sudo parted /dev/loop0
print

It shows the 2 partitions in the image file.  We want to resize partition 2.

resize 2

Accept the default values for the start and for the end, enter a number that you know will not truncate any data.  And in this case, for me, a number that is small enough that it will fit on the DVD-DL.  I went with 7.9G.  And keep in mind that this is not the size of the second partition but the location of the end of the second partition or the full size of the two partition disk which means that the space must include the space for the first, EFI, system partition.  After the resize, we exit parted and refresh the partition table in memory.

(default)
7.9G
quit
sudo partprobe /dev/loop0
sudo losetup -d /dev/loop0

Now we know that the contents of the image file have nothing that we care about beyond the size that we specified and therefore we can lop off the end of the file by copying only a certain number of blocks.  Since the block size is 1M, the count will be in Mb.  And therefore since we said 7.9G above for the end of the last partition, the count here will be (7.9 * 1024) + a little extra to be safe = 8100.

ls -l USB-drive-v2.img
dd if=USB-drive-v2.img of=USB-drive-v3.img bs=1M count=8100
ls -l USB-drive-v3.img

Now we have confirmed that the file size is much smaller and should fit on the DVD-DL.  But the image is currently damaged because the end of it was lopped off.  So we can use gdisk to fix it.  And again, for gdisk we need to use the loop device.

sudo losetup /dev/loop0 USB-drive-v3.img
sudo partprobe /dev/loop0
sudo gdisk /dev/loop0

gdisk will complain about a number of things.  That’s good.  That’s why we are here.  First, we will “v” to verify, then we will “r” to repair and “e” to rebuild the partition table.

v
r
e
y
v

Yes, problems remain, but I don’t think these are important.  We should be able to continue now that we fixed the main issue.

w
y
sudo partprobe /dev/loop0
sudo losetup -d /dev/loop0

At this point, we now have an iso that is trimmed down and suitable for burning and that will fit on a DVD-DL disc.  So time to burn it!  I ran Brasero to do the burn of the image and got a coaster – it errored out part way through.  I tried the same thing again in k3b and got an error there two.  Two coasters and counting.  I tried again with the command line using growisofs:

growisofs -dvd-compat -Z /dev/cdrom=USB-drive-v5.img

And the real test is booting the laptop from the new disc.  And…  nothing.  Not bootable.  Now that is frustrating.  Another coaster.

I tried moving the image file back to the Mac and burning there using Disk Utility.  It failed to burn at all on the Mac with a weird error – “0xFFFFFFCA”.  That’s interesting.  Maybe there is a problem with the image.  So I tried mounting the image on the Mac.  It came right up and showed the two partitions.  Okay, so proof that the disk image is good.

And here’s something else interesting.  I created this image file originally on linux using “dd” (see above) and yet it faithfully produced an image that works perfectly on MacOS.  So what is the difference between an ISO and an “IMG” file created using “dd”?  It doesn’t look like there is much difference at all.

But this didn’t solve the problem about why it wouldn’t burn in Disk Utility.  I tried doing the same thing in the command line and got a Segmentation Fault “11”.  That is probably the same error as what I got in Disk Utility.  (The hex conversion doesn’t work out to 11 but I mean it seems like a similar kind of crash.)

I tried using Toast and it got part way through and failed.  In fact it hung up the drive with a stuck process so  I had to reboot.  And another coaster.

Next I tried using the Burn program.  Since it appears to just be a front end to the built in Mac utilities, it wasn’t too surprising that it failed but what was interesting is that it showed an error about permissions.  That’s interesting, I thought.

Back to command line but this time, I did a “sudo” when I tried burning and it seemed to have gotten further before I got an “error 45”.

sudo hdiutil burn -addpmap -forceclose -nosynthesize USB-drive-v5.img

I tried again and removed the “-nosynthesize” and it worked!  The burn finished and the verify worked.

sudo hdiutil burn -addpmap -forceclose USB-drive-v5.img

Again, the real test was whether it would boot.  It did not.

I put both of the discs that burned successfully into the computer and checked the partition maps.

hdiutil pmap USB-drive-v5.img
hdiutil pmap /dev/disk4
hdiutil pmap /dev/disk5

The image I was trying to burn had the pmap that I expected to see and that it matched the partition map of the source USB drive.  Unfortunately, I lost track of which disc burned which way so I can’t match up the burn method to the result.  In one case, I had a disc that had an ISO partition and had only the main partition on it – no EFI partition at all.  And in the other case, I had an exact copy of the disk image’s partition map.  So one of them appeared to have an ISO setup that is proper for an optical disc but it didn’t have boot information while the other appeared to have boot information but was not a proper setup for an optical disc.

At this point, I had succeeded in shrinking the disk image so it would fit on a DVD-DL but burning was stripping away something that was making the USB drive bootable.  Or perhaps it wasn’t but an optical drive requires more than a USB drive does so there wasn’t enough there for the BIOS to use.  Either way, things weren’t looking good.

To go one step further, I tested what the process would be like if I did succeed.  I put the CD that matched the USB drive’s partition map in the laptop CD tray and booted up using the hard drive’s Clover bootloader.  Clover correctly discovered that there was a CD that it could use to boot from (even though it couldn’t boot from it’s own bootloader) so I selected that and had it boot up.  I wrote up most of this post while it was trying to load from that DVD.  It took probably 30 minutes for it to reach the end of the progress bar and when it did, it just froze.  I think the upshot is that loading from DVD is not the way to go any more.  To put it another way, everything I have been trying to do thus far in this post I now realize is pointless.  If I had succeeded in burning what I wanted to burn, the installation wouldn’t have worked that way anyway.  As much as I would want to have a CD in my library for future reference, it isn’t going to happen like it has before.

I did briefly explore the possibility of creating the installer with a disc target in mind all along.  I figured I’d start with the Install OS X El Capitan disk image file and modify that.  And I found info about how to convert a disk image to be read/write so I could make changes.  But as I was beginning this process, I was also working on the question of whether I would ever be able to write a bootable disk image to CD and have that actually boot the computer.  I’m convinced that I would.  So pulled the plug on this plan before I got too far down this path.

And yet, I didn’t want to give up entirely on the idea that I could archive the work on a single disc.  So I created a directory named Installer Archive and moved the original DMG of the USB drive into the new folder.  Then I created a readme.txt file that explains in a much briefer form what I discovered here – that burning a DVD to do the installation would be pointless.  But at least this way, I have the drive image available to me that I can use to restore to a USB drive at some point in the future.  And it would probably take less time to go to a store, buy a new USB drive, come home, and restore the drive image from DVD to the new USB drive than it would to ever successfully load the installer from DVD.

For the record, that’s 4 coasters, 2 DVDs that worked but aren’t useful, and 1 DVD that contains the archive.  DVD-DL discs aren’t cheap but they are way cheaper than all the time I’ve burned (pun!) on this nonsense these last few days.  And at this point, just being able to say I have something to show for my work is worthwhile.

Leave a Reply

Human Verification *

All content Copyright © Katharsys LLC Created with Wordpress, Theme "Synergy" by Pagelines modified by Katharsys LLC