Partitioned OS X installation with seperate swap partition.....

Aug 09, '04 10:41:00AM

Contributed by: jalbrecht2000

I'm not going to get into a battle of whether or not to partition an OS X installation. I found partitioning useful, but found very little information on how to do it. So here it goes.

The overall goal of this article is how to properly do a partitioned install on OS X. I will be the first to admit that I'm a new OS X user, but I've been a FreeBSD user for quite sometime. I even tried using all of the hints on macosxhints.com and none of them ever completely worked.

Using the other hints, if you booted your system in verbose mode and watched the log on the screen, the partitions were never mounted properly by the BSD subsystem. Granted OS X has some failsafe procedures and these partitions ended up being mounted anyways, but it caused me nothing but problems down the road. Here is what I came to find out. Without properly mounting the partitions at bootup, your Applications and Users partitions get mounted under /Volumes instead of under /. This can cause some serious problems when a program starts traversing your directory structure and doesn't find those two folders where it expects to find them. When I started installing applications it just started dumping them in the root of my system drive instead of under the Applications partition like I wanted.

I saw plenty of people who were talking about using BSD symbolic links to fix this, but that really is more of a band-aid than an actual fix. The instructions on how to partition this install are pretty much the same as the other posts, but the key here is the modifications made to the fstab file. Simply using the Label=partitionnamehere option doesn't work. What my trick does is it makes the file system look identical to a single partition (according to the OS, that is), even though you actually have multiple partitions setup.

Please remember to backup before proceeding!

Start the OS X installation by booting off of your system restore CD. Once you are at the welcome screen, click installer and then click on Disk Utility. The disk utility will open up and allow you to view your drives and their current status. Select the drive that you wish to partition and then click on the partition button. Choose a partition scheme that will work for you. Please remember to leave plenty of space on each partition for expansion, as this cannot be easily undone later.

On my installation, I chose to create four partitions. One for the system files, one for the Applications directory, one for the Users directory, and one as a swap/scratch partition for OS X and Adobe applications. I recommend setting your swap partition to 1 gig. Anything more than that is wasteful unless you have some huge Photoshop projects. Make sure you set the swap partition to UFS instead of HFS+. UFS is far less prone to fragmentation. A fragmented swap file defeats the hole purpose of a separate partition.

I chose 6 gigs for my System partition, 10 gigs for my Applications partition, 1 gig for swap, and the rest of my drive for the Users partition. The user partition is bigger because I store most of my files in my home directory. Once you have selected your partition layout, click the Partition button. The Disk Utility will partition the drive and then format all of the partitions. Once this process has been completed, you can drop back out to the installer and continue the OS installation.

Once you have OS X up and running, you need to open up terminal and run some commands to prepare our partitions to be used by the OS. First we need to duplicate the Users and Applications folders to their respective partitions. At the command prompt run the following commands:

$ sudo ditto -v -rsrcFork /Applications /Volumes/Applications 
$ sudo ditto -v -rsrcFork /Users /Volumes/Users
Once this operation has completed, we need to update our system to attach the new partitions as usable file systems for OS X. We do this by editing fstab under /etc. To do this, you must first find the unix label for the partitions. Do this by typing the following:
$ df –k
This will print out a partition list and their relative mount points. You are looking for something like the following:
/dev/disk0s7   7208960   4882716   2326244   68%  /Volumes/Applications
/dev/disk0s9   23529816  3279444  20250372   14%  /Volumes/Users
The important part of this is the /dev/disk0s7. ***NOTE*** Your label will vary. Write down the unique numbers after the /dev/disk portion to get the correct partition location for your system. We will use this later. Now it's time to update fstab to modify how OS X mounts and uses the partitions. Do this by typing the following:
$ sudo pico –w /etc/fstab
This will open pico, a unix text editor, and load the fstab file. At the end of this file type the following in:
/dev/disk0s3 /Volumes/swap ufs rw 1 2
/dev/disk0s7 /Applications hfs rw 1 2
/dev/disk0s9 /Users hfs rw 1 2
Please change the information above to match what we wrote down earlier. The UFS and HFS parts make a difference, too. You need to set these to whatever you chose to format the partition during installation. (Notice how swap is set to ufs, or the Unix Filing System). Once you have typed this in, press control-O to save the file, and then Control-X to exit pico. Now we will load the fstab info into netinfo:
$ sudo niload -m fstab / < /etc/fstab
Once this has been completed, you are finished with this portion of the work. Now we must load OS X into single user mode to properly create placeholders for the partitions. Do this by restarting your computer and holding down Command-S immediately after the chime. You will see some unix code fly by, and then you will be dumped to a unix prompt. Now it's time to make OS X behave the way we want it to. Check the file systems by typing the following:
$ /sbin/fsck –y
Now mount the root partition in read/write mode:
$ /sbin/mount –uw /
Move the Applications and Users directory to alternate directories as a backup in case something goes wrong:
$ mv /Applications /Applications-old
$ mv /Users /Users-old
Now create empty directories for to use as placeholders to mount our partitions into:
$ mkdir Users
$ mkdir Applications
Now let's set the appropriate permissions for the directories:
$ chmod 755 Users
$ chmod 755 Applications
Now we will reboot the computer and watch the startup to make sure there are no errors. Do this by typing the following:
$ reboot
When your computer chimes, hold down the Command-V keys. This will print the verbose logging to the screen. Look for the following:
/dev/disk0s7    /Applications  (local, journaled)
/dev/disk0s9    /Users		(local, journaled)
If you see something similar to above, you've done it! You now have a partitioned system that keeps your User, System, and Applications files separate. This is especially useful for system crashes. You can simply reload OS X and follow the instructions above (minus the ditto commands) and keep your Applications and User files intact. Now let's finish moving the swap file. Open up terminal again and type the following:
$ sudo pico –w /etc/rc
Now let's search for the correct line. Type control-W and type swapdir in the search field. This will bring you to a spot in the file with the following information:
echo "Starting virtual memory"
swapdir=/private/var/vm
Comment the swapdir out by putting a # sign in front of it so it looks like this:
#swapdir=/private/var/vm
Now type the following below the commented line:
swapdir=/Volumes/swap/vm
So now the file should look something like this:

echo "Starting virtual memory"
#swapdir=/private/var/vm
swapdir=/Volumes/swap/vm
Type Control-O to save and Control-X to exit. Restart the system. Once it has been rebooted, verify that your swap file has been moved by openeing the swap drive, opening the vm folder, and verifying that a file called swapfile0 exists. If it does, you're all done! If it doesn't, go back and check for mistakes.

Comments (37)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040716153639236