How to Disk Image a Mac Using Ubuntu Linux

A while ago my friend’s wife’s MacBook Pro started to have issues with its graphics card. As we all know, graphics cards in laptops are pretty much non-replaceable items (soldered into the main board). So, with some deadlines looming on the horizon for poor Stacey, the question was: “How to get the data off of one drive and onto another quick before the laptop was sent away to Apple for repair or replacement or before the graphics card gave up the ghost entirely and keep all of the data, applications, etc. intact in order to use it on another mac?”. Stacey needed to be able to work on her files in the state that they were already in. She also used a lot of actions and presets that needed to stay the same in the Adobe Creative Suite. You may have a different reason for imaging a drive and you may have slightly different gear, but the process is relativelythe same. This entire process could also be used in order to backup data and preserve it in “snapshot” format. In other words, an imaged drive is a drive image that has exactly the same number of ones and zeros as the physical drive that it came from. Even desktop icons will remain in their frozen, exact positions.

We are going to be making said image onto a USB drive and re-imaging it back from a file onto a physical drive.

You will surely need:

  • Some knowledge of the Linux command line.
  • Some sort of bootable copy of Linux. (Reason is the drive that’s going to be imaged can’t be mounted at the time as data corruption is very much a possibility). I recommend Ubuntu as it’s popular (easy to find help with) and, well, I know it. So burn this image to CD:
  • A USB hard drive (or other storage media) with more free space on it than the total size of the drive you plan on imaging. You could borrow a friend’s and buy him beer.
  • The computer with the hard disk installed that you would like to image (duh..). You can use this computer to run the bootable copy of Linux while you image the drive.

From here on in, I assume you are on a mac and using Ubuntu Linux. This guide will work for lots of different computers and lots of different flavors of Linux though… Pop the CD that you’ve burned (above) in the mac (or whatever computer you’ve got) and as the mac boots up, hold down C. This forces the mac to look for bootable media in the CD drive and boot from it (the process to boot from CD is different for other computers). Ubuntu loads and boots! :)

Now that Ubuntu is booted, plug in your external drive and open a terminal bash. I think it’s Applications > Accessories > Terminal but look around. At bash type:

“sudo gparted”
(All commands I list here are in “quotes” but don’t type the quotes… oh, you knew that already.. OK!) You’re welcome to copy and paste commands, but do be careful. Read them at least before hitting Enter.

Gparted launches and scans all the drives for partitions and displays them via the dropdown (top right). I’m sorry, I don’t have screenshots… Please don’t hate me.

Locate your USB drive and partition free space to something larger in size (I recommend at least 10GB larger than the drive that you are about image). Use EXT2 as a format – almost all Linux systems like this format and it supports large files. This article will help you. The article says to use the bootable live Gparted CD but you don’t need to do that as you are using a live CD with Gparted on it anyways, it just has an OS on it too. :) Once you are done apply your changes and close Gparted. You’ve now got a large amount of space on a completely blank drive. You can put your image (of your drive) here. Yummy.

Since you haven’t clicked on it via the graphical file manager, the drive you want to image will not be mounted. That’s good. But first, mount the EXT2 partition that you just made on your USB drive. To find all the drives and their partitions:
“sudo fdisk -l” and be sure and put “-l” at the end.

All the drives (mounted or not) list. Find the partition that you just made. It will be recognizable as EXT2 and the proper size (that you allocated). Note the path will be very much likely be: ”/dev/sd”and then”a”or”b”or”c”,ect. and then a number like”1”,”2”or”3”. Example: /dev/sdc2 Note down this path.

“sudo mkdir /media/hippo” We create a mount point for the partition.

“sudo chmod -R 0777 /media/hippo” Permissions are set wide open on our mount point.

“sudo mount /dev/the/path/you/just/wrote/down /media/hippo” Mount your USB drive at our newly created mount point.

“sudo chmod -R 0777 /media/hippo” Just to be sure we set permissions correctly, I run this command again with the partition mounted.

“cd /media/hippo” Change directory to the mountpoint.

“ls” Check the contents of our blank partion on the USB drive. Nothing should list, maybe a folder called “lost+found”. That’s fine.

Just to be really sure the partition is mounted, “mount”. The partition on the USB drive will be listed close to the bottom of the list. Make sure, check the path you wrote down earlier.

“sudo fdisk -l” one more time. This time find the drive you are going to be imaging, not the USB drive’s partition. It’ll be something like /dev/sda without the number and have the flag “hsf+”(this is the Apple Extended Journaling Format). It will have numbers for the partitions. I’m guessing they’ll be two partitions on there, if your mac was setup with just a plain (standard) installation of OS X. It doesn’t really matter as since here we are imaging the entire physical disc. If you want only to image one partition, note down the number at the end of it. Example: “/dev/sda2” However, since we need to image the entire physical disc, we’ll be using the path /dev/sdx without the number. This ensures that the MBR is imaged and the image is bootable once we place it back onto the new drive of our new machine. To be safe, write down the path to the drive that you will be imaging.

OK now to use dd. dd is a UNIX program and is perfect for imaging. It comes with pretty much all modern flavors of Linux. BE CAREFUL HERE. Don’t mix these paths up, otherwise you will image all the blank data from the USB partition on to your drive! Not good. The command will be:
“sudo dd if=/dev/sdx of=/media/hippo/stacey.image bs=4096 conv=noerror”
(Replace /dev/sdx with the proper path! It’s the one you wrote down).

And we’re off! As you know, the command line isn’t pretty so you’ll just get a blinking cursor and the light on the USB drive should be going like crazy. This is good. It means that we are writing our image to the drive. It’ll take about 3 or four hours, maybe more if your drive is over 250GB. Just be patient. The HDD light on the USB drive is your friend. Flashy flashy. When finished, the output numbers of “in” and “out” should be exactly the same (or at max. one number off from each other). You’ll know what I mean. dd gives you these results.

Now you have the image! Don’t worry if it’s going onto hardware with different RAM or slightly different processor speed, it should work. It’s a mac! :) If there are other hardware differences, give it a shot anyways… Good chance as long as this is an Intel mac, and not a PPC mac.

To get your image onto your new mac/computer, keeping all of your files and applications and settings intact:
Basically go through the same steps as above but no need to repartition the new mac’s drive or the USB drive (obviously). The command will look like:
“sudo dd if=/media/hippo/stacey.image of=/dev/sdx bs=4096 conv=noerror” (with x being the correct partition number).

Boot up without holding C and cross fingers!! Right on!

One thing: If the new drive is larger than the old one you will need to use Gparted again in order to expand the image/main partion (created when you dd’d the image onto the new drive) into the new drive space in order to take advantage of the new drive’s ginormous space. HFS+ can only be expanded, not shrunk, FYI.

Have fun and enjoy your new computer without having to setup a new OS! :)

» It's all over...