Monday, May 7, 2007

Removing Ubuntu from my MacBook Pro

You've followed some how-to's online and setup your MacBook Pro to dual boot OSX/Ubuntu. Now you realize that you never use Ubuntu and really want that space back on your OSX partition so that you can keep downloading episodes of The Office. Well it's not as easy as it sounds.

It was a long process but I finally got that sucker off of my laptop. I found a lot of stuff on the internet about resizing* an HFS+ partition but basically only Bootcamp and commercial software can do it. The most important piece of information in the post is at the very end, about restoring a backup image using the OSX install disk.

What Doesn't Work

Bootcamp - Normally what a user does is repartition their drive with Bootcamp, install Windows, gets bored, then uses Bootcamp to delete the Windows partition and have their OSX partition take back the space. If you alter the partitions at all after running the Bootcamp utility to repartition your drive you cannot use Bootcamp to restore it. It will display a message telling you that it cannot recognize the Windows partition and then exit.

Disk Utility - This program is pretty much useless. It won't let you alter any partition that it doesn't understand and just about the only type it does understand is HFS+.

GParted - I found this great utility for repartitioning drives. Too bad it doesn't support resizing of HFS+ partitions.

Tricking Bootcamp - I used GParted to reformat the linux partition to FAT32 and NTFS but try as I may, I couldn't trick Bootcamp into thinking that there was a Windows partition that needed removing.

What Does Work


These are the steps I went through to completely restore my computer back to working order, complete with the stupid things that don't work that'll drive you crazy trying to figure out.

Preparing the USB Drive For the Backup

Most USB drives are formatted to FAT32 because both Windows and Macs can read/write to it. Too bad FAT32 doesn't support large files.
  1. Boot up using GParted
  2. Shrink the FAT32 partition to make room for another partition that is LARGER than the amount of data that is on your OSX partition.
  3. Boot up using the OSX install disk and run Disk Utility to create a new HFS+ partition on the USB disk from the free space.
How to Make the Backup
  1. Boot up using the OSX install disk
  2. Click on the OSX partition you want to back up (probably called "Macintosh HD")
  3. Click "New Image" and save to the partition on your external USB device that you just created.
Repartitioning

Any changes you make to your partition table using Disk Utility WILL indeed erase all the data on it. It is not lying when it warns you of this fact. Just delete the extra partition and make the OSX one as big as you can.

How to Restore the Backup

This is probably the most annoying part of the whole thing. You see there is a problem with the version of Disk Utility that comes on the Intel OSX install disks. Basically you can't use it to restore a backup. Damn them!
  1. Using Disk Utility, mount your backup image
  2. Quit Disk Utility and open up the Terminal
  3. Type in the following commands
    • cd /Volumes/{mounted backup}/Applications/Utilities
    • cp "Disk Utility.app" /Volumes/{usb backup}/
  4. Replace {mounted backup} with the name of the partition image, probably something like "Macintosh HD 1" and replace {usb backup} with the name of the HFS+ partition on your USB drive.
  5. Quit Terminal and open Disk Utility
  6. Unmount the backup image
  7. Quit Disk Utility and open up Terminal
  8. Run the new Disk Utility program
    • cd /Volumes/{usb backup}/"Disk Utility.app"/Contents/MacOS
    • ./Disk\ Utility
  9. Now you can properly restore the disk image
    • just select the partition you want to restore
    • click "Restore" and drag the partition to "Destination"
    • click "Image..." and select your backup
  10. You're Done! Reboot and enjoy.
Basically to restore your backup you just need a working version of Disk Utility. You could do this multiple ways other than retrieving it from your backup image. It would probably make more sense to copy it over to your usb drive before you started trying to mess with partitioning at all.

*One method to resize an HFS+ partition I cam across was to use the command diskutil resizeVolume but I was unable to get this to work.

Creative Commons License

4 comments:

Alltruist said...

Thank you so much for posting this tutorial. I had the same problem.

One slight mistake I found was that for the terminal command for copying Disk Utility.app, since the app is a directory, the command should be:

cp -R "Disk Utility.app" /Volumes/{Usb backup}/

Thanks!

Rukqo said...

Actually, the problem can be solved much more easily. If you delete the Windows partition with GParted and resize your Mac partition with Disk Utility, your problem is solved.

Alltruist said...

The problem with resizing the Mac partition after removing the Ubuntu partition is that Disk Utility doesn't let you resize without erasing the entire partition.

Paulo said...

@Alltruist: what Rukgo said works just fine. I've just booted with Ubuntu LiveCD and removed Linux partition using GParted. Then booted with OS X Leopard CD and resized hard disk with Disk Utility. Now, only have OS X. Without loosing any data (ie, without formating entire partition). Really, was that easy. So happy! :)