My way or the highway

Setup and Customize Windows XP


When you install windows, the easiest way is to just accept whatever the setup program suggests. That's the easiest way, but not necessarily the best. It is not necessarily a good idea to use one large partition, to have system, program files and user data on the same partition, to have a swap file and operating system sharing the same partition, and so on. However, as Microsoft has set the defaults this way, customizing your configuration means a lot of manual tinkering and adjusting. This is something you want to avoid, obviously.

So, would it be possible to customize a Windows XP setup in such a way that it is a bit more 'Linux-like" - e.g. with the operating system seperated from the user data, with all user data and preferences in a dedicated home directory, etc. - while at the same time making this setup reproducable ? I think it is ...

Goals

What we're aiming for is

  1. an automated setup
  2. using multiple partitions
  3. a dedicated partition for the operating system
  4. programs on a separate partition, preferably without having to specify an install path
  5. a user 'home' folder that contains all user-specific files, and located on a partition other than the system partition so the system can be re-installed without harm to the user data. This would also make it possible to migrate the user(s) to an other system/machine/ ...
  6. the ability to reproduce this setup easily

Design a partion scheme

Decide how many partitions you want to use, and how large they should be. A typical configuration would be

  1. C: operating system
  2. D: program files
  3. E: data

Sizes would depend on the size of the disk(s) and the expected volume of program and data files. The size of the C: partition should be at least 2 GB (Windows XP system requirements) - possibly a bit larger if you'll be keeping the swap file in that partition as well. Note that this 2 GB will be not enough to accomodate Program Files and user data. Also some system files (printer spool, temporary files, Windows update patches and backups of the files they've replaced will end op in this partition as well. If your harddisk is rather small and you want to save space, you'll need to make sure these temporary files and backups get deleted regularly. We will move swap, Program Files and user data to an other partition so we can keep the system partition rather minimal.

In the rest of this article, we'll assume a slightly simplified partion scheme:

C: (system)
boot- and system partition. A 5-6 GB primary partition that will hold the Windows folder and not much more
D:
the data partition : all remaining disk spaces, in which we well have a program files folder, user home folders, ... This can be either another primary partition, either a logical volume inside an extended partition.

You can create these partitions in advance, using a boot disk with partitioning tools, or do it during windows setup.You can also choose to create all partitions now, or create only the C: partion to install Windows in, and create the rest later. The latter allows you to include a 'diskpart' (disk and partition manager) script to automate the creation of additional partitions.

Set up Windows XP

Set up Windows XP as you normally would, or use an answer file for a silent install (sample answer file). Windows will be setup in C:\<windowsfolder>.

Create Partitions and Assign Drive Letters

If you haven't done so during Windows Setup, create the additional partition(s) now. At the same time, check the drive letters. You may possibly need to assign a higher letter to the CD-rom drive. See this script /commands to create partitions and assign drive letters.

Move the Swap file

You can do this from the Start Menu\Settings\Control Panel\System Advanced\Performance Options : virtual memory.

Moving (and increasing) the swap file is often discussed in performance tweaking. You'll often get the advice to use a separate disk (on a separate controller) for best performance. While this is quite true, we're assuming a simple 1 disk configuration here. IMHO, it then makes sense to have a swap file on each partition to reduce access times (disk head movement). We'll go for a rather small swap file on C: (so Windows will still boot even if the D: partition is not available) and a large (1.5 x RAM but not more than 4 GB) swap file on D:

You can set the pagefile in Computer Properties : Advanded : Performance ..., or you can use regedit : Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory management and edit the PagingFiles entry. The format is driveletter:\pagefile.sys minsize maxsize.

Editing the registry is our prefered method (against Microsoft's advice), as it will also allow us to automate (and thus reproduce) this configuration, either by using the REG command, scripts such as VBS and Kixtart, or importing reg files with the REGEDIT command.

Move Program Files

The main reason for this, as with moving pagefile (swap file), is to be able to keep the C: partition relatively small. By moving the default 'Program Files' folder away from C:, we don't need to plan for additional disk space for all future programs and we can thus limit the C: partition to something between 3 and 5 GB.

Strictly speaking, it would be sufficient to 'custom' install each and every application and indicate an install folder, but this lacks elegance and is harder to reproduce and keep maintenance low. What we want is to set the 'default' programs folders to a new location (D:\Programs), in stead of "C:\Program Files". That will also cover all tools and applications that 'just install' without asking where you want to install them.

Moving the "Program Files" folder is accomplished by changing a registry key : HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ProgramFilesDir. Insert an appropriate value, eg. D:\Programs or D:\programfiles.

Again, this is scriptable, so we're doing fine :-)

Move User Profiles

Since Windows 2000, XP, ..., Windows keeps user profiles in (default) C:\Documents and Settings\%username%\. This is more or less equivalent to the Linux/Unix $HOME directory in that it contains all user-specific files : data as well as preferences, configuration settings for applications, desktop, start menu, history and recently used files lists, etc.). The Bad Thing is that the 1 partition approach puts all this in the same partition as the operating system - apart from the space requirements (My Documents, My Music, an iTunes library, a movie collection, Internet Explorer Temporary Files, ...) this also means that a re-install of the operating system may wipe out all data and all personalized configuration.

