again: resize a partition?

rhg

Registered
Found this on macosxhints.com - use at your own risk;

http://www.macosxhints.com/article.php?story=20021119053614569&query=partitions


Modify partitions without wiping the entire disk
Tue, Nov 19 '02 at 08:36AM • from: Anonymous
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.
=================================

Another for mirrored drives;

http://www.macosxhints.com/article.php?story=20031026062133683&query=partitions
================================
 
That's great info Bob, thank you. Not exactly what I need, however. Having the opportunity to manipulate the partition table is great, but resizing a partition - my original question - is a different story.
 
rhg said:
Now coming back to an older thread:
http://www.macosx.com/forums/showthread.php?t=36142

How about resizing Mac OS X HFS+ partitions - is it possible?

Does anybody have experience doing this with FWB Partition Toolkit (which is, as far as I understand, Max OS 8/9 only but capable to handle HFS+, see http://www.fwb.com/html/partition_toolkit.html)?

How about hdiutil, can it be used for this purpose (see http://www.osxfaq.com/man/1/hdiutil.ws)?

Or are there other recommendable tools?

Has anyone used Partition Toolkit? I have one (count 'em one) partition on my hard drive, but want to break it up into two so I can install Panther on the second partition. I think you should be able to boot into OS 9, run Partition Toolkit (can you boot off of the PT CD? That would be ideal), create a new partition, then reboot into X.

Any insight?

Thanks!
 
How to join two partition

I would like to know how to join two partition. I have MAC OS X has two partition.

Macintosh HD (43.0 GB) and Untitled (31.2 GB)

I would like to convert into one full partion only. Any step by step help will be higly appreciated.

Thank you

Qamarjrk
 
Back
Top