Repartitioning a GUID disk

From Provider Wiki

Jump to: navigation, search


With later versions of MacOS 10.4 Apple introduced a method to dynamically repartition the disk format used by Intel versions of its computers. This new system is used by the BootCamp system to create new partitions to install Windows onto. As of 10.4.9 Apple has not provided any graphical system of doing this, and you should read all of the caveats before going any further.

Contents

Caveats

  • This is an advanced hint. You can destroy all of your data if this goes wrong, so this is something you should be very, very careful in using. If you are not comfortable with any step involved then DON'T DO THIS!
  • This will only work on computers formated with the GUID disk format. As of 10.4.9 (and probably permanently) this means that all Intel-based macintoshes can do this and no PowerPC (G3/G4/G5) computers can do this. Stated again: This will not work on PowerPC computers.
  • You should update your computer to the latest version of 10.4 before doing this, and run Disk Utilities' "Verify Disk" (and get an OK status) before you do any of these steps.
  • As of 10.4.9 this utility can only shrink or grow existing (HFS+) partitions, it can't move them. So if you have 2 partitions, one after another, you can't grow the first partition without wiping out the second one first (and thus destroying that copy of the data). You can not move the second one back with this tool.
  • Do not use these instructions if you are using BootCamp! BootCamp uses the same tools, but does a couple extra things that these instructions will probably mess up. There are other instructions out on the web that are better sources for this information.

An Overview

Since we are about to make a rather low-level (fundamental) change to a the boot drive of a computer while it is running (read: DANGEROUS) it is a good idea to have some understanding about what we are going to do.

A hard drive is philosophically laid out as a single line of data (in reality it is much more complicated than this, but we are simplifying here). That line of data has a bit of space reserved near the beginning to tell the computer how the rest of the hard drive is arranged. This map points to sections of the hard drive called "partitions". Each of these partitions can be formated differently (examples of formats used are: HFS+ Journaled, NTFS, FAT16, and FAT32).

What we are going to do is to change that map so that that we can add another partition (as an example). Along the way the tool that we are going to use has to understand the format of the partitions that it resizes in order to not break that format, and it might have to move some of the data around in that partition if the data happens to be in a space we want to re-allocate. Luckily for us the tool we are going to use is smart enough to do this for HFS+ partitions.

Getting ready

We are going to be using the command line tool 'diskutil' to do the work. This is the main tool that the GUI program "Disk Utility.app" uses to get its work done (it also uses 'asr' and others).

Getting the name we need

'diskutil' is pretty good about figuring out different ways of addressing disks, but to be on the safe side we are going to be as exacting as possible.

So our first task will be to get the names of the volumes we are going to be changing. To do this open a command line window and enter the following command:
diskutil list
That should return something like this:
/dev/disk0
   #:                   type name               size      identifier
   0:  GUID_partition_scheme                    *149.1 GB disk0
   1:                    EFI                    200.0 MB  disk0s1
   2:              Apple_HFS Macintosh HD       148.7 GB  disk0s2

If you have more than one physical drive connected, including CDs/DVDs, external hard drives, USB thumb drives, or anything else you might see more entries. You should be able to figure out which group refers to your main drive using the name column.

You might have noticed that despite the fact I am starting with a disk with only one "partition" on it, I seem to have 3 partitions on it, and two of them seem to be quite large. The first one (0) actually refers to the whole disk and how it is formated. This nicely gives us the total size of the disk, and the fact that it is formated with GUID (the "GUID_partition_scheme" part). If the '0' line says anything other than "GUID_partition_scheme" (such as Apple_partition_scheme), then you can not use this article.

The second line (1) is a little section is a partition that the computer uses to boot off of. You should never touch this section unless you really, really know what you are doing. Apple assumes that it owns that section, and you may well render your computer unbootable by messing with this. People have rendered their computers into bricks/doorstops by playing with this. There are ways back, but they are not easy. Put simply: don't touch this.

It is the third line (2) that we are going to be playing with. Note that the name ("Macintosh HD" in this case) is that of your main hard drive. And here the important bit of information we need is the last two bits: that the disk is 148.7 GB, and that it is named "disk0s2". Note that in theory this name can change between boots, and for external drives there is a good chance that it will. So if you are going to be playing with this you have to be careful. But for most Macs as they came out of the factory it is likely that you will be using "disk0s2".

If you do have more than three lines things can get a bit complicated. Without moving data around (my suggestion would be disk images) you can only work on the last partition on a disk (oversimplification, but probably true enough). And if you do find yourself in a more complicated situation then this article is not going to cover it for you. If you have used BootCamp to re-partition your drive already then you also find yourself in the same boat. There are other articles out on the we that might be able to help you, but that is outside the scope for this article.

Figuring out how much space we have available

Now that we know how we are going to reference the disk (disk0s2), we need to figure out how much data is already on it, and how small we can make it. Once again diskutil can be used to get this information with the command (replace 'disk0s2' with your volume label if it is different):

diskutil resizeVolume disk0s2 limits

Which should return something like:

For device disk0s2 Macintosh HD:
        Current size:   159697911808 bytes
        Minimum size:   52469465088 bytes
        Maximum size:   159697911808 bytes

As you can see, the sizes are listed in bytes. To translate the numbers into Gigabytes, divide them by 1073741824 (1024*1024*1024). In this case I have about 148Gigs to play with.

From this you are going to need to decide how large a chunk you want to take out of this partition. Remember that if you are going to continue to use your original partition that you have to leave enough room to add things to it, you probably will not be able to grow the original partition without going to a lot of trouble once you have the new partition tacked on the end.

Since the goal here is to add another partition, I am going to set my existing partition to 75 Gigs and I want my second (and last) partition to take up the rest of the space. I could do all of the math and figure out how pig it should be so that I don't wind up with extra space, but diskutil defaults to making the last partition as big as it can be (ignoring what I tell it), so I am just going to make the number a bit smaller than I need and it will take care of that for me.

Making the changes

Now that you have decided how large your old partition is going to be (I have decided on 75Gigs) it is time to shrink the old partition and add the new one.

Warning: this is where you can do serious damage to your data

First quit out of all apps that are not strictly necessary. You want to have as little writing to your hard drive as possible.

Now we are going to actually shrink the volume (substituting your volume label and size) and adding the :

sudo diskutil resizeVolume disk0s2 75G JHFS+ NewVolume 73.5G

Here is a breakdown of what I am telling it:

  • sudo - I want to run the following command with root priveleges
  • diskutil resizeVolume - I am using diskutil, and telling it that I want to resize a volume
  • disk0s2 - this is the name of the volume I want it to resize
  • 75G this is the new size of that volume

The rest of the command is creating a new volume

  • JHFS+ - this tells diskutil that I am going to put a Journaled HFS+ filesystem in this new partition
  • NewVolume - this is the name I want to give the new partition
  • 73.5 this is the size I want the new partition to be. Use 'diskutil resizeVolume' to get the format for this. I did the math and that is how much space will be available.

This should ask you for your password, then take a few minutes. You should get something like this:

Started resizing on disk disk0s2 Macintosh HD
Verifying
Resizing Volume
Adjusting Partitions

Finished resizing on disk disk0s2 Macintosh HD
You will need to manually reformat your new partitions.
WARNING: You must now reboot!

And here we are going to do what it asks and reboot the computer.

Once you have rebooted use Disk Utility.app to format the new volume the way you would like to, and you should be up and running.

References

In creating this article I used the following sources: http://www.macgeekery.com/tips/cli/nondestructively_resizing_volumes

Personal tools