Sunday, November 11, 2012

How I Installed a 2012 Fusion Drive In My 2009 Macbook Pro

About 2 Weeks ago, Apple announced Fusion Drive in their new line of 2012 iMacs and Mac-Minis. The first thing I thought about after hearing about this, is that I'd like to try and incorporate the same ability in my 2009 Macbook Pro.
For anybody willing to try this out, I should warn in advance that this is obviously unsupported by Apple, so beware since YMMV. Also, it's not quite certain yet if it behaves exactly as advertised. If you're anything like me, this warning means little to nothing to you, and you may want to go ahead anyway.

And that's just what I did.

A few weeks ago a dear friend (@avihut) left the company and the team I work at, In order to focus on his studies. When he left, I inherited his 2009 13 inch Macbook Pro. And an old and trusty beast it is.

Ever since, I've been working at both adapting to the Mac world, and at the optimization of my new/old MBP - bringing it up to date, getting as much as I could out of it. One of the first things I did was to replace its HDD with a SSD. It is quite modest in size (only 80GB), but it's what I could get my hands on at my workplace, and it gave me a significant performance boost. The HDD I took out, I reassigned as an external USB drive. But that's not quite what I was looking for...

So when Apple came out with their announcement of the new Fusion Drive included with new iMacs and Mac-Minis, I was quite intrigued. This didn't seem like an hybrid drive, containing both Flash storage and spinning disks in the same piece of hardware. They said you could choose between 1TB and 3TB, which sounded to me like some implementation of a logical volume built out of one SSD and one HDD. But is it some kind of hardware RAID feature built into new iMacs?

Nope. As blogger jollyjinx soon found out, this is a software feature of Mountain Lion (namely 10.8.2), and can be achieved on older Macs as well. He was so kind as to also post instructions and perform some tests. Turns out it's also block-level optimized, as opposed to file-level. Awesome! This means large files don't have to be copied wholly between physical drives, but specific more frequently accessed blocks in a file will be moved to the faster SSD for better performance.
However, I have a Macbook Pro with room for only one drive. In order to create a Fusion Drive, you need two physical disks, and I wasn't about to walk around with a USB drive tethered to my MBP, slowing things down.

So I set myself a few mission objectives:
  • Find a way to get another HDD inside my MBP
  • Follow Jollyjinx's instructions on creating a Fusion Drive with the SSD and HDD
  • Install OS X on my new Fusion Drive
  • Have my Mac all set up, configured and ready to go, as if nothing happened
Fauxptibay + HDD
The first objective was surprisingly easy to accomplish. The optical drive inside computers has become rather unnecessary in the last few years. We can do anything (including booting and installing stuff) either online, or with USB flash drives. A few companies picked up on that and are offering a kit to replace the optical drives in MBPs with another HDD bay. One of these products is named OptiBay but at 50$ it's quite pricey. You can also purchase an enclosure for your removed optical drive at 29$ more.

Naaah, I'll go the Ebay way. I found one of many cheap OptiBay knock-offs for 10$ (I dub thee 'Fauxptibay'!), and using iFixit's optical drive replacement instructions, I installed it along with my Mac's original 250GB* HDD in no time.

One Mac - 2 Disks
* I ended up swapping this 250GB 5400rpm drive for a faster, larger 320GB 7200rpm drive.

Now, on to the next three objectives - creating a Fusion Drive and installing OS X on it, without losing my setup. There are 2 ways to go about it:
  1. Restore my current setup to an external HDD -> Boot from it -> Create the Fusion Drive -> Install a fresh copy of OS X using the Mountain Lion Installer -> Restore from the external HDD to the new OS X instance running from the Fusion Drive (as described here)
  2. Backup to TimeMachine -> Create Bootable USB Flash -> Boot from it -> Create the Fusion Drive -> Install a fresh copy of OS X -> Restore from TimeMachine
Since I already had an up-to-date TimeMachine backup, I opted for the second option.
It's important to note that it seems you need a OS X 10.8.2 bootable USB installer in order to create the Fusion Drive, since older versions don't have that ability. Luckily, if you bought Mountain Lion from the Mac AppStore, the installer app gets updated automatically to 10.8.2 and you can create a 10.8.2 bootable USB version.
Fusion Drive in diskutil

Once I booted from the 10.8.2 USB installer, it was just a matter of firing up the Terminal, and following the instructions in jollyjinx's article. Using diskutil, I created a new Logical Volume Group, and within it created a new Logical Partition.

When this was done, I quit Terminal, went back to the OS X installation, and chose my new Fusion Drive as the installation destination. Once the installation was finished (about 30 min incl. reboots), My fresh Mountain Lion installation came back up. I restored from Time Machine, and 30 min later I was back to my old setup - except now on Fusion Drive.

2009 Macbook Pro + 2012 Fusion Drive

Overall, this was pretty straight forward. I haven't tested performance yet, but hopefully this was worth it and I'll see some improvement soon.

I'll be sure to let you know!

Thursday, November 1, 2012

Exploiting Python Features Vs. Employing Python Hacks

Every programming language has its quirks and dark alleys, which may be useful from time to time in order to achieve certain results. But when does using one of these features turns it into a hack?

A few days ago, I found myself having to solve a problem, and for some unexplained reason I went about it in a more 'interesting' way than one usually would (which doesn't mean more efficient). The way I solved this problem was such an amusement for me, that I felt the urge to go to the next room down the corridor, and tell Alon and Shahar all about it.

All hell broke loose.
At some point, Shahar became so horrified, he had to pull the "Zen of Python" manifesto on me (He was right, by the way).