20

When changing my mac HDD to an SSD I ran into the following problem:

I've created a DMG image of my old HDD which has a capacity of 320GB. The DMG file remembered and saved the capacity in the image, and the problem is my SSD is only 120GB.. So the DMG can't be used if I can't decrease the capacity somehow..

EDIT: The total amount of used space on the image is only 15GB..

I've looked at hdiutil but I'm actually a ruby on rails developer so I don't really get this stuff..

Is their any way with this or another util to decrease the capacity of the DMG?

Thanks!

migrated from serverfault.com Aug 13 '12 at 20:22

This question came from our site for system and network administrators.

39

There isn't a good way via GUI that I've seen to do this - you've got to use hdiutil as you asked. It's a quick command. To resize (change 25G to whatever you want),

hdiutil resize -size 25G /PATH/TO/DISK/IMAGE.dmg

Another way to compress it is to clone your disk image into a sparsebundle, then compress the sparsebundle. This may or may not work, depending on how much compression takes place.

First, create the disk image which mirrors your old disk image:

hdiutil convert /location/of/disk.dmg -format UDSP -o /PATH/TO/NEWIMAGE.sparseimage

Then, compact the resulting sparseimage:

hdiutil compact /PATH/TO/NEWIMAGE.sparseimage

If these commands don't work then it's got something to do with your disk image and/or permissions.

I have spent a lot of time playing with hdiutil and it's far from flawless - I've found & submitted bugs in Snow Leopard that still haven't been corrected in Mountain Lion, so if you do get a bit of odd behavior, don't be off-put!

  • I've tried this, but the resize verb throws a permission problem, I'm now creating an RW disk image of to see if that works. – Tim Baas Aug 14 '12 at 8:00
  • With my RW disk image, I was able to use the resize verb and shrink the image to 120G, this resulted in a 128,85 GB capacity.. So that's the right way, but it's still not enough to fit on my SSD.. The compact verb doesn't work, it says compact failed - function not implemented. – Tim Baas Aug 14 '12 at 8:40
  • @TimBaas Kinda late, but if you get permissions problems (maybe you don't have write access on the DMG), you can use sudo hdiutil resize -size 25G /PATH/TO/DISK/IMAGE.dmg. I just did it with my Time Machine backup disk image, and it didn't seem to break any permissions. – sudo Jan 18 '17 at 17:34
  • I converted to a sparse image with your second command, but then neither the compact nor the resize would work on it. compact said it trimmed 0 bytes, but I have 40GiB free in it. convert said the size is too small. The volume is Mac OS Extended (Journaled). – sudo Oct 12 '17 at 20:29
1

Try this one:

hdiutil compact image.dmg

But as you can see in hdiutil manual:

Depending on the location of files in the hosted filesystem, compact may or may not shrink the image.
  • Thanks for your reaction.. When executing this command I get the response that theirs a permission problem.. Probably because the dmg is a read-only formatted disk image.. I now have Carbon Copy Cloner creating a copy via FireWire.. – Tim Baas Aug 13 '12 at 20:02
  • You can use Mac OS X Disk Utility to convert from ro to rw image. – klocek Aug 13 '12 at 20:08
  • I got it working with CCC, thanks for your help anyway! – Tim Baas Aug 13 '12 at 20:11
1

After cjc pointed out to ask the question at apple.stackexchange.com, I did. When asking the question I got to a related questing answered by someone saying to try Carbon Copy Cloner.

Carbon Copy Cloner cloned the files via FireWire to my SSDisk no questioned asked, and everything is how it should be..

Here's the question I'm referring to:

Restore system from DMG (original source disk bigger than destination)

For those of you interested in resizing a disk image:

Make your disk image read-write in Mac's Disk Utility:

Mount the disk, select it and click new disk image. Select read-write in the disk image structure drop down and click save. ( My OS is dutch, so these are my own translations ).

Use hdiutil to resize the disk image:

In terminal: hdiutil resize -size 100G /location/of/disk.dmg. You can replace 100G by the size you want.

Optional (didn't work for me), you can try to compact it:

In terminal: hdiutil convert /location/of/disk.dmg -format UDSP -o /location/of/NEW/disk.dmg.

This creates a sparse image.

Then: hdiutil compact /location/of/SPARSE/disk.dmg.sparseimage

This will try to free up space on the disk image.. If it works I guess you may need to resize your DMG again to lower the capacity (I'm not sure)..

0

Tried all this to no avail; hdiutil wouldn't let me resize below a certain threshold (much lower than OP).

Simple answer:

  1. Make a new DMG file at the size you want.
  2. Copy all the files over from the old DMG
  3. Close and reopen new DMG and verify it's all good
  4. Trash/backup/archive the old DMG.
  • I'm not sure how to do this when copying a system. cp gives me tons of errors for special files. – sudo Oct 12 '17 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .