You can kill the background for speed, if you wish.[x]

Monday, July 9, 2007

Moving or Changing your Documents and Settings and Program Files directories to a different partition on Windows XP

Otherwise known as "The next installment of my installation saga, tuned to search engine hits".

Well, I had this big fancy walkthrough on how to do this during the Windows install so it would be nice and clean and easy. And it would have been - but I couldn't get it to work. I may have been more successful if I had a floppy drive, but I don't. So I had to do it the messy way - which actually ended up pretty clean in the long run. Here's about how it went down.

First, I installed Windows XP normally - plain vanilla, standard install. The key to doing things the 'messy' way is to install as little as possible before you go around messing with things. I would highly reccommend grabbing John Haller's portable apps suite, putting it on your flash drive, and running what you need off of that (for example, Portable Firefox to bring up this blog, or any how-to pages or downloads). I made the mistake of installing Firefox and my wireless driver first - which caused some annoying problems, especially the Intel wireless, which I'll go into down below.

Firstly, if your wireless doesn't work becuase of a driver, I would reccommend plugging into ethernet somewhere for now. If your LAN port doesn't work (unlikely), use another computer to pull up the how-to pages. Copy any needed files over on a flash drive. Once again, the key here is to avoid adding ANYTHING to your computer until after you get this taken care of. A squeaky-clean windows install is what you want.

I started with a nice post over at WinForums that, while I'll be doing most of the replacing myself, gives a nice procedure on when to do it. Oh, and to do the replacing, you'll need either a lot of free time and a good measure of masochist tendencies, or a registry-replace program. I'd reccomend going with the second option. I used RegReplace, a C++ freeware program. I don't know of its merits versus other programs available, but it worked fine for my purposes. Don't let its command line interface scare you away, it's very simple.

So, to get this thing started, follow the first few steps on the WinForums post:

  1. Login as administrator

  2. Create a backup copy of your registry - this is very important, you can screw up all kinds of stuff messing with your registry, and you'll need a backup in case you do. To do so, go Start->Run (Windows Key+R) and type 'regedit'. Click on "My Computer" and select File->Export. Save it somewhere safe, preferably off-disk, such as a flash drive. it will be somewhat large, my fresh Windows install was about 25MB, yours will probably be similar. Just make sure it's somewhere around there.

  3. Create a new user (Start->Control Panel->User Accounts) as an administrator, call him (or her) "temp" - you won't need the account for long.

  4. Log out of Administrator

  5. Log in as temp

  6. Create your target folders - I did it the hard way and renamed my folders as well, so I'll be using D:\ProgDir for Program Files and D:\Profiles for Documents and Settings. You can use whatever you like. Just replace any mention of D:\ProgDir and D:\Profiles with whatever you chose. In any event, you'll need to create them wherever they belong - I went to D:\ and just created a couple folders and named them ProgDir and Profiles.

  7. Now it's time to get our hands dirty. Bring up a command prompt and cd to the location that you downloaded regreplace.exe. For example, if it's on your flash drive at E:\Downloads, you would do something like the following:
    C:\Documents and Settings\temp\>E:
    E:\>cd Downloads

    Now, time to run the regreplace. You specify what to search for by adding /S "String to find" after the exe, and /R "String to replace with" after that. For example:
    E:\Downloads>regreplace.exe /S "C:\Documents and Settings" /R "D:\Profiles"
    E:\Downloads>regreplace.exe /S "%systemdrive%\Documents and Settings" /R "D:\Profiles"
    E:\Downloads>regreplace.exe /S "C:\Program Files" /R "D:\ProgDir"

    Now, there will be a bunch of status messages between those letting you know that it's replacing stuff. That's just fine - let it do its thing. There are a few things we did here:

    • Replaced references to C:\Documents and Settings with our new path (D:\Profiles in my case)

    • Replaced references to C:\Program Files with our new path (D:\ProgDir in my case)

    • Most strangely, replaced references to %systemdrive\Documents and Settings with our new path (D:\Profiles in my case). %systemdrive% is an environment variable that contains the drive that the Windows dir is on. Environment variables are basically placeholders that can be used all over the system for various often-used paths, like the system drive.

  8. Now that we've done most of the dirty work (that wasn't so hard, was it?), we need to go smooth out some rough edges. For instance, regreplace only replaces string values - not keys or other random things. So you'll have to do a little manual search-and-replace, but not too much. Also it's good to make sure that we got everything. But first, the next couple steps on WinForums.

    you will see 2 SIDs at the bottom of that key similar to the following...

    \\REGISTRY\\USER\\S-1-5-21-602162358-616249376-839522115-1001"="\\Device\\HarddiskVolume2\\Documents and Settings\\temp\\NTUSER.DAT"

    "\\REGISTRY\\USER\\S-1-5-21-602162358-616249376-839522115-1001_Classes"="\\Device\\HarddiskVolume2\\Document s and Settings\\temp\\Local Settings\\Application Data\\Microsoft\\Windows\\UsrClass.dat"

    See that number after "HarddiskVolume"? It may not be 2, it might be 1 or 3 or 17 (unlikely). Whatever it is, take whatever drive letter you want your directories to be on (D), count how many letters away from the drive it's on now (C), and add it. So if it's 2 right now, and you're moving from C to D, that's 1 away - meaning HarddiskVolume3 would be your new label.

  10. Now copy the folders (except the temp user folder and all users folder) from C:\documents and settings\ to where you want it (D:\Profiles here).

  11. Go ahead and search for "Documents and Settings" and "Program Files", replacing any wrongly-pointing entries to your new location (D:\Profiles, D:\ProgDir) by hand. In a fresh install, there shouldn't be many left.

  12. Do a reboot - a complete reboot is always best when you're working with the registry, I've found. When it comes back up, log in as Adminsitrator.

  13. Try to copy the All Users folder (inside Documents and Settings) over to the D: drive and rename (or delete) the C:\Documents and Settings. If succesful, You're done, otherwise, you may have to wrestle a bit.

  14. If you have problems, you can just try finding and replacing any wrongly pointing entries manually again and rebooting, or try booting into safe mode - whatever you can do to get the settings to stick. In my case, I had my wifi driver running, and I had to go uninstall it (which was a pain), make sure it wasn't trying to boot up with Windows, and finally get rid of the folders on the C:\ drive.

