Transferring OS X and Boot Camp to a New Hard Drive

For Christmas my brother gave me a copy of the game Portal, which required there to be about four gigabytes of available space on my hard drive. There wasn’t. In fact, every time I’ve wanted to copy a large file for the last while I’ve had to re-arrange and purge my hard drive, both in OS X and in my Boot Camp partition. It was time for a new, upgraded, hard drive, and this is how I was able to copy both my OS X partition and Boot Camp, (Windows), partitions to the new drive, and expand both partitions to fill my drive, all without re-installing any software.

The Hardware

First, the hardware. I use a Macbook Pro that dates from the summer of 2007. Until I made this change it had its factory-installed 160 GB, 5400 RPM hard drive. This was an upgrade from the standard 120 GB drive, but three and a half years later it’s no longer big enough for me. I had dedicated 32 GB to my Boot Camp partition, which with a Vista installed was very cramped, perhaps even more cramped than my OS X partition that made up the balance of the drive. I ordered a 500GB, 7200 RPM Western Digital Scorpio Black , (yes, that’s an Amazon Affiliate link), hard drive from Amazon to replace the factory-installed drive. Apparently the WD Scorpio Black uses the same amount of power as a normal 5400 RPM drive, but is faster. I’m not super concerned with power these days as my 3 1/2 year old battery doesn’t exactly hold a charge so I’m always plugged in anyway.

A note on warranties and recalls:

My laptop is in the group affected by the NVIDIA Recall, so even though my 3-year AppleCare is expired, (and it was worth it – a new mainboard and hard drive later), I am still covered for a few months if the video goes kaput. I called Apple to see if I could change my hard drive without voiding that special coverage and they said that yes, so long as there was no physical damage to the computer, I would still be covered if my video died.

My Best Way to Transfer Everything, Step by Step

Required Equipment
  • Your Mac, with the old hard drive still installed
  • Your new hard drive
  • A way to connect your new hard drive to your Mac, probably a SATA to USB connector, or an external hard drive case.
Required Software
The Steps
  1. Plug your new hard drive into your Mac, using whatever connector you have.
  2. If your Mac isn’t already on, boot from your old hard drive
  3. Using Disk Utility format your new hard drive. Select a GUID Partition table, (so you can start your computer from the drive), and, unless you’ve specifically chosen another format, OS X Case-Insensitive, Journaled, as the format. Make the partition as one single partition, (volume), that fills the whole drive. We’ll add in a Boot Camp partition later.
  4. Using SuperDuper! copy your OS X partition from your old drive to the new volume you just created on your new hard drive. Use the “Backup – all files” option in SuperDuper!
  5. Go clean the garage, or plant the garden. This will take a while. It took about four hours for me to copy about 115 Gigabytes of data
  6. When SuperDuper! is finished its business shut off your computer and disconnect everything. You’re about to take your computer apart.
  7. Find your computer on iFixit.com and make sure you have the appropriate tools. I only needed two screwdrivers, however one of them was a T6 Torx screwdriver, and the smallest I had was a T8. My father-in-law also had a T8 as his smallest. We ended up using a file to give a hexagonal screwdriver a shape closer to a Torx screwdriver.
  8. Follow the instructions on iFixit.com to replace your computer’s old hard drive with the new one that you copied OS X to in steps 4 & 5.
  9. Once everything’s connected, but before you’ve put your whole computer back together, I recommend starting up your computer to make sure everything’s connected properly. Be careful not to touch anything inside your computer when it’s running, you could hurt yourself, (or worse, your computer!), if you touch the wrong thing. Once you know the hard drive is properly connected turn off your computer again and remove the power source.
  10. Re-assemble your computer.
  11. Hook your old hard drive up to your computer the same way you had the new hard drive hooked up before you installed it.
  12. Start your computer.
  13. If you did everything right you should be running off of your new hard drive now. Check that you are running off of your new hard drive by starting finder and checking the size of your hard drive, or use Disk Utility to check the brand name of your hard drive, or just start without the old drive hooked up and connected it later.
  14. Now we’re going to move your Boot Camp partition.
    1. With the computer booted, and the old hard drive connected externally, start Boot Camp Assistant, (it’s in Applications > Utilities).
    2. Follow the wizard to create a BootCamp partition. This partition does not need to be the same size as your old Boot Camp partition. When Boot Camp Assistant asks you to insert a Windows install disk quit Boot Camp Assistant. Your partition is created.
    3. Install and run WinClone. It will probably ask you to install the NTFSProgs Binaries, which it needs to do some reading and writing to NTFS-formatted filesystems, (like Windows partitions), these seem to be safe so go ahead and install them.
    4. With WinClone you’ll first need to make a disk image, (a file that contains the whole contents of your old Boot Camp partition), then restore it to your new Boot Camp partition. So, you’ll need OS X formatted space to store this image. This could be your new hard drive if you’ve just installed a larger drive like I did, or it could be another external drive.
    5. Tell WinClone to make an image of your old Boot Camp partition. It took about 1/2 hour for me to image a 32 Gigabyte partition.
    6. Tell WinClone to “restore” the data in the disk image you just made to your new Boot Camp partition. This could take a while. Grab lunch.
    7. When WinClone is done turn off your Mac and disconnect the old hard drive.
    8. Turn on your Mac holding down the Option key on the keyboard. You should see your Boot Camp partition as a boot option, (it’s probably labeled “Windows”). Select it to boot into Windows.
    9. Windows may want to run a chkdisk. It’s probably best to let it do so. It shouldn’t take crazy long, but will probably take long enough to make a pot of coffee.
    10. After chkdisk runs and you’re booted in Windows check everything is ok.
  15. That’s it. Enjoy your new hard drive!

