Michael Logozar

Mac OSX DIY Fusion Drive without Re-formatting

This is a technical post not a musical one, but I thought I'd share some tips for those trying to squeeze extra performance out of their macs.

I recently have been working on reconfiguring a 2011 iMac up to function well as a music composition workstation. Many of the software instruments have very taxing requirements on I/O (hard drive speed) *and* space at the same time. For instance, Hollywood Strings require 320GB of storage space *and* very fast disks (i.e. SSD) in order to load the gigabytes of samples that might be loaded for any one patch.

My iMac came preconfigured with an internal 256GB SSD and a 1TB HD, but at the time of beginning to work on this I had only approximately 100GB free on the SSD and 500GB on the HD, and by the time I finished installing all my software instruments I only had about 200GB free on the HD.

So on first glance, I could rearrange some things and put Hollywood Strings on the HD, but it would be too slow, and I couldn't put it on the SSD at all.

I went down the path of trying out various thunderbolt enclosures to put an SSD outside of the imac, but ran into two problems:

The Problem:

1) Why dedicate an expensive SSD to a piece of software I'm only occasionally going to use?

2) Once I started testing the various options, most enclosures and hubs I tried out would only connect via thunderbolt at SATA1 or at best SATA2 speeds, limiting the I/O to a measly 120-130MB/sec which is not much better than a typical inexpensive hard drive.

The Solution:

Apple has begin shipping their newest macs with a tiered storage feature called "Fusion Drive". This is a technology that pairs an SSD (i.e. 128GB) with a HD (ie. 1TB) into a logical volume and filesystem to act as one drive. In the background, it processes and moves the most frequently accessed bits of data to the faster operating SSD. This can be considered more intelligent than an average hybrid drive or cache, and the end result is having the speed of the SSD on your most frequently accessed applications or data.

There are many postings around the internet speculating that "Fusion Drive" is really just the default built-in way that Apple's Core Storage volume management software works, and that you can create your own "Fusion Drive" on older Macs by creating a Core Storage logical volume out of two drives, listing the SSD as the primary and the HD as secondary.

jollyjinx.tumblr.com/post/34638496292/fusion-drive-on-older-macs-yes-since-apple-has
is one such example.

All of the postings I've found require either having two new drives to reformat, or to image your existing drives, wipe them out, build the "fusion drive" and then start over.

This was all too risky for me, so I decided to try take it a step further. Borrowing a page from other virtualization technologies, I decided to try building a fusion drive out of disk images instead with the intent of benefiting from the speed of my internal SSD without having to rebuild my whole machine.

I did some re-arranging of my data to free up 128GB of space on my primary internal SSD and about 800GB of space on my internal HD and proceeded to build a Fusion Drive *without* reformatting my hard drives.      Here's how I was able to accomplish a DIY Fusion Drive without reformatting my existing setup:

BEWARE: This is not an officially supported configuration. Like any process that involves data and hard drives, back up all your data before proceeding or be prepared to lose all your data if something goes wrong.   Apple may also in the future choose to block access to creating your own Fusion Drives.


1. Create your disk images:

You can use a "Sparse Bundle" or "Sparse Image" -- I chose Sparse Image because I don't want to pre-allocate all of the space, and I also don't care about time machine backing up the image files -- instead I want Time Machine to back up the resulting mounted filesystem and the files inside of it.

Inside of “Disk Utility”, select “File->New->Blank Disk Image”:



When filling out the disk image attributes, do the following:

Name: Name your SSD Disk Image File
Size: Select “Custom” and fill out the size you want. In my example, the SSD was 120GB and the HD will be 800GB
Format Mac OS Extended (Journaled)
Encryption None
Partitions Single Partition – GUID Partition Map 

** This is very important – You cannot create a core storage volume from disks (or virtual ones) that don’t have a GUID partition map.
 

Under "Image Format", I chose Sparse Disk Image (one single file that only consumes the amount of space as to what’s inside the image… it will grow up to the maximum size you specify in the Size column above)

Another option would be “Sparse Bundle” which is similar but shows up as a directory split into multiple smaller files – This is supposed to be better for backups, but I would rather exclude these images from Time Machine and point Time Machine to backup the resulting mounted filesystem instead.

When finished, click “Create”. This will create your SSD disk image file.

Once Finished, repeat the above process again for the HD disk image file.   (in my case I allocated 800GB to the HD disk image file).

At this point you should have two disk images (or sparse bundle directories).

**It is VERY important that you do two things at this point:

1) Move these disk images to the actual devices they indend to reside on. i.e. Move the SSD disk image onto the SSD drive.

2) Make sure the files are NOT owned by the ordinary user you intend to have accessing the data on this fusion drive.

i.e. “sudo chown root /path/to/SSD_120GB.sparseimage” and repeat for the HD image.

If you accidentally have a process attempt to write to the image itself you will completely corrupt your virtual Fusion Drive and have to reformat the drive and restore all data to it, doing the above will add a layer of protection to make sure only the 'root' user can write to the file directly.

By example, I had just finished installing all 700GB of my instrument data onto my new Fusion Drive when I decided to install the last item on my list who's installer decided to identify the path to the image file itself as the 'installation directory' rather than the mounted up /Volumes/AV.   As soon as it touched that disk image directly, it corrupted the whole filesystem and I had to start the entire process over.    If you protect the disk images to be owned by root, then an ordinary user or process won’t corrupt those files.