If things went (somewhat) well, you should in the end only have a WINDOWS folder in your C:\ drive, and all your programs and data should be on the D:\ drive (or wherever you chose). New programs should install there by default, and it will be quite better for backup purposes and just a lot cleaner. You may still have some shortcuts and such on your hard drive pointing to your folders that were in the C:\ drive - I used the free ReplaceEm to root out and fix these various pointers.

So I scoured the web for a while, trying to figure out how to easily change program files and documents and settings to my data partition. There are all kinds of ways to do it, I found, but the easiest way I found just takes a USB Flash drive, an overly large (predictably, being HP) download - forty-some megabytes - and a computer to reinstall Windows on. Yes, I said reinstall - since I'm doing just that, and it's infinitely easier to do it this way, that's how I'm going to do it. Not keen on reinstalling Windows? Then keep Googling away, cause I won't be of any help.

So, thanks to the helpful folks over at WinForums, I've compiled a step-by-step guide to moving your docs and settings and program files folders to a separate partition. Here goes.

Stage 1: Preparation of Boot Media

Not as scary as it sounds, just getting a boot USB stick (easy) or floppy (dead easy) ready.

  1. First of all, if your computer has a floppy drive, then download and run the DOS 6.22 boot disk installer, and skip to stage 2. Since most computers nowadays don't have one (thanks, Dell), you'll probably have to find a flash drive that you're willing to part with the contents of, at least temporarily. Smaller ones are better, since they'll have less data to backup, but anything will do. If you don't have one, go pick one of those 32MB sticks out of the candy jar at staples for $5. If they don't have them, you can get a 512MB stick for $10, in cute pink or slightly less effeminate blue, or a more functional 256MB stick. Whatever you choose, be ready to part with and/or back up the data that's on it.

  2. Hop on over to National Instruments where they have a nice tutorial on how to

  3. Hop over to HP's website (thanks to Damien Stolarz over at O'Reilly for the tip) and download their Bootable UFD utility. While you're at it, stroll on over to (a very helpful site) and grab the zipped DOS 6.22 floppy image - you'll need it for HP's wizard to work.

  4. Unzip the image you downloaded to a place of your choosing, and run the installer for the HP utility. You'll then have an "HP System Tools" folder in your start menu - find it and run the DriveKey Boot Utility.

  5. Pick your drive letter, choose "Create New or Replace Existing Configuration" (check the Backup box if you need to - but a warning, it didn't seem to work for me and I'd already backed up my flash drive with John Haller's excellent backup utility, so I didn't worry about it.)

  6. Choose the "Floppy Disk" option, and then select "Image from File". Browse to where you unzipped your DOS 6.22 zip that you downloaded earlier, and select the "622c.img" file.

  7. Click "Finish", and then unplug the flash drive.

Stage 2 - Installing Windows

  1. First, a little prep - plug the flash drive back in or put your floppy in, and paste the following into Notepad. Both sections are optional, and you need to replace "E:\Program Files" and "E:\Documents and Settings" with wherever you want your directories, of course.

  2. [Unattended]
    ProgramFilesDir="E:\Program Files\" ;Program Files
    CommonProgramFilesDir="E:\Program Files\Common\"

    ProfilesDir="E:\Documents and Settings\";Documents and Settings

  3. Now save that as UNATTEND.TXT to your boot disk (USB or floppy)

  4. Put your boot disk into the target computer and turn it on. You may have to press F2 or Delete or F8 or the Anykey or something to get it to boot from your boot disk.

  5. If all goes well, you should boot into a DOS prompt. Make sure your Windows CD is in the drive, and type the following, where D is your CD drive lettter:

  6. D:\i386\winnt /u:[UNATTEND.TXT path] /s:D:\i386

  7. Continue installing Windows as normal. It'll be slower, but in the end it'll be just how you want it.

Well, that's about it. Let me know if you have any questions or problems, and I'll do my best to dig up some solutions and answers (respectively).

No comments: