Jaa


Windows images, and dual-boot

Introduction

Recently, I wanted to play with a preview of Windows (an image that I knew would be ephemeral) while keeping a different, more permanent, version of Windows on the same PC. Virtual hard drives and Hyper-V had worked for me in the past for the same purpose, but this time I had the opportunity to try Windows image (.wim) files. So I gave it a go and kept a record of what I did.

If you want to boot your PC into one of several installed versions of Windows - whether or not you use Windows image files - then this information may be of some interest to you.

Some background on disks, partitions, and booting

Your PC has one or more physical disks in it. On them you can put OSes (one or more per disk) and/or data. The BIOS in the PC determines the boot order of disks. Each disk has an MBR (Master Boot Record) in which are the commands necessary to start the OS, as well as a list of the disk's partitions (a partition contains a file system, has a drive letter, and is loosely synonymous with a drive, or a volume). The MBR itself is not located in a partition.

At most one partition on a disk is marked as active, and this is the partition to whose VBR (Volume Boot Record) the MBR transfers control. A boot record is loosely synonymous with a boot loader. To enable booting into one of several OSes on different partitions of a disk, the Windows Boot Manager (loaded by the active partition's VBR) reads the BCD (Boot Configuration Data) in which the available OSes are described. The BCD is stored as a file, and it has the same format as that of the Windows Registry. It is stored in the active partition, in \Boot\Bcd.

Planning the disk configuration

The first thing I did was to plan out what partitions I needed. I had two disks, and I would put my permanent OS on the first partition of my first disk, and that would be drive C. I would put my ephemeral OS on the second partition of the first disk, and that would be drive D. Since I could see myself reformatting and re-imaging drive D from time to time, it didn't seem like the best place for the BCD. So I decided to make drive C the active partition and that's where I would keep the BCD that I'd need to craft at some point during the process. The rest of the first disk would be a data partition (drive E), and so would all of the second disk (drive F).

To manage disks and partitions, you can use the DISKPART command-line tool. Alternatively, the Disk Management snap-in can be launched quickly in one of several ways. Start > Run (or Windows Logo+R) > diskmgmt.msc. Or, in Windows 8, Windows Logo+X (to display the Power User, or Windows Tools, menu) > Disk Management. You can also display that menu by right-clicking the Start screen popup in the lower left-hand corner.

Using DISKPART

DISKPART's commands are documented here: https://support.microsoft.com/kb/300415.

I network-booted into Windows PE (Preinstallation Environment) and used DISKPART. List disk displays a list of the installed disks along with their number and size, so this helps you identify them. My OSes were going onto disk 0 so I selected that with select disk 0. List partition displays a list of the partitions on the selected disk along with their number, type, and size. I had a small OEM partition (1) and a large Primary partition (2) so I selected the latter with select partition 2 and then deleted it with delete partition.

To create the first OS partition, 100GB in size, I used create partition primary size=100000. The newly-created partition is automatically selected, as is the corresponding volume. Then I formatted and labeled it with format fs=ntfs quick label="WINPERM" , assigned a drive letter with assign letter=c, and made it active with active. 100GB is two-to-five times the size I strictly needed, but I had the space so what the hey. And, you can always assign drive letters later, in Windows, since they'll likely change from the ones you set here before you're done.

I then created another partition the same size, labeled it WINEPH, and assigned letter D. And finally, to fill up the remaining disk space, create partition primary and then formatted it without a label but assigned letter E (which I had to steal from a DVD drive). Disk 1 already had one NTFS partition.

I exited from DISKPART and rebooted with wpeutil reboot.

Installing Windows

Booting from the network again, I installed my permanent OS, being careful to choose the first partition on the first disk (the one labeled WINPERM).

This next stage - installing the ephemeral OS - will be repeated each time I move to a new one, so I'll describe the steps in terms that will work for both initial and subsequent iterations.

It's unlikely that you'll have BitLocker enabled on your WINEPH volume but, if you do, now's the time to suspend it and save the key someplace. I network-booted into Windows PE again and first confirmed the drive letter of the second partition on the first disk. It had changed to E, but I knew it was the same partition because dir showed the right volume label (WINEPH). Next, I followed the steps below (provided by my co-worker) to apply a Windows image file (available on my network) to my drive E.

  • Map the path to the IMAGEX tool to a local drive letter (so I can use it later on the command line). net use y: \\<servername><path>
  • Map the path to the Windows image files to a local drive. net use z: \\<servername><path>
  • format /q e:
  • Apply the Windows image. y:\imagex /apply z:\<filename> 1 e:
  • wpeutil reboot

Remember, a PC boots into the active partition (WINPERM, in my case) and, since that partition knows nothing about WINEPH, I have some work to do before I'll get the option to boot into the OS on that partition.

The first thing I did after the reboot was to use the Disk Management snap-in to fix up my drive letters.

Dual-boot camp

To edit the BCD store on my active partition (WINPERM), I used the BCDEDIT command-line tool. Windows Logo+X > Command Prompt (Admin). Bcdedit lists the entries in the store. I made a copy of the boot loader entry with bcdedit /copy {current} /d "Windows Ephemeral" . Running bcdedit again will show the identifier of the new entry, so marking that and copying it to the clipboard is a good idea at this time. Then I pointed the new entry to the right partition with bcdedit /set {<id>} device partition=d: and bcdedit /set {<id>} osdevice partition=d: .

That's it. Reboot, and you'll be presented with WINPERM's Windows Boot Manager and from there you can choose the Windows Permanent or Windows Ephemeral OS. I chose Windows Permanent first, then rebooted. That reboot took about ten minutes, I don't know why. Then I chose Permanent again, rebooted (which was quick), chose Ephemeral, and every reboot since has been perfectly normal.