Resize partitions on-the-fly
Command-line enthusiasts know that if you can do something in the regular Mac interface, you can usually do it faster using Terminal. But as of Mac OS X 10.4.6, Terminal also lets you perform a feat that previously required add-on software. Using a hidden command, you can resize disk partitions on-the-fly, without losing data.
This command lets you change the size of an Intel Mac’s partitions, or of external disks connected to that Mac, while the data remains untouched—a job that used to require software such as Coriolis Systems’ $45 iPartition. The addition of this feature is a boon to anyone who has ever split up a disk, realized that one partition was too small, and then suffered through backing up, repartitioning, and copying data back to the drive once again. (For more information about partitioning, see Multiply Your Drive.) Of course, you should always back up data before messing with your disk, but if all works as planned, your backup will now just be a safety net.
What’s the magic command? It’s a function of the
resizeVolume. It’s so secret that it doesn’t even display in the appropriate
manpage. However, by typing
diskutil resizeVolumein Terminal (/Applications/Utilities), you’ll get an overview of the command and its syntax.
Note that this command works only on Intel Macs with hard disks formatted using the GPT (GUID Partition Table) format with a journaled Hierarchical File System Plus (HFS+) file system. This is the default for Intel Macs’ hard disks, but you can also format an external drive in this manner through Disk Utility (/Applications/Utilities).
To use the
resizeVolumecommand, you need to get some information: you must be able to specify which partition you want to resize. You also need to know the partition’s size limitations, since it must be big enough to hold data already on the disk.
To find the partition’s name, type
diskutil listin Terminal. Press return and you’ll see a list of all the disks on your Mac (see “Particular Partitions”). The one labeled /dev/disk0 is your boot disk. If you have other disks, they’re named disk1, disk2, and so on. Look under the Identifier header for the names of the disk’s partitions; for example, disk2s2. (Ignore any partitions labeled GUID_partition_scheme or EFI.)
Now you need to find out what size your new partition can be. Run this command:
diskutil resizeVolume disk_identifier limits, replacing disk_identifier with your partition’s identifier. This will return the current size of the partition, as well as the minimum and maximum sizes you can use. For example:
For device disk2s2 Untitled: Current size: 215822106624 bytes Minimum size: 6691028992 bytes Maximum size: 215822106624 bytes
Compose your command
Now that you know the disk’s name and size limits, prepare your command. It should follow this basic model:
diskutil resizeVolume disk_identifier partition_size second_partition_format second_partition_name second_partition_size
The first part of the command is, of course, the command itself:
diskutil resizeVolume. Follow that with the identifier and size of the partition you’d like to split. Type in the size you want this partition to be, not what it currently is. So, for example, if you want the first partition to be 100GB, specify
100G. (Notice that you drop the B from the abbreviation for gigabyte ; you’d do the same for megabyte ). Finally, specify the format, name of your choosing, and size for the partition you want to create. Want more than two partitions? Just add additional arguments to your command.
Although you can resize the first partition, you can’t change its format—that’s why you don’t need to specify one for it. For each additional partition you wish to create, you must specify the format you want it to adopt. For example, type
JHFS+for journaled HFS+,
HFS+for unjournaled HFS+,
UFSfor Unix File System, and so on. You must specify the size for each partition. For example, to create a 100GB partition in journaled HFS+, you’d type
JHFS+ new_partition_name 100G.
You cannot create a bootable partition for Boot Camp using this command. The
diskutil resizeVolumecommand will resize your disk, partition it, and format it to use MS-DOS, but it can’t install an MBR (Master Boot Record) on the disk. To make a bootable partition for Windows, you must use the Boot Camp Assistant or partition your disk with the
diskutil partitionDiskcommand, which will destroy all data on it. (Type
man diskutilin Terminal for more information on this command.)
The command in action
Here’s an example of a slightly more complicated
diskutil resizeVolumecommand at work:
diskutil resizeVolume disk2s2 100G JHFS+ Part2 100G
This command splits a single partition in two. It specifies a size of 100GB for the first partition. Then it creates a new, second partition, named Part2, using the journaled HFS+ format, with a minimum size of 100GB. If there’s more empty space in the partition, the command will use it all. So if you split a 232GB partition, the above command would give you a first partition of 100GB and a second partition of 132GB.
Two Disks, Two Formats You can also use this command to make partitions with different formats if you need more disk space for Boot Camp. Using the previous example of a 232GB hard disk, here’s how you’d redo the partitions to create one partition for Mac OS X and another for Windows:
diskutil resizeVolume disk2s2 132G MS-DOS Windows 100G
You now have a 132GB journaled HFS+ partition (for Mac OS X), and a new 100GB FAT32 partition named Windows. Here’s something to keep in mind: Windows ScanDisk, the Windows disk-checking and -repair utility, requires that you make the FAT32 partition no larger than 124.55GB. If you don’t plan to use ScanDisk, don’t worry about this limit.
Reassess Before You Resize If you want to split your Mac partition again, run
diskutil listto make sure you know which identifier to use—the partition numbers have probably changed. To split the Mac partition from the previous example in two again, for example, you could run this command:
diskutil resizeVolume disk2s2 65G JHFS+ Part2 65G
You now have two Mac partitions and one FAT32 partition. You cannot resize FAT32 partitions with the
The Last Word
resizeVolumecommand occasionally fails. If it encounters any disk problems, it will stop, and you’ll need to run Disk Utility or another disk-maintenance program. If you have any system or special metadata files—which can’t be moved—in the section of your partition that you wish to reallocate, the command will also fail. Unfortunately, the error messages won’t go into any detail.
This new command is a work in progress and will probably see changes when OS X 10.5 arrives. In the meantime, with this tool at your disposal you can resize partitions on-the-fly, rather than having to copy data back and forth to an external drive. And you don’t have to spend a dime to do it.
Before using this technique to resize the partitions on your drive, make sure you’ve backed up everything. It’s all too easy to make a typo, and you can’t undo the command line! (For backup tips, see Better Mac Backups.)
[ Kirk McElhearn is the author of many books, including The Mac OS X Command Line: Unix under the Hood (Sybex, 2004). ]Particular Partitions: Before you can resize your partitions, you need to know their proper names. Use the diskutil list command to discover those names. Its output shows you the partition identifiers (A).
Resize partitions on-the-flyNext Page