Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Modify partitions without wiping the entire disk System
I had originally created three partitions on my hard disk, one for OS X, one for Home directories, and one for other stuff. After a while I wanted this changed to merge the second and third partition. I did not want to reinstall everything. Apple's Disk Utility insists on wiping the whole disk, so its use was out of the question. What do do?

[Editor's note: The remainder of this article describes a process through which you can make changes to your partition map without wiping everything on the hard drive. Please note that this does not mean you can modify a partition without losing the data on that partition!! This hint is extremely dangerous if used incorrectly, and I have not tested it myself. I strongly urge you to proceed with extreme caution and make sure you have a full and working (test a restore!) backup before you attempt to modify your partitions in the following manner. With that caution in mind, this appears to be a good way to save a reinstall if you wish to modify a partition structure that has OS X on its own partition, and any number of other partitions for other stuff.]

Enter pdisk
Mac OS X comes with a command line utility called "pdisk". It can be used to edit the disk's partition map and will not force the whole disk to be wiped. Of course any partitions that you delete or create will be wiped, but those left alone while using pdisk will remain as they were and the data will not be disturbed. So, here is what I did:
  1. Make a backup of the data on my second and third partition
    You can do this any way you like, but remember to preserve file ownership and permissions.

  2. Boot from installation disk in single user mode
    Boot from CD-ROM using whatever method is appropriate for your machine. For me it means holding down "C". Next, timing is crucial. In order to boot in single user mode you must hold down command-S. If you do this too early you may boot into your OS X version still on hard disk, if you do it too late, the installer on the CD-ROM will fire up. For me the procedure turned out to be to let go of the "C" and press Command-S just before the grey screen with the Apple logo comes up. This may take some experimenting before you succeed.

    The sign you did it right is for some text to come up on the screen with a remark at the end that file system has been mounted read only. If you understand the rest of the messages you can check that you booted from the CDROM by checking it booted if the right /dev/disk.

  3. Use pdisk to delete two partitions and create one larger one instead
    I will give the commands for my situation as an example. My second and third partition were slices 10 and 11 (you can see these numbers if you use the "p" command for pdisk to list the contents of the partition map). So, the sequence of commands I used was:
     pdisk
    e
    /dev/rdisk0
    p
    d 10
    d 11
    C
    10p
    11397071
    Home
    Apple_HFS
    w
    y
    q
    The "e" command initiates editing. It will ask which device, to which I answered the name of my primary disk. The "p" command prints out the partition map, useful for double checking your slice numbers. Based on this printout, I needed to delete slices 10 and 11 with the two "d" commands. Before I did so, I wrote down the size in blocks (from the "p" command) for the two slices I was going to delete. Next I used "C" to create a new partition. It will ask for the first block of the new partition. I indicated "10p", meaning "same as slice 10" (which was now a partition marked as free).

    Next you will be asked for the size in blocks. I would normally have answered "10p" again, but that leaves zero blocks for the "free partition". Although my original partitioning was like that, earlier experiments had pdisk freak out when I tried to create that partition with length 0, so I decided to make my new partition one block smaller. This prevents using "10p" as the command. Instead, add up the size of the two partitions you wrote down earlier, subtract one, and input that number. Finally you'll be asked for the name for the new partition, pick anything you like, and the type, which will almost always be "Apple_HFS".

    When all this is done, use the "w" command to write the new map to disk. You'll be asked if you are sure, enter "y", unless you think you made a mistake. If you do not execute "w", but proceed to the "q" command to quit pdisk, nothing will be written and you can start over. This is important to remember if you make a mistake.

  4. Intialize the new partition with a file system
    Use this command:
     % newfs_hfs -w -v Home /dev/disk0s10
    After writing the partition map and quiting pdisk, you must initialize the new parition. Note that it was created on slice 10, hence the form of the final command above.

  5. Restore my backup to the new partition

  6. Make sure permissions and ownership are OK
    In my case, I had to recreate the Users directory on the new partition. Things will not work correctly if this directory does not have the right permissions and ownership. In my case it needed to be owned by user root, group wheel and the permissions needed to be rwxrwxr-t. You could use the following commands to do this:
     % cd /Users; chown root.wheel .; chmod 775 .; chmod +t .
  7. WARNING
    THE ABOVE IS JUST A DESCRIPTION OF HOW THINGS WORKED FOR ME. MESSING WITH THE PARTITION MAP CAN RENDER ALL YOUR DATA LOST. MAKE SURE YOU HAVE A BACKUP!
Final remarks:

You can do a dry run with pdisk as long as you do not execute the "w" command. pdisk works with an in-memory copy of the partition map and only writes it if you issue the "w" command, and only then if you confirm it. Do a dry run with lots of "p" commands to get comfortable.

The whole repartitioning procedure only took a couple of minutes. Making the backup and restoring it took significantly longer. I used a firewire disk to copy files back and forth.
    •    
  • Currently 3.75 / 5
  You rated: 4 / 5 (4 votes cast)
 
[116,309 views]  

Modify partitions without wiping the entire disk | 22 comments | Create New Account
Click here to return to the 'Modify partitions without wiping the entire disk' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Thank you!!
Authored by: urcindalo on Nov 19, '02 10:58:25AM

Thank you!!

I've wanted to know how to do that on OS X for ages.
And the explanation is clear and concise ;)