We will avoid that by moving the "Documents and Settings" to a separate partition. This is done by modifying the following registry key : HKEY_LOCAL_MACHINE \ SOFTWARE\ Microsoft\ Windows NT \ CurrentVersion \ ProfileList. Insert an appropriate value, eg. D:\home or D:\userprofiles.

Avoid Windows activation

Reinstalling Windows XP from scratch requires reactivation - and you can only activate windows XP 3 times without having to call Microsoft and explain why you need a new activation key. If you install Windows XP on the same system, you can avoid the activation by restoring C:\Windows\System32\WPA.DBL from the old system. Of course, you will have had to keep a copy before you re-install. So why not do it immediately after you've set up Windows and activated it ? In your subsequent installs, you can copy this file back to the system folder.

see http://www.theregister.co.uk/2001/07/23/winxp_product_activation_cracked_totally/ and http://www.extremetech.com/article2/0,1697,554872,00.asp for background on how much hardware you can replace before Windows XP wants to re-activated again.

Keep it Tidy

When you've moved C:\Program Files, C:\Documents and Settings, ... you may have some leftover files and subdirectories in the old location. Make sure there's a copy in the new location, then remove the old ones. To copy, we use XCOPY because it allows to preserve ownerschip and ACL's of files and directories when they've been copied.

Note that, for the new locations, we're using file and directory names without spaces. Names without spaces are far more easy to use in scripts, so why not make our lifes easy ?

automatically reproduce it

When you've set things up as described here, you should be able to wipe the system partition and reinstall it. With a script such as the following (a copy of which you could keep on the data partition - e.g. D:\setup\...) you can re-create the configuration. You will still need to install the applications again (can be scripted as well - see automatic software deplouyement), but they'll take the settings that you still have stored safely in D:\home\%username%\Application Data, so all preferences and options you used to have, will be restored.

The changes we've made have quite some impact on the system and will only take effect after a reboot. The script could use the reboot command from Windows Support Tools.

	@echo OFF
	REM Koen Noens, October 2006
	REM Customize a Windows XP configuration
	REM ============================================================
	REM

	REM using REG to edit registry. Win XP REG has no update command, use add and confirm overwrite with echo Y
	REM also note use of \0 as 'end of string' character i.e. delimiter for MULTI_SZ values

	ECHO setting swap file
	ECHO Y| REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory management" /v PagingFiles /t REG_MULTI_SZ /d "C:\pagefile.sys 256 256\0D:\pagefile.sys 1024 2048"

	ECHO.
	ECHO moving program files
	ECHO Y| REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\" /v ProgramFilesDir /t REG_SZ /d "d:\programs"
	XCOPY "c:\Program Files" d:\programs\ /E /C /H /O


	ECHO.
	ECHO moving user profiles
	ECHO Y| REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfilesDirectory /t REG_EXPAND_SZ /d "d:\home"
	XCOPY "c:\Documents And Settings" d:\home\ /E /C /H /O


	ECHO.
	REM if there is a backup of wpa.dpl, we avoid having to activate windows after a new setup by copying tha wpa.dpl
	if exist d:\setup\wpa.dpl (
			ECHO restore Windows Product Activation
			copy d:\setup\wpa.*  %systemroot%\system32\ 
	)

	REM if there is no copy of WPA yet, we better keep one.
	if not exist d:\setup\NUL (
			ECHO backing up WPA
			md d:\setup
			copy %systemroot%\system32\wpa.* d:\setup\ 
	)

	ECHO.
	ECHO.
	ECHO. you need to reboot now for changes to take effect.
	ECHO.
	ECHO.
	

Can I do this on a Linux system as well ?

yes and No. You don't have to do anything like this, because Linux is designed to handle this in it's own (Unix) way.

While a Windows file system starts at a drive letter, and therefor the paths are defined by the partitions, Linux works the other way around : you mount partitions in a unified file system. So you can use e.g. a separate partition for /home (all user settings and data), and each user will have his own /home/<username> directory, containing all user data ad user-specific configuration, on this partition. The design of the operating system and the filesystem is such that this can be accomplished without having to wory about drive letters and without thinkering in a registry or any other configuration file than the file system table, or fstab, which decribes the partitioning scheme).

Linux uses swap partitions in stead of swap (page) files, so this too is managed when setting up partitions. And Product activation ... ah, wel ... you know ...

No wonder some people consider Linux superior to Windows, at least from a system administrator's perspective


Koen Noens
October 2006