Retrieving files from mac OSX (backup) dmg file

Posted by Flo in Tricks on November 30th, 2010.
Tags: , , ,

A little while ago, the my brother’s macbook pro died a horrible death (Apple hardware tends to do that). Luckily a backup of the hard disk could be made with the mac disk utility. Well, luckily… Retrieving the data from the .dmg file seems to be more troublesome than I hoped it would be. When accessed with mac software, not all data could be retrieved (some files don’t even appear). However, after a long night of work, I got access to all the files again. How? read on…

Please note that all my solutions, including this one, are at your OWN-RISK. If you kill your computer or damage it, or any data on it, in any way, you are the cause. I WILL NOT TAKE ANY RESPONSIBILITY. The only advice that I can give is that if you don’t understand a step, don’t do it or search the internet till you understand it.

First of all, how would I summarize my problem?

  • I got a backup from the whole hard disk (around 200GB) made with the mac disk utility.
  • I couldn’t open it on Max OS X, it decompresses the file, but doesn’t show anything
  • With other software (disk warrior?) some data could be retrieved, but not all data.

Of course, I wanted to access all the data, and after hours of searching and testing I came up with the following solution. It should however be noticed that a little knowledge of linux system might help (although, I hope to describe things well enough for anybody to understand).

What do you need?

  • A lot of time (decompressing can take a few hours depending on the size)
  • The full disk backup like the one described above (a .dmg file).
  • Enough free disk space on a non-hfs or hfs+ formatted (it’s a mac format) drive to decompress the backup disk to. 
    • This means that you need about 20% more disk space than the size of the .dmg file. example: the dmg file is 100gb, you’ll need at least 120gb free space.
    • This means you need either an ext3 (linux) formatted partition on a hard disk with that much space or a ntfs formatted partition on a hard disk. The easiest way to get this, is to format an external hard disk in windows (or linux), but you’ll need to find instructions for that on the net, and format it to ntfs. (this is also possible on a mac, but it’ll take some reading/time: search for macfuse).
    • NOTE: I believe this can be very troublesome if you only have a Mac without an external drive.
  • A Linux distribution: if you don’t have it, you can either install it, or run it from a live cd. I will roughly describe how you would do the last option below (see: I don’t have a linux machine).

 I have a linux machine!

NOTE: I use Kubuntu, so I’ll describe the steps for that system (it also works for ubuntu). if you use another distribution, you’ll need to interpret the steps for your distribution.
NOTE 2: I intend to keep it simple so "anybody" (well, I know you need to have some computer experience) can use it. Experienced users probably know enough if you just read the bold texts.

  1.  open your favorite terminal. Mine’s konsole, so press alt+F2, type ‘konsole’ and press enter.
  2. navigate to your .dmg file using the cd command. If it’s on an external hard disk, connect the disk to your computer. To find your dmg file with the terminal, use:

    $ sudo find /media/ -name *.dmg

    You’ll need to enter your super user password, and the location of all the .dmg files are displayed like this:

    /media/SECURE DISK-1/yourfilename.dmg

    If none are coming up, you probably have a problem, otherwise find the file you want to use. We’re now going to go to the folder.
    The following commands are useful for that: the cd command is for changing folders, the ls -l command (L’s, not I’s) displays the content of the folder and lists it.  You go up 1 folder by using cd ..
    We are going  to the folder using:

    $ cd /media/path/to/your/file

    in my example:

    $ cd /media/SECURE\ DISK-1

    Note that you can use tab to autocomplete: so I’ll only have to type /media/SE then press tab, and it will be automatically completed to /media/SECURE\ DISK-1.

    If you have trouble using these commands, see this website. (<click it)

  3. Check if the .dmg file is compressed, by using the file command

    $ file yourfilename.dmg

    If it’s compressed, it will return some short line containing VAX COFF, otherwise it will return a large description containing HFS or HFS EXTENDED.

  4. If it isn’t compressed, see this site (<click it)for instructions how to mount the file and access your files, otherwise do what I did:
  5. If it is compressed (VAX COFF), you’ll need to decompress it. The web is full of descriptions how to do this (using dmg2img or DMGeXtractor (<click it)), but my experience is that the first one doesn’t work for large files (> 6.3GB) and the second one didn’t work in my case. So do the following:
    1. download peazip (<click it)(or any other extracting application that can handle .dmg files) If you want to install it, get peazip for linux -> the .deb file, otherwise just use the standalone application for linux.
    2. Install Peazip (double click the downloaded .deb file and follow the instructions).
    3. start peazip in the terminal by using:

      $ peazip &

    4. Now select the .dmg file you want to extract and extract it to the (correctly formatted) free space we reserved for it above (DON’T BROWSE THROUGH IT IN PEAZIP, IT WILL EAT UP ALL YOUR FREE SPACE AND WILL CRASH YOUR COMPUTER IF THE FILE IS LARGER THAN YOUR OS PARTITION). This took me around 3 or 4 hours for 200GB.
  6. After this is done (don’t be too afraid for errors, I had 2 and it didn’t matter), we want view the contents of the partition, so we’ll need to mount the result. What’s the result? we can check it by browsing to the folder containing the result:

    $ cd /path/to/the/extracted/files/
    $ ls -l

    I got some files called like this: 00. MBR, 01. Primary GPT Header, … , 05. hfs, …, 07. DOS_FAT_32, etc. These are the partitions from the disk you backed up. In my case the 05. hfs file contained my mac files, and the 07. DOS_FAT_32 file contained my windows partition, so my windows files. Now, how to view the partition? Follow the instructions

    1. First of all, I don’t think you should open the MBR file, just mount the partitions that might contain your files (usually the largest files, check it using ls -l) in my case 05. hfs and DOS_FAT_32
    2. We’ll need to check how they are formatted, for this use

      $ file nameofthepartition

      in my case:

      $ file 05.\ hfs

      This will result in a large description. Check for: "HFS" or "HFS EXTENDED" or "FAT", remember this.

    3. now we are going to prepare the mounting by creating a mounting point. Where I put ‘name’, you should put a good description, like macdisk or windisk:

      $ sudo mkdir -p /mnt/name

      so in my case for the mac partition:

      $ sudo mkdir -p /mnt/macdisk

    4. Now we are going to mount the file. How we’re going to do this depends on how they are formatted.
      • For HFS EXTENDED use the command: $ sudo mount -t hfsplus -o loop nameofthepartition /mnt/name
      • For any FAT type use the command: $ sudo mount -t vfat -o loop nameofthepartition /mnt/name
      • For HFS, use the command: $ sudo mount -t hfs -o loop nameofthepartition /mnt/name
  7. If that went allright, we can access the files using dolphin (kubuntu) or nautilus (ubuntu). Use the command:

    $ sudo dolphin /mnt/name &

    We need to be super user, because files may be read protected, and we still want to read them.

  8. That’s it! I hope it worked for you, otherwise I’m very sorry for wasting your time. If you want to restore the files back to an empty hard disk with the original partitions, you probably need the dd command, but you’ll have to look that up yourself.