[ Reply to This | # ]
Great!
Authored by: prk on Nov 19, '02 11:53:56AM

This hit came at just the right time. Last night I was wanting to nuke the Debian partition on my Mac and make it another Mac partition. I do not use Debian on my Mac any more now that 10.2 is on my system. I was having so many problems before that I would dual boot to Debian to get my work done.



[ Reply to This | # ]
Great!
Authored by: dolfs on Nov 20, '02 12:34:45AM

Note that for this case you will only have to "delete" the entry for the Debion partition and than use the C command to create an Apple partition instead. Also, the parameters will be simpler. Let's say your Debian partition was "7":
e
/dev/rdiskx
d 7
C
7p
7p
Name
Apple_HFS
w
q



[ Reply to This | # ]
Resize
Authored by: arizdave on Nov 19, '02 02:53:26PM

Is it possible to just "resize" 2 of 4 partitions without deleting them & if so how??



[ Reply to This | # ]
Resize
Authored by: lstewart on Nov 19, '02 03:35:01PM
Someone please correct me if I'm wrong, but I don't think it's possible to resize partitions without losing the information on them.

I came up with a procedure similar to the above back when I was juggling partitions between OS 9, Mac OS X Server 1.x, and LinuxPPC. There is a port of pdisk that works under OS 9, and I used it with great success, without even booting off the CD-ROM. (It would modify the tables of the booted partition, but the changes would only become active when you rebooted.)

pdisk works great for wiping & redefining partitions, but it's not cut out to resize or move existing partitions without data loss. That's one of the things I miss from my past life on the PC... PowerQuest's Partition Magic. That thing would resize, move, consolidate, slice, dice partitions on a PC like nothing else. Too bad they're not in the Mac market. (I actually know an engineer there, and tried to talk him into a Mac port, but I was starting on the wrong end of the management chain. ;-)

Once I foolishly tried to "consolidate" two contiguous HFS+ partitions (using pdisk - delete the second partition and resize the first one to take up all the space) while retaining the data on the first one. It really hosed things. I had to run every disk utility I could get my hands on several times each before the partition would mount, and if my memory serves, it never worked completely (without errors) again until I reformatted it.

I've looked at several HFS+ disk utilities, and though I found one that claimed to do partition resizing for (legacy) HFS disks without data loss, nothing I found would work for HFS+. It's been a couple years since I researched it, though, so maybe there are more options now.

[ Reply to This | # ]

Resize
Authored by: gvitale on Nov 21, '02 07:36:50AM

as pointed out by dolfs, pdisk is not destructive, as it does not manipulates the partitions themselves. In other words it relocates disk blocks to logical partitions, without actually writing data to the blocks themselves. This means that you can split an existing partition (lets say 40% full) in two (or more) partitions and still preserve the content of the original disk/logical partition. The first of the newly created partitions must have enough blocks allocated ti it in order to accommodate all the data of the original partition (that is at least 40% of the blocks have to be relocated to the first of the newly created partitions), and all the data have to be moved to that blocks PRIOR repartitioning the original disk/logical partition (this can be done with Norton SpeedDisk, selecting CD master as optimization profile). After repartitioning, all the data (and the directory information) will still be present in the first new partitions, and you should run a disk repair utility to fix inconsistencies in the disk catalogue map.
You can practice this with a disk image, before doing thinks to your HD ;-).



[ Reply to This | # ]
iPartition will do this
Authored by: Coriolis Systems on Jul 05, '04 12:55:23AM

Our product, iPartition, will let you resize partitions easily without having to reformat. See our site for more information.

We should also say that we definitely do not recommend the method espoused by some people in this thread whereby pdisk is used to change the size of the partition and then a disk repair tool is used to clear-up the resulting mess. Even with a disk repair utility involved, the volume that results from this operation is most likely quite broken, as the volume data structures will not have been resized correctly to take account of the new size of the volume.



[ Reply to This | # ]
Resize
Authored by: dolfs on Nov 20, '02 12:41:48AM

Remember that pdisk manipulates the partition map, not the partitions themselves. As a result (and as noted by the editor in the original hint), you can not preserve the contents of a partition itself if you manipulate its entry in the map.
If the 2 partitions you are asking about are physically adjacent on the disk (meaning that the start of the second one is equal to the start of the first one, plus its length), you can delete both entries (and thus loose the files on both partitions), and create a single new partition that combines the original ones in terms of size.
You will still have to run the newfs command to initialize the file system on the new partition. If you did not already understand, this command will erase anything that used to be on those two partitions.
So, as long as you backed up all your files, you can now restore them to the new and larger partition.



[ Reply to This | # ]
Resize
Authored by: calroth on Nov 20, '02 09:32:24AM

I tried resizing a partition using pdisk (on a HD which I wasn't using otherwise, no data at risk, etc.). The result was, it mounted OK and looked good in the Finder, but came up with directory structure errors which I couldn't fix. Not something I was willing to live with.



[ Reply to This | # ]
It really works
Authored by: dolfs on Nov 20, '02 12:29:22AM

I was the one to submit this hint (before I had an account, hence the anonymous). I actually performed this procedure succesfully. The only problem I encountered was not being able to login until after I hade made sure the directory permissions for /Users were OK. This is one of the last steps mentioned in the hint.



[ Reply to This | # ]
bonus points
Authored by: Hes Nikke on Nov 20, '02 03:44:42AM
for bonus points, you can mount your new users partition at /Users rather then /Volumes/Users using this hint :D

[ Reply to This | # ]
Important tips on pdisk
Authored by: metafeather on Nov 20, '02 05:25:01AM

Having used pdisk on OS9 and OSX this is one utility where it really pays to read the man page, and here are some other tips:

1. A capital 'L' will list all the current partitions, their start block, length, device and name.
This gives you all the info you need to manipulate the map and i generally do this first.

2. The first thing you see from the above is that there are a number of partitions used by apple for boot drivers etc - DO NOT MESS WITH THESE!
Therefore your first partition is not your first (its generally the 9th)

3. You can do all this as root or sudo on a running system, the map will not be written until the 'w' command and not active until you reboot.

As a general strategy, this is one reason for partitioning a new machine to have the OS on a separate partition, you can then backup files and rearrange the rest of your partitions without ever having to reinstall.

Good luck



[ Reply to This | # ]
Map is not writable
Authored by: jkolb on Nov 20, '02 10:23:03AM

I tried the originally posted directions on my machine with a UFS formatted OS X.2 partition, and did the following:

Top level command (? for help): e
Name of device: /dev/rdisk1
/dev/rdisk1
Command (? for help): d 9
The map is not writeable.
Command (? for help): c
The map is not writeable.
First block: 9p
Length in blocks: 21002992
Name of partition: Name
Command (? for help):

As can bee seen from the above, pdisk never asks for what format, and when I look at the partitionaing table, it shows the new partition as Apple_UNIX_SVR2. Does anyone know if having a UFS partition causes this?

I've been careful and haven't dared hit "w" yet....



[ Reply to This | # ]
Map is not writable
Authored by: kurtis on Dec 12, '02 04:31:18PM

Whenever you create a partition, you have to make sure you're using a captial C. Othewise it's automatically making an MkLinux partition (or some it claims in the Help context). Good luck.



[ Reply to This | # ]
Map is not writable
Authored by: cubixe on Dec 14, '02 10:17:07AM

Make sure you boot from a CD



[ Reply to This | # ]
Map is not writable
Authored by: tdearborn on Oct 16, '04 09:10:18PM
I found that the map is not writeable because the drive is mounted. You need quit pdisk, 'eject' the mounted drive/partition(s), and then sudo pdisk again.

Also, be careful about using the "L" command in the top level of pdisk, as this will remount the drive you just unmounted. Go straight to "e" and type the device in. You can then use "p" to display the partition map without mounting the drive.

[ Reply to This | # ]
Add OS9 drivers to OSX partition table
Authored by: tingeltangelb0b on Nov 26, '02 10:33:51AM

Hi there!
Is it possible to add OS9 drivers to my OSX disk? I forgot to check the box at the installation procedure. I have only one partition. I don't want to install it all over again...
Thanks for help!
Bob



[ Reply to This | # ]
Add OS9 drivers to OSX partition table
Authored by: kurtis on Dec 12, '02 04:34:19PM

I haven't actually tried this yet, but it's all in theory. If you reboot your computer with a startup disk (I'd suggest OS9 but X should work as well), you can go into a drive manager. In MacOSX Install, you'll find Drive Setup in your OSX Install Menu. In OS9, go into your applications and then enter Drive Setup. You'll want to format the desired partition again (after using Pdisk) with the option of using OS9 Drivers. Good luck and remember, this is in theory.



[ Reply to This | # ]
Another means of booting
Authored by: Monkey Angst on Jan 08, '03 06:17:37PM

Loved this hint, it helped me reclaim a Linux partition for OS X.

But it doesn't have to be that tricky to boot to CD from Single-user mode. If you have an AGP G4 or later, restart with Option held down, this will give you startup manager. Select the CD, then hit the arrow pointing to the right, and immediately hold down Cmd-S until you see text. (remember -- everything will take longer while booted to the CD)



[ Reply to This | # ]
Great for old machines
Authored by: discordantus on Jul 14, '03 03:54:23AM
Thanks! I tried this and it worked like a charm. It had additional benifits, too:

I wanted to install my copy of Panther Dev Preview alongside my Jaguar installation. Problem is, the current partitioning scheme I had was not suitable. I have an old machine, so any boot volume must be within the first 8 gigs of the disk. I had one 6.5 gig system partition, one 1 gig OS9 partition, followed by a 1 gig swap partition; followed by the User partition, which filled up the rest of the disk.

I wanted to get the maximum space for my new system partitions, so after deleting the smaller partitions, I multiplied out the number of blocks in 8 gigs. I created a new partition starting at the block number I figured out, and only one block long. Then I divided up the free space in front of it (a little less than 8 gigs) and partitioned it. Finally, I deleted the the 1 block partition and left the 500 megs following it as free space (the rest of the disk is 80gigs, so I wasn't concerned about the wasted space).

This way, I got the absolute maximum space available on my system partitions.

[ Reply to This | # ]

Use iPartition, it's much easier
Authored by: Coriolis Systems on Jul 05, '04 12:59:42AM

It's a bit of a blatant plug, but our product, iPartition, is a great deal easier to use than pdisk, and has the additional bonus of being able to resize existing partitions without destroying their contents. See our site for more information.



[ Reply to This | # ]
Use iPartition, it's much easier
Authored by: sjk on Jul 05, '04 09:00:59PM

Be shameless. If this works to effectively expand an eMac system (boot) volume a few GB by stealing space from its other volume you may get my $ (or £, as the case may be). I'll take a closer look later...



[ Reply to This | # ]