Notes on Backups

The first time I connected my Time Machine drive to my Mac after doing the hard drive replacement Time Machine realized that I had installed a new hard drive and did a full backup. This took a while, (especially because I accidentally pulled the USB cable out of the computer halfway through). If you’re using a Time Capsule it is a good idea to plug your computer in to the Time Capsule with an ethernet cable, not do the full backup over the air.

BackBlaze, (again, that’s an affiliate link), which I use on two computers, didn’t notice the change in disks and continued as normal. I am pretty happy about that because the initial backup with any online service can take a long time and this saved me from uploading over 60 Gigabytes of data over my DSL connection.

Notes on Fragmentation

I took the opportunity to defragment both my Windows and OS X, (I use iDefrag to defragment OS X. In reality there was very little fragmentation on either side, I think that the process of copying everything from the old disk to the new one may have essentially defragmented everything anyway.

Running my Boot Camp partition in VMWare Fusion

The first time I tried to launch my Boot Camp partition in VMWare Fusion I got an error because the Boot Camp volume had changed. It asked me to remove and re-add the virtual hard drive, which I couldn’t figure out how to do in 5 seconds, so I removed my Boot Camp partition from my Virtual Machine Library. Then to re-add it I had to click “Home” in the VM Library window and choose “Run Windows from your Boot Camp partition” on the right hand side. There’s a setup that’ll run for a few minutes, (it took less than 2 minutes for me), and the Boot Camp partition should be re-added to the VM Library.

Windows Activation

After I had my Boot Camp partition running for a while in VMWare Fusion Windows informed me that it had been deactivated due to a hardware change and I had to reactivate. I don’t know if this was only because of the remove and re-add I did to the Boot Camp virtual machine, or if it was because of the actual hard drive change. Either way Windows had to be reactivated, which is a pain since activation online never works for me anymore and I always have to activate Windows over the phone. However, it’s activated now and seems to work fine.

Conclusion

While it seems like there were a lot of steps, and copying everything around took quite a while, it was much, much easier to copy everything from my old hard drive to a new one. I didn’t have to re-install any software or any operating systems, something that I was afraid I would have to do. It’s something that can be accomplished in about a day, if you have all of the tools and equipment on hand. If you do it on the weekend then you don’t have to feel guilty about the downtime.

Test ASP.NET apps on your Mac with VMWare Fusion & DD-WRT

Today I needed to test and fix mac-specific bugs in a website that is written in ASP.NET, but I generally use a Mac. When I work on the ASP.NET site I boot into Vista using Boot Camp, and the rest of the time I spend happily in OS X. I needed a solution to run both at the same time, and on the same computer, (this is the only mac I have, but my development environment for the .NET site is on my Boot Camp partition). It was time to see if Virtualization has gotten any better. It has.

There are two reasons that virtualization is better: VMWare Fusion 3.0 was released, and I doubled up my RAM, (now at 4GB). With these two changes, and Aero turned off on the Windows side, Vista runs ok under VMWare Fusion on my ageing Macbook Pro. Now to see changes made in Vista from OS X.

The simplest way I found to make this happen was to use some of the DHCP features DD-WRT on my router to assign a static IP address to my virtual machine and to map a URL to that IP. I’ll do this in steps:

  1. Before starting your VM in VMWare, go to the settings for the VM > Network and choose “Bridged” then open the advanced section and click the button to generate a MAC address. Copy the generated MAC address.
  2. To to Services > Services in your DD-WRT web interface and in the DHCP Server box assign a static IP to the Mac address you just copied
  3. In the DNSMasq box enter the following:address=/the-url-you-want-to-map-to-the-vm/THE.IP.YOU.JUST.SET entering, of course, the real values.
  4. Hit Apply and Save at the bottom of the page
  5. Start up your VM
  6. Make sure that Windows Firewall is set up to let HTTP connections through
  7. Type the URL you created in your browser in OS X and you should get the web page served by Windows
  8. Now, there should be a way to make this work without the router, using NAT network mode for the VM and some hosts file edits in OS X. I’m going to try to figure out how, but for now I just need to get some bugs fixed in the .NET app. If anyone has any ideas how to make this happen without involving a router let me know, (or blog about it and leave a note in the comments).

Bringing my External Hard Drive Back to Life

Last Monday I wrote about restoring access to an outdated subversion repository after the hard drive in the computer that was being used as a subversion server died. That was my second hard drive failure of 2009, but at the time I thought it was the third. It turns out that what I had thought was my second failure, the failure of the external drive that I use for backup and random storage, was in fact a case failure. The drive is fine, and it is once again functional in a doctored case.

The drive in question is a 500GB Trekstor Datastation maxi m.u that I got at a boxing day sale at Future Shop a couple of years ago. As many Canadians know, when something from Future Shop dies you’re pretty much on your own to fix it, so that’s what I did. When the drive stopped working I googled it and discovered that a lot of people have had problems with the power supply to the drive. Some have been able to fix the problem with new power adapters, so I tried using an all-in-one adapter that I had, but the drive behaved as it had with its own adapter. Ever hopeful, I opened up the case and brought the drive to the in-laws’ place to test it, and when inserted into a computer it worked, so all I had to do was replace or repair my case and I would have my external hard drive back again.

I looked online at new cases, but it seemed like a waste to get a whole new case when the only thing that was broken was a small circuit board, so I found a stand-alone SATA to USB converter with no case and ordered that. When it arrived I tested it and it worked, so today I set about putting the drive back in the case, but with the new adapter. First, I removed the old electronics from the case. However, the holes that were in the back panel were not large enough for the ends of the cables of the new adapter.

The back of my hard drive case
None of the new cables will fit through these holes!

Out came the Dremel and most of the back panel was cut out to make room for cables & electronics. Once I had made the cut, cleaned up, re-mounted the drive, and re-attached the back plate, I had a good hole through which I could attach my shiny new adapter and keep the drive itself protected.

The back plate of the drive case has been removed.
That's better. I can reach through there.

My only complaint is that the USB cable on the adapter is a bit short, so I may have to get a hub or something to pretend it’s an extension able. For the moment I have just re-arranged my desk slightly.

The drive, in the case, with the new adapter attached.
The drive, in the case, with the new adapter attached.

* A note on image quality: My camera went missing a while ago, so the best I can do right now is the iSight built in to my laptop. Sorry!

How to Update an Outdated Subversion Repository from a Working Copy

Last week the hard drive on my Subversion server failed and I had to rely on my backups to bring up a new server.  My most recent backup was not 100% current, so I ended up with a Subversion repository at revision 935, but a working copy at revision 953.  This is the story of how to reconcile the working copy with the backup so that your latest work is once again in your repository, on a Mac.

First, I looked for a way to simply import my working copy, along with any version info that it might have, but that doesn’t seem to exist.  Then, I tried just committing a new revision to the repository, (it had the same URL as the one on the failed hard drive), but that lead to subversion errors.  It turns out, that if your working copy has a revision number that is higher than that in the repository, you need to check out a new working copy, then copy changes from your old working copy into your new one, the commit your changes to the new working copy.  It sounds easy enough, but there are a couple of gotchas to watch out for, like those pesky .svn folders, so here is a recipe for merging a working copy with an outdated repository, so that the repository is brought up to date:

  1. In your existing working copy, (I’ll call this the “old working copy” from now on), make sure that you’ve done an svn add for any files that are not yet under version control but you want to make the transfer.
  2. Check out a new working copy from the outdated repository, (I’ll call this the “new working copy”).
  3. On the old working copy, do an svn export.  This gets you all of your most recent files, but without any .svn folders in the mix.
  4. In Terminal copy the exported files into the new working copy by running the command cp -R exported_folder/* new-working-copy-folder
  5. [optional] Do an svn infosvn status on the new working copy.  It should show that you need to check in all of the changes you made since the repository was last updated, (or since your last backup).
  6. Commit the changes in your new working copy.   You are finished, (you might want to archive the old working copy at this point in case something didn’t work right).

Your new repository should now have the latest work in it from your working copy.  You will have lost the revision history between your latest backup and whatever you had in your working copy, but you won’t have lost it all, and you will once again be up and running and ready to code, (or write, or whatever).

Of course, you could avoid this whole hassle by making sure your backups are always up to date.

Get your Development Server Running after Upgrading to Snow Leopard

After upgrading to Snow Leopard today I tried to access my localhost versions of the websites I have under development and was met by this great message, (impatient? skip to the step-by-step solution):

Forbidden

You don’t have permission to access / on this server.

Great. I couldn’t even access http://john-mbp/ – my computer’s name, and the URL that the System Preferences’ Web Sharing pane tells me I can access. However, all is not lost.

Part 1: Get the Virtualhosts Online

The first place I looked was my httpd-vhosts.conf file, located in /var/apache2/extra, (this has not changed since 10.5), and as I suspected it had been reset to the Apache defaults, (thanks Apple). I suspected this might happen though, and had made a backup of the file, (actually, I backed up my whole hard drive, then made a separate, easier to find, copy of the file). Replacing the new httpd-vhosts.conf with the old one and doing an sudo apachectl graceful got the virtualhosts responding to requests again.

Part 2: Establish a MySQL Connection

While my virtualhosts were up and running at this point they did not have a MySQL connection. Maybe this is because my MySQL installation is from MacPorts so the socket is in a different place, or maybe not. Either way it had to be fixed.

Upon running a phpinfo(); I discovered a couple of things. First, the included version of PHP is now 5.3.0 and second, PHP was not loading any php.ini file, so I went on a php.ini hunt and found 2 files: php.ini.default and php.ini.default-5.2-previous, both located in /etc. Copying php.ini.default to /etc/php.ini and doing a sudo apachectl graceful brought my MySQL connections back online, leaving one final problem.

Part 3: Getting rid of the timezone warnings

Since I usually code with an error reporting level of E_ALL, and PHP 5.3 doesn’t seem to like not having a timezone set in the php.ini file, (it’s not set by default, at least not in Snow Leopard), I was getting a bunch of warnings whenever I used the date(); function in PHP, so, I needed to set a default timezone in php.ini. If you don’t already know the PHP name for your timezone, go to the PHP timezones page and find it, then open php.ini, (sudo vi /etc/php.ini the sudo is important), and search for “timez” to find the timezone section of the file. Now, on the line that says “;date.timezone = ” add the name of your timezone after the equals sign and remove the semicolon from the beginning of the line. Once you’ve done that, save the file, (it’s set as read-only for some reason so in vi you need to do :w! to make it save), then quit your text editor and do one more sudo apachectl graceful and you should be good to go.

Step by Step

  1. before installing, back up your computer
  2. before installing, make a copy of /etc/apache2/extra/httpd-vhosts.conf and put it somewhere safe
  3. install Snow Leopard
  4. replace the new /etc/apache2/extra/httpd-vhosts.conf with the old one you saved in step 2. If you don’t have a backup you’ll have to re-enter your virtualhosts in the new httpd-vhosts.conf file which isn’t the end of the world
  5. in Terminal type sudo apachectl graceful and enter your password if prompted to restart apache with the new configuration. Your virtualhosts should now be online
  6. rename or copy /etc/php.ini.default to /etc/php.ini (sudo cp /etc/php.ini.default /etc/php.ini)
  7. Find the name of your PHP timezone, (look on the PHP timezones page). Write it down.
  8. Edit the new php.ini file to have the correct timezone.
    1. open the new php.ini file (sudo vi /etc/php.ini)
    2. find the timezone section, (type /timez and press enter).
    3. move your cursor to the line that says “;date.timezone = ” using the arrow keys
    4. press the i key to edit the text
    5. add the name of your PHP timezone after the equals sign
    6. remove the semicolon from the beginning of the line
    7. press the escape key to stop editing the text
    8. type :w! to save the file
    9. type :q to quit the text editor
  9. One final sudo apachectl graceful and you should be back up and running.