This does however mean you’ll need root/sudo access in order to mount the filesystem, but that’s a reasonable trade off for some data safety.


2. Mount the Disk Images

The next step in building your DIY Fusion Drive is to mount up the disk images.

In a terminal window, type the following, replacing the image paths with the paths to your disk images:

sudo hdiutil attach -nomount -noverify -noautofsck /SSD_120GB.sparseimage
sudo hdiutil attach -nomount -noverify -noautofsck /HD_800GB.sparseimage

You will have to type in your password unless you’ve already configured /etc/sudoers to not require a password

At this point type ‘diskutil list’ to identify the disk ID’s of your newly mounted disk images:

Find the IDENTIFIER that matches your new SSD image and your HD image:

i.e. “disk5” and “disk6” in this example:


3. Create the CoreStorage (Fusion Drive) Volume:


Be very careful here to specify the correct disk identifiers or you could overwrite your main disks and cause severe data loss.

In the above example, it would be “disk5” and “disk6”. Ideally you could run a “diskutil list” before attaching your disk images and one after to compare the difference to be certain.

Here’s the command to create the logical volume group I’m going to call “FusionDrive” – you can replace this name with any name of your choosing:
mac:~ name$ sudo diskutil cs create FusionDrive disk5 disk6

The SSD device needs to be the first one listed, as that is considered the ‘fast’ drive to move data to in Fusion Drive.

You should see something like this:

Started CoreStorage operation
Unmounting disk5
Repartitioning disk5
Unmounting disk
Creating the partition map
Rediscovering disk5
Adding disk5s2 to Logical Volume Group
Unmounting disk5
Repartitioning disk5
Unmounting disk
Creating the partition map
Rediscovering disk6
Adding disk6s2 to Logical Volume Group
Creating Core Storage Logical Volume Group
Switching disk5s2 to Core Storage
Switching disk6s2 to Core Storage
Waiting for Logical Volume Group to appear
Discovered new Logical Volume Group "092AEBE1-5170-47C1-8D59-D331B0A40D89"
Core Storage LVG UUID: 092AEBE1-5170-47C1-8D59-D331B0A40D89
Finished CoreStorage operation

Note the UUID at the end (listed in bold in this example).   That string will be needed for the next step.

Before proceeding, you can verify what the above command did by running ‘sudo diskutil cs list’ .

4. Create the Volume from the logical volume group:
In the following example, use the UUID of the Logical Volume Group, not the UUID of the “Physical Volumes” – this is the UUID listed at the end of the diskutil cs create… command

In this example, “AV” is the name of the mountpoint …. i.e. when finished you will have a useable filesystem mounted as /Volumes/AV
mac:~ name$ diskutil coreStorage createVolume 092AEBE1-5170-47C1-8D59-D331B0A40D89 jhfs+ AV 100%
Started CoreStorage operation
Waiting for Logical Volume to appear
Formatting file system for Logical Volume
Initialized /dev/rdisk5 as a 873 GB HFS Plus volume with a 73728k journal
Mounting disk
Core Storage LV UUID: 6E11B456-0388-4694-9C4D-8A4BAA37905E
Core Storage disk: disk5
Finished CoreStorage operation
 


5. Before using your new Fusion Drive, make sure it mounts up on reboot

There are lots of different ways to do this, but one way is to create a script that you can add to your “Login Items” under System Preferences->Users and Groups->(select a user)-> Login Items.

i.e. edit a file, and call it “mount_av.command” and in that file put something like this:

sudo hdiutil attach -nomount -noverify -noautofsck /Path/To/Your/SSD.sparseimage
sudo hdiutil attach -nomount -noverify -noautofsck /Volumes/Macintosh\ HD/Path/To/Your/HD.sparseimage
sudo hdiutil mountvol /dev/`diskutil list |grep "Apple_HFS AV" |awk '{print $6}'`

In the above script the 3rd line is mounting up /dev/{diskname} where {diskname} is the 6th column of the line matching “Apple_HFS AV”, when "AV" is the name of the volume you are mounting.    Manually run 'diskutil list' to identify what you should put in this line.

It’s important to not just assume the diskname is what it was the first time you saw it because if you plug in any external disks, then the ordering / disk names may change.   This is the reason for the 3rd line in the script dynamically identifying the disk name.

Running the above script will still prompt you for a password unless you edit /etc/sudoers and make your account able to execute sudo commands without a password:
 
i.e.

sudo vi /etc/sudoers and put a line for your username that looks like this:

username ALL=(ALL) NOPASSWD: ALL


6. Verify the performance of your Fusion Drive

Before putting data on your drive it's a good idea to verify that the intial writes are going to the SSD first. This can be done with a combination of benchmarking tools and the 'iostat' command.




That’s it. Once you can verify that you predictably get your Fusion Drive mounted up on reboot, and that it is reading/writing to the SSD first,  then it's time to configure backups and start installing data to your new DIY Fusion Drive.

I have yet to verify my "Fusion Drive" in operation, except to know that it filled the SSD first, then the HD when copying the files.... over time, monitoring with iostat while using my applications should show which drives are getting the reads and writes, and there are other reports on the internet that other DIY Fusion Drives are indeed reshuffling the data in the background after some use.

- Michael

P.S. If you like this article, please re-post it and also take the time to check out my music!