Clean up your mounted drives

If you don’t want to access the partition anymore, you can use the command (from anywhere)

$ sudo umount /mnt/name

where /media/name is the path to the mounting point we just created.
If you get the error that something is busy, you should close all applications that use the drive, and then your terminal. Now reopen your terminal, and try again.


I don’t have linux!

You can still follow this guide by following some extra steps and using a live cd. Using the live cd is relatively safe, but again, read my warning on top of this post. I can not guarantee that it will work (since I have not tested it this way), so you might be wasting a lot of your precious time =). You might need a USB drive.
NOTE: I don’t think you have to use the sudo parts of the commands when using the live cd.

  1. Get a kubuntu live CD or DVD: You need a Desktop CD or DVD for your processor type (32bit or 64bit). It matters ^^ but if you don’t know, get the 32bit.
  2. burn the live cd from the downloaded iso file (follow the instructions on the site) and put it in your computer.
  3. reboot and boot from the live cd. If you have a mac, I believe you must load the cd, reboot and hold the c button during startup. Otherwise you can use this guide (<click it).
  4. start kubuntu from the live cd.

Now you should follow the instructions from the guide above till step 4. Step 5 is a little different because you can’t install things when using the live cd, so we’ll need to get the standalone version of peazip.

  1. Open a browser: alt+F2, enter "konqueror" and press enter. You can try to enter "firefox", but I don’t think it’s in the distribution.
  2. Download peazip (<click it), select the standalone version and get the one for linux with gtk. Download it to your USB drive.
  3. Extract the tar.gz file to your USB drive, either do it manually with the file browser (dolphin). Just open the file browser, open your USB drive, double click the file, and it will extract. Or browse to it in the terminal (konsole) and extract it with the command:

    $ tar xvzf peazipfile.tar.gz

  4. After you’ve extracted it, open the folder either using the terminal or the file browser and run the executable (for the file browser, double click it, for the terminal, I believe you shoul type $ ./peazip ). If this doesn’t work, and an installation screen shows up, you might need to use the QT version in step 2, if that doesn’t work, I’d like to hear it.
  5. extract the file, and follow the instructions further from step 6.

 The only problem that might occur if you have made it this far (in my unmeasurable optimism) lies in step 6.2, you might not be able to make the directory… It might help to make it like this:

$ sudo mkdir -p ./mnt/name

and thus making the directory on your usb drive containing the file you want to mount… although I can think about millions of reasons why it wouldn’t work :-D.


Some sites that have helped me:

I would love to hear if anyone could comprehend the guid/ found some mistakes or improvements/if anyone could do this from the live cd.

best of luck!

Leave a Reply