Tuesday, August 25, 2009

Booting Windows XP from a USB Flash Drive

I was trying to install Ubuntu 9.04 (Jaunty Jackalope) without also installing Windows on a laptop computer. That is, for purposes of simplicity in ongoing operations (e.g., avoiding GRUB problems), I was trying to avoid making it a dual-boot machine. I found, however, that I also needed to run some Windows programs on the laptop (e.g., to update its firmware). The question confronting me was whether I could run those programs by booting the machine from a Windows installation on a USB flash drive (as distinct from a normal Windows installation on the computer's hard drive). There seemed to be quite a few different options along these lines. For example, wimb_2 offered a guide to creating a multiboot USB stick that could boot DOS, Windows XP, Syslinux, and other operating systems. El-saabi's guide to putting WinXP on a stick used a 2GB flash drive. El-saabi also provided guides for creating a flash drive capable of installing WinXP and a DOS boot flash drive. There are options in other operating systems (e.g., Penlinux). You can buy a ready-made Flashboot USB drive. As another example, Björn Fröhlecke posted a how-to on Tom's Hardware describing how to create a bootable Windows XP flash drive, with helpful details on many points. There are many other examples.
* * * * *
The first guide I decided to follow was the one that Fred Langa published in an article in Information Week. Here is how I applied what Fred advised:
  • This will only work on a USB drive between 256MB and 2GB in size. Also, a 256MB drive may not hold all of the add-ons you may decide to include in this device.
  • Make sure the BIOS in the machine you want to boot can boot from a USB drive. This can require you to check several locations. A BIOS upgrade may be needed.
  • Create C:\Temp if it doesn't exist. Get rid of anything that is already in C:\Temp. Download Windows 2003 SP1 (32-bit version) (329MB). Move it to C:\Temp.
  • Open the WinXP command line in C:\Temp (i.e., Start > Run > cmd > OK). On the command line, type "c:" and then "cd \Temp." (Here, and always in this post, don't type the quotation marks or the ending period unless otherwise indicated.) Type the name of that SP1 download and then "-x." Example: "WindowsServer2003-KB889101-SP1-x86-ENU.exe -x." Hit Enter. Let it extract to C:\Temp.
  • Download BartPE Builder to destination folder C:\Temp\BartPE. Run BartPE Builder. You can let it get itself organized while you continue with the following steps.
  • Create a subfolder called C:\Temp\BartPE\srsp1.
  • Copy setupldr.bin and ramdisk.sy_ from C:\Temp\i386 to C:\Temp\BartPE\srsp1.
  • On the command line, use the "cd" command to navigate to C:\Temp\BartPE\srsp1. Type "expand -r ramdisk.sy_." Delete ramdisk.sy_.
  • Go back to the BartPE Builder program. Click OK, leave its default settings as-is, and click Build. When it's finished, click Close and Exit.
  • Plug in your USB drive. Look at Windows Explorer to see which drive letter is assigned to the USB drive. In my case, the letter was J.
  • On the command line, navigate to C:\Temp\BartPE. Type "pe2usb -f J:" (replacing J with the drive letter for your USB drive).
  • Eject the USB drive from the computer. Plug it into the computer you want to boot from USB. Boot that computer.

The resulting USB stick didn't work, unfortunately. To clarify: it might have been fine for booting a machine that was not as screwed-up as my laptop appeared to be. I did not test it on a normal machine. It just did not work for my purposes.

Meanwhile, I had come across some pages describing other approaches, and went partway through their process. Here are some notes from that. Their first instruction was to find DOS system files. I used DOS 6.22. That particular download came in .exe format (boot622.exe). When I ran it, it looked for a floppy drive to install itself onto. I didn't have a floppy drive, so I used a virtual floppy drive creator program named Virtual Floppy Drive (VFD). But I couldn't get VFD to see the virtual floppy drive as drive A, so it didn't function as a substitute for drive A. Then download the HP USB Disk Storage Format Tool. If the download is in .rar or other compressed format, extract the .exe file. El-saabi used a file called HPusbUtil.exe. I didn't preserve the original name of the one I used, but it was 2026KB in size. Install the HP USB Disk Storage Format Tool. (That's as far as I got before taking a whole new approach, as described below.)

* * * * *

On the second attempt, I decided to try el-saabi's guide for creating a USB flash drive capable of installing WinXP. This guide had been created within the past eight months, by someone who described himself as a senior software developer, so I thought it might be worth trying. It didn't work on my screwed-up laptop either; but, again for posterity, the steps in his process were as follows:
  1. On a computer running Windows (not necessarily the one where you will be installing Windows XP from a USB stick), open Windows Explorer (not Internet Explorer). Plug a USB flash drive into that computer and make sure it shows up in Windows Explorer. (I used a 4GB SanDisk USB jump drive.) If Windows needs to reboot in order to "Finish installing devices," do that.
  2. In Windows Explorer, create a new folder called C:\bootusbxp.
  3. Download PeToUSB 3.0.0.7 and usb_prep8 and bootsect from a safe location (e.g., 2shared.com) and move them to C:\bootusbxp.
  4. Unzip each of these three downloads. (To unzip, right-click on the file in Windows Explorer and choose Extract All.) So now you have folders called C:\bootusbxp\PeToUSB_3.0.0.7, C:\bootusbxp\usb_prep8, and C:\bootusbxp\bootsect.
  5. If the unzip created redundant nested folders, eliminate the redundancy. So, for example, if unzipping usb_prep8 gave you a folder called C:\bootusbxp\usb_prep8\usb_prep8 that contains a bunch of files, move those files up one level so that they are at C:\bootusbxp\usb_prep8\. In that example, you should now have a file whose full pathname is C:\bootusbxp\usb_prep8\boot.ini.
  6. Move C:\bootusbxp\PeToUSB_3.0.0.7\PeToUSB.exe so that it is now C:\bootusbxp\usb_prep8\PeToUSB.exe.
  7. Run C:\bootusbxp\usb_prep8\usb_prep8.cmd. To run an executable file (e.g., .cmd, .exe, .bat) in Windows Explorer, hit Enter when it is selected, or double-click on it. This opens a black-and-white command window. Press any key to start PeToUSB. Make sure your target USB flash drive is designated. Click Start to format it. Leave PeToUSB up and running for now - that is, don't close it.
  8. Open a WinXP command window (Start > Run > cmd). In that window, navigate to C:\bootusbxp\bootsect. (To do that, type C: and hit Enter; then type "cd \bootusbxp\bootsect" and hit Enter.) Type "bootsect.exe /nt52 G:" (replacing G with the actual letter for your jump drive as shown in Windows Explorer) and hit Enter. You should get a "successfully updated" message. Close the command window. Now close the PeToUSB program window, but not the command window that it was opened from.
  9. Insert your Windows XP installation CD. If it autostarts, kill that. Look at the command window that remains open. It should show a menu of options labeled "Prepares Windows XP LocalSource for Copy to USB-Drive."
  10. From that menu, choose option 1, "Change USB Setup Source Path." Browse to your Windows XP CD and click OK.
  11. Now choose option 3, "Change Target USB-Drive Letter." Type the letter of your USB drive.
  12. Now choose option 4, "Make New Tempimage with XL LocalSource and Copy to USB-Drive." When asked, proceed with format. In this process, there will be a few times when you will again have to press a key or click a button to continue. Altogether, this stage takes around 15 minutes.
  13. Say Yes to the questions about "Preferred Boot Drive U:" and "Unmount the Virtual Drive." Press any key (a couple of times) to close the command window.
Steps 1-6 seemed to involve a one-time setup. That is, it appeared possible to program a number of additional bootable USB flash drives by repeating steps 7-13, which could be done quickly. To test that, I did use those last seven steps to set up another USB jump drive, this time on a generic 2GB flash drive. Once that was done, I moved the jump drive over to the computer I wanted to boot from USB. I started that computer. When given a choice between GUI or TXT mode, I chose TXT mode, and that gave me the familiar WinXP Recovery Console. Upon continuing with the process to install Windows XP, though, I got this error message:
Windows could not start because the following file is missing or corrupt: [Windows root]\system32\hal.dll. Please re-install a copy of the above file.
This appeared to be a common problem for bootable WinXP USB flash drives. An old Microsoft webpage suggested that this might result from an error in the boot.ini file, but that error did not seem to exist here.
* * * * *
Trying a third approach, I downloaded WinSetupFromUSB. With guidance from installation instructions that seemed to be intended for a somewhat older version of WinSetupFromUSB, I took the following steps:
  1. Copy the entire contents of a Windows XP installation CD (ideally, one that includes Service Pack 3) to a new folder called C:\WINXPCD.
  2. Plug in the USB flash drive you want to use as your bootable WinXP flash drive.
  3. Install WinSetupFromUSB to its default location C:\WinSetupFromUSB. When installation finishes, start WinSetupFromUSB.
  4. In WinSetupFromUSB, use the Browse button to select C:\WINXPCD. Click Refresh to make sure WinSetupFromUSB recognizes your USB drive. This may give you an error message, such as "Warning! You should not be using FAT16 on partitions > 2GB!" I got this error message even when using a USB drive that Windows Explorer > Properties reported as being only 1.97GB. To change the format and choose which formatting tool to use, click on the Format USB Disk > RMPrepUSB button. For that particular USB drive, I chose the FAT32 filesystem and the XP Bootable [NTLDR] boot option, with no Overrides checked. Then I clicked on the Prepare Drive button; and after that was done, I clicked Exit.
  5. That put me back at the WinSetupFromUSB window. There, I clicked the GO button. This gave me a "Could not install GRUB4DOS bootsector" error. The error message indicated that it would try an alternative; I was not able to catch its details in time to record them here. Possibly I should have used FAT16 rather than FAT32 after all. But anyway, the process ran.
  6. When the WinSetupFromUSB process was complete, I got a dialog asking me to agree to the license terms. Next was a dialog that said, "This is important! Keep the USB disk plugged in AND start from USB 2 times - Text mode and GUI mode parts. When the GUI mode (the graphical part) is completed you should be safe to start from internal disk." It seemed that I might not have done this correctly in el-saabi's procedure (above).
  7. Although that warning did not explicitly allow me to move the USB drive from the computer where I had been programming it to where I intended to use it, that was obviously necessary, so I did that and then tried to follow the instructions just quoted. But in this version of the USB drive, I didn't get the same kind of menu as with el-saabi's method (above). Instead, I got a GRUB4DOS menu with only one option: "Windows XP/2000/2003 Setup - First and Second Parts." Ah, but then, when I hit Enter, it gave me a list with the first part and then the second part, and when I did nothing it seemed to default to the first part. That gave me the WinXP Professional Setup. I hit Enter to "set up Windows XP now." It said, as before, that it recognized no mass storage devices. I hit Enter again. This time, that gave me the Windows license screen. I hit F8 to agree. Now I was again given an option to install WinXP on the USB drive - which, of course, I did not wnat to do. I saw no alternative but to hit F3 to quit. The system again gave me the GRUB4DOS menu; and when I did nothing, it defaulted into the Second Part of the setup. Again, though, it gave me the "Windows could not start because the following file is missing or corrupt" error.
* * * * *
About this time, I came across one possible explanation for the failures of these several methods for creating a bootable WinXP USB flash drive. When I had obtained this laptop, it had come with a factory-installed recovery partition. I had wanted a clean drive and a Windows XP system. So I had wiped off all partitions - or so I thought - using a Gparted CD. But My Digital Life said that the factory-installed hidden partition could evade detection and removal even by advanced third-party disk partitioning programs. In response, one kludge solution would have been to leave such a partition in place, but edit boot.ini so that it would refer to partition(2) instead of partition(1). But I preferred to make sure that this hidden partition (if there was one) would not haunt me in the future. In that case, My Digital Life advised a direct download of Microsoft's DiskPart.exe for pre-Vista versions of Windows. I did so. To try it out, I installed it and ran it (Start > Run > diskpart.exe) on a working WinXP computer. It gave me the usual DOS-like inscrutable prompt, only this prompt said simply "DISKPART." Hypertrophy said that the first command to use was "list disk." At the DISKPART prompt, I typed "diskpart /?" for a list of DiskPart commands. "List" was one of the commands in that list, but I was not sure what "disk" did. At the DISKPART command prompt, I typed "list /?" and got the information that "list disk" would print out a list of disks. I thought I might actually prefer a list of partitions or volumes, which were the other two list options. A Microsoft webpage on DiskPart command syntax suggested that "detail" might be a more useful command than "list," for my purposes, so I tried that. Following their lead, I began with "select disk 0" and then "detail disk." This did appear to be a program that I could use to detect and delete a hidden partition on the target laptop, if there was one there. The only problem was that I had to be able to run WinXP on that computer in order to run DiskPart.exe, and I hadn't yet succeeded in doing that. It occurred to me that BartPE might be able to handle this kind of situation. I went back to el-saabi, this time to his guide on putting BartPE on a USB stick. This guide called for some steps that were similar to those recommended by Fred Langa (above), refined as follows:
  1. Put your Windows XP CD into your CD drive.
  2. Create C:\BartUSB. Download and run BartPE Builder (name of present version: pebuilder3110a.exe). Install it into C:\BartUSB. So now, for example, you have a folder called C:\BartUSB\drivers. When BartPE asks, let it search for Windows installation files. It should find the files on the CD drive. If it doesn't, point it that way. Don't go any further with BartPE now.
  3. Download srsp1.zip (or srsp1.rar, another zip-like format). This srsp1 file contains just the files we need, which is faster than downloading the whole Service Pack as called for in the Fred Langa approach (above). (The "Extract All" right-click option in Windows XP does not open .rar files, but 7-Zip does.) Unzip the contents of the srsp1 file to C:\BartUSB. So now you have a folder named C:\BartUSB\srsp1, and that folder contains two files: ramdisk.sys and setupldr.bin.
  4. If your WinXP CD has service pack 2 or service pack 3 included, click on BartPE's Plugins button and enable "RpcSS needs to launch DComLaunch Service first - SP2 only." Then click on Close and then Build, and let it go through its steps. When the Build is done, close and exit.
  5. Plug a USB drive (size: 256MB to 2GB) into the computer you will be using to make the BartPE stick. In Windows Explorer, take note of its drive letter. On the command line, navigate to C:\BartUSB. Type "pe2usb -f J:" (replacing J with the drive letter for your USB drive). Type YES and so forth, as prompted, to finish the process.
  6. Eject the USB drive from the computer. Plug it into the computer you want to boot from USB. Boot that computer.
This setup took only 157MB on my 256MB flash drive. Unfortunately, the result was still not bootable. It gave me GRUB Error 15. When I removed the thumb drive, Ubuntu booted normally. Even if it had booted, I was not yet entirely sure how I would run DiskPart.exe. Again, note that I was looking for a bootable USB drive that would fix problems that appeared to stem from an imperfect removal of the factory-installed recovery partition on a hard drive that had originally been home to a Windows Vista installation. I had to conclude, at this point, that I lacked the knowledge and time required to prepare a USB flash drive that would tackle this problem effectively. Based upon my knowledge at this point, it was unfortunately necessary, then, to wipe the hard drive and reinstall the partitions in order to eliminate this problem.

0 comments: