Migrate Windows 8.1 from an HDD to a smaller SSD

Over the last couple days I’ve fought to migrate my desktop computer operating systems to a new SSD, without reinstalling anything. I have a multiboot system containing partitions for Windows 8.1, Linux, and OS X, across two hard drives. Linux and OS X gave me no trouble, but Windows proved particularly hard to move and get working again, so I’ve made some notes here in case they can help someone else (or future me) down the road — not a total step-by-step, but an outline an experienced administrator could follow.

First, some notes on my particular situation:

  • The new SSD (240GB) is smaller than the old HDDs (500GB + 80GB), so all partitions need to be shrunk to fit.
  • My original Windows installation included a separate boot partition which preceded the main partition. In a perhaps-misguided effort to simplify things, I opted to omit the boot partition from the new disk.
  • This system has a BIOS, not UEFI, so I will be using an MBR partition table on the SSD rather than the more modern GPT.
  • Windows is on the first partition, and this should be known as C:.
  • GRUB is installed to the MBR and used to boot all three OSes.

Now, to the actual process:

I started off in Linux (Ubuntu, FWIW) to resize and copy the Windows partition.

  1. Use GParted or another tool to partition the SSD. Mark the Windows partition as boot/active.
  2. Resize (shrink) the old partition so it’s small enough to be copied to the target
    ntfsresize --size <size> <source_device>
  3. Copy data to the new partition
    ntfsclone --overwrite <target_device> <source_device>
    ntfsresize <target_device>
  4. Use testdisk to rebuild the NTFS boot sector with the new partition offset. I don’t know why the partition has to know about its own position, but that’s NTFS for ya.

Next, boot to a Windows 8.1 install/recovery USB drive and enter recovery mode. Under advanced troubleshooting, start a command prompt.

  1. Check the disk for consistency. The resize operation has already marked the volume for a check anyway.
    chkdsk /f c:
  2. Rebuild the bootloader to take the place of the old boot partition
    c:
    bcdboot c:\windows /s c:
    bootrec /rebuildbcd

If you stop here, where I was stuck for a long time, Windows will boot but will not show your lock-screen wallpaper and won’t load anything after you log in. There’s one more step which I didn’t discover until I poked around the registry and stumbled across the magic key:

  1. Clear stored drive addresses
    reg load HKLM\TempSystem C:\Windows\system32\config\SYSTEM
    reg delete HKLM\TempSystem\MountedDevices /va
    reg unload HKLM\TempSystem

And that’s it! If I remembered everything during this brain-dump writeup, your resized-and-moved Windows installation should now be able to boot from the SSD (with GRUB’s help). Two evenings’ worth of struggle condensed into a short list.

I read far too many articles and forum posts along the way to have kept track of all the sources that helped me. Although I’m grateful to all of the authors, unfortunately I can’t give proper credit where it’s due; I can only hope that by posting this, I can partially return the favor.

Good luck!

Deploy CakePHP on Heroku

Heroku’s not just for Rails anymore, folks. If you’re more PHP-inclined and lean toward frameworks such as CakePHP, you might enjoy trying Heroku’s current Celadon Cedar stack as your platform.

Here I’ll step through the Blog Tutorial in the the CakePHP Cookbook, with the few extra steps needed to get it running on Heroku. As prerequisites, you should be familiar with this tutorial in its generic form, and with the basics of using Heroku.
Continue reading Deploy CakePHP on Heroku

vshadow.exe can’t be run under WOW64

I use the Microsoft-provided vshadow.exe tool to script some backups, but I got an error when trying to run it on a Windows 7 x64 machine:

ERROR: COM call "m_pVssObject->InitializeForBackup()" failed.
- Returned HRESULT = 0x80042302
- Error text:
- Please re-run VSHADOW.EXE with the /tracing option to get more details

That error is obviously unexplanatory, but some investigation led me to deduce that you can’t run the 32-bit version of the tool on a 64-bit version of Windows. The fix is to download the Windows 7 SDK, install the “Developer tools” portion, and dig the 64-bit version of the tool out from %ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\x64\vsstools\vshadow.exe.

If you were Googling that error code, I just saved you some time. You’re welcome.

Styling WordPress 2.7 author comments

Note: this site no longer uses the native WordPress commenting functionality, so the feature described below can’t be seen here.

Styling post author or registered user comments on your WordPress 2.7 blog is much easier than it was back in ol’ 2.6. The new wp_list_comments() template tag (or comment_class() if you’re doing it the hard way) automatically includes class names like byuser and bypostauthor for easy CSS styling. Slick.

See the official 2.7 theme migration guide for more details.