Create a new disk partition without partitioning

May 09, '05 02:00:00PM

Contributed by: juz10mac

This hint will let you create a new disk partition without destroying your data, or actually partitioning. What do I mean? I think this warrants some explanation: Instead of partitioning your hard disk to divide the space between two different volumes, you will make a disk image that is invisible. This disk image will be automatically mounted when the system boots, and it will look and feel exactly like a hard disk partition. The only difference that should be noticeable is that you cannot boot from it.

Hopefully most of you will find this one easy. It does require a little Terminal usage, but I'll step you through it.

[robg adds: I haven't tested this tip. If you do so, be careful with it, especially if you choose to later remove it -- any files not backed up from the 'partitions' will be lost when you delete them. I don't think this will work as described in Tiger, due to changes in handling diskmounting, but I'm not positive.]

Installation

  1. Open Disk Utility in your Utilities folder (inside the Applications folder).
  2. Without having any drives or volumes selected, click on the 'New Image' button. This will be your partition; choose a size accordingly. (I recommend read/write disk image, but sparse should also work)
  3. Save it as 'Partition' and save it to your Desktop
  4. Open Terminal in your Utilities folder, and type the following commands (you will be prompted for for an admin password). You can copy and paste things into the Terminal -- this will make things immensely easier.
  5. sudo mv ~/Desktop/Partition.dmg /.Partition1.dmg
    This moves the partition file you created off your desktop and makes it a hidden file. If you wish to make additional partitions, use Partition2.dmg then Partition3.dmg and so on.
  6. sudo mkdir /Library/Hooks; sudo echo "#! /bin/bash" > /Library/Hooks/MountFakePartition
    This will make a script that can be run before login. Skip this step if you have done this at least once already.
  7. sudo chmod +x /Library/Hooks/MountFakePartition
    This will make the script executable. Skip this step if you have done this at least once already.
  8. sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true
    Enable disks to be mounted without user intervention. Skip this step if you have done this at least once already.
  9. sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow LoginHook /Library/Hooks/MountFakePartition
    Have the script run right before login. Skip this step if you have done this at least once already.
  10. sudo echo "hdiutil mount /.Partition1.dmg" >>  /Library/Hooks/MountFakePartition
    This will add the mounting of the partition to the script. Change /.Partition1.dmg to whatever is necessary if this is not your first time to do this.
That's it; restart your machine, and you will have a 'partitioned' (not really) hard disk!

What's the deal? Okay, Juz10mac, you said this would look and feel like a real hard disk partition, but it doesn't look like one. The solution to this is easy, and optional:
  1. Control-click on your hard disk and choose Get Info. Click on the icon in the Get Info window then do an Edit -> Copy.
  2. Control-click on your new partition and choose Get Info. Click on the icon in the get info window then do an Edit -> Paste.
To uninstall: Warning! this will delete your created 'partitions.'

Open Terminal in your Utilities folder, and type these commands (you will be prompted for for an admin password):
$ sudo rm -f /.Partition*
$ sudo rm -f /Library/Hooks/MountFakePartion
Enjoy!

Comments (9)


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