Windows 7: replacing a MBR disk with a GPT disk

Door mrmrmr op zaterdag 16 april 2016 17:38 - Reacties (7)
Categorie: Operating systems, Views: 2.975

Recently, my Windows 7 x64 system needed a new hard disk. I suspected that the existing hard disk was the reason for undefined freezes. I bought a new 4 TB disk to move from the old unreliable 2 TB disk.

You'd think that cloning the disk would not be a problem, there are many tools around that help clone disks. Some disk drive vendors provide them for free. Some even work with disks from a different brand as long as at least one recognized brand disk is present in the system. There are free tools available too.

However, there are a few serious problems. The first problem is that the current disk uses a MBR (Master Boot Record) and the new hard disk has to use GPT (GUID Partition Table) to make available the full 4 TB. MBR is limited to about 2.2 TB in Windows.

The second problem is that many disk clone tools do not work if the disk was partitioned with separate volumes for boot, system and user profiles and disk letters get mixed up terribly. Cloned drives often did not even boot properly. Normally, a standard Windows install is a C: drive containing all of the operating system, but using autounattend.xml on the setup USB stick will allow separation on different volumes. We'll discuss that later.

The system has C: as a boot disk, D: as the Windows disk, E: as the user profiles disk and F: as a data disk. This article describes how to handle this specific case. Your system may have a different layout of split installation, requiring some adjustments.

It may work for single C: drive installs too, but there will likely be some unneeded steps, such as collecting partition and volume layout information and changing the registry.

1. UEFI
Make sure the motherboard is using UEFI. Sometimes this is difficult to verify. The AMI BIOS my system uses isn't too clear about it and manuals may not mention it at all. UEFI is necessary to enable support for GPT disks.

2. Create a UEFI USB flash disk
Rufus can create a bootable USB disk from an ISO or IMG of Windows 7. It needs to be the x64 version of Windows 7, the 32 bit version does not support GPT. Select the GPT partition scheme for UEFI. This will partition the USB disk in GPT format. This persuades Windows Setup to support GPT disks.

http://static.tweakers.net/ext/f/CAgqQNzQzCkZWSLc1IARx3HM/full.png

Create another USB Flash disk with CloneZilla Live on it. We'll need it later. It doesn't need to have GPT partitioning.

3. Connect the new disk and boot from the Windows installation USB stick
Disconnect all existing disks and connect the new disk to the system. Boot from the Windows installation USB disk.

4. Get a command prompt and partition the new disk
As soon as a GUI window appears, press Shift-F10. This opens a command prompt window. Start the diskpart partitioning tool.

diskpart
select disk 0
list partition


No partitions should be present. If you are sure you are editing the new unused disk, enter the following commands:

clean
convert gpt
list disk


  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
* Disk 0    Online         3726 GB  3726 GB        *

The asterisk at the end shows that the disk is initialized as a GPT disk.

exit

5. autounattend.xml
Windows Setup can run in automated mode. One of the ways to do this is to create an autounattend.xml file.

XML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>en-US</UILanguage>
            </SetupUILanguage>
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
        <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ImageInstall>
                <OSImage>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>5</PartitionID>
                    </InstallTo>
                    <InstallToAvailablePartition>false</InstallToAvailablePartition>
                    <WillShowUI>OnError</WillShowUI>
                </OSImage>
            </ImageInstall>
            <UserData>
                <ProductKey>
                    <Key>XXXXX-XXXXX-XXXXX-XXXXX-XXXXX</Key>
                    <WillShowUI>OnError</WillShowUI>
                </ProductKey>
                <AcceptEula>true</AcceptEula>
                <FullName>Name</FullName>
            </UserData>
            <DiskConfiguration>
                <WillShowUI>OnError</WillShowUI>
                <Disk>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                    <CreatePartitions>
                        <!-- EFI system partition (ESP) -->
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Type>EFI</Type>
                            <Size>260</Size>
                        </CreatePartition>
                        <!-- WinRE recovery tools partition -->
                        <CreatePartition wcm:action="add">
                            <Order>2</Order>
                            <Type>Primary</Type>
                            <Size>300</Size>
                        </CreatePartition>
                        <!-- Microsoft reserved partition (MSR) -->
                        <CreatePartition wcm:action="add">
                            <Order>3</Order>
                            <Type>MSR</Type>
                            <Size>128</Size>
                        </CreatePartition>
                        <!-- C old boot disk -->
                        <CreatePartition wcm:action="add">
                            <Order>4</Order>
                            <Type>Primary</Type>
                            <Size>300</Size>
                        </CreatePartition>
                        <!-- D Windows -->
                        <CreatePartition wcm:action="add">
                            <Order>5</Order>
                            <Type>Primary</Type>
                            <Size>100000</Size>
                        </CreatePartition>
                        <!-- E User Profiles -->
                        <CreatePartition wcm:action="add">
                            <Order>6</Order>
                            <Type>Primary</Type>
                            <Size>100000</Size>
                        </CreatePartition>
                        <!-- F Data -->
                        <CreatePartition wcm:action="add">
                            <Order>7</Order>
                            <Type>Primary</Type>
                            <Extend>true</Extend>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <!-- EFI system partition (ESP) -->
                        <ModifyPartition wcm:action="add">
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                            <Format>FAT32</Format>
                            <Label>System</Label>
                        </ModifyPartition>
                        <!-- WinRE recovery tools partition -->
                        <ModifyPartition wcm:action="add">
                            <Order>2</Order>
                            <PartitionID>2</PartitionID>
                            <Format>NTFS</Format>
                            <Label>WinRE</Label>
                            <TypeID>de94bba4-06d1-4d40-a16a-bfd50179d6ac</TypeID>
                        </ModifyPartition>
                        <!-- Microsoft reserved partition (MSR): do nothing -->
                        <ModifyPartition wcm:action="add">
                            <Order>3</Order>
                            <PartitionID>3</PartitionID>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Order>4</Order>
                            <PartitionID>4</PartitionID>
                            <Format>NTFS</Format>
                            <Label>C</Label>
                            <Letter>C</Letter>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Order>5</Order>
                            <PartitionID>5</PartitionID>
                            <Format>NTFS</Format>
                            <Label>D</Label>
                            <Letter>D</Letter>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Order>6</Order>
                            <PartitionID>6</PartitionID>
                            <Format>NTFS</Format>
                            <Label>E</Label>
                            <Letter>E</Letter>
                        </ModifyPartition>
                        <ModifyPartition wcm:action="add">
                            <Order>7</Order>
                            <PartitionID>7</PartitionID>
                            <Format>NTFS</Format>
                            <Label>F</Label>
                            <Letter>F</Letter>
                        </ModifyPartition>
                    </ModifyPartitions>
                </Disk>
            </DiskConfiguration>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Reseal>
                <Mode>OOBE</Mode>
            </Reseal>
        </component>
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <HideEULAPage>true</HideEULAPage>
                <NetworkLocation>Other</NetworkLocation>
                <ProtectYourPC>3</ProtectYourPC>
            </OOBE>
            <FolderLocations>
                <ProfilesDirectory>E:\Profiles</ProfilesDirectory>
            </FolderLocations>
        </component>
        <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="wim:c:/win/install.wim#Windows 7 PROFESSIONAL" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>


This autounattend.xml file creates a EFI partition, a recovery partition and a ESR partition. The EFI partition is used to boot the disk. The ESR partition is hidden. Four drives are created: C:, D:, E: and F:. This matches the drive letters on the old disk. The volume sizes can be adjusted as needed. On the old disk, the C: drive was used as the boot disk, D: contained Windows and E: contained user profiles. F: is the data volume. The new disk will have the same drive letters, this prevents broken links.

Replace the key in the ProductKey section with your own key and save the file as "autounattend.xml".

The autounattend.xml file should be copied to the root of the USB setup disk. Windows Setup will find it there.

Next, we'll need to install Windows. This creates the proper disk layout we need later to copy our old data into.

6. Boot from the Windows USB disk
Enter the BIOS or boot menu and make sure that the USB disk shows up as UEFI, select the UEFI USB disk as the boot disk.

Windows will start setting itself up when the Windows 7 USB disk is booted. The disk is partitioned, volumes are created and Windows is installed. Nearly everything is automated.

When everything is done, it will be possible to login to the newly installed Windows. Insert the USB key and rename the autounattend.xml to autounattend.xml.renamed.

7. Export DosDevices key from the registry
Another boot from the USB disk is needed. This time we need to export drive letter data from the registry of the Windows Setup environment. Use Shift-F10 when you see a Windows screen. From the command prompt diskpart can be used to verify the existing drive letters.

diskpart
select disk 0
list partition
list volume


Save the output of these screens to the USB disk for later reference.

If the volumes listed include C, D, E and F with expected sizes, we can export this key from the registry: HKEY_LOCAL_MACHINE/SYSTEM/MountedDevices

\DosDevices\C:
\DosDevices\D:
\DosDevices\E:
\DosDevices\F:


Save the file as driveletters.reg. Press Shift-F10 and start notepad from the command line, edit the reg file and remove drive letters G: and higher, then save the file.

8. Copying old data to new volumes
There are several ways the old data can be copied. A requirement for any method is proper handling of hidden and system files and links. We'll use CloneZilla to copy the content from the old disk to the new disk. CloneZilla does not try to change things that shouldn't be changed. That's exactly what we need.

9. Power down and connect the old disk
We need to gather some information about the partitions and volumes. Connect the old disk and disconnect the new disk. Let Windows boot from the old disk. The old disk has several primary partitions, one extended partition and logical partitions. Type Disk Management in the search box of the Start menu. We need to make sure that each volume has its own unique name (Properties, General tab), we'll use disk letters as volume labels. The C: volume has 'C' as its label, etc.

To get detailed data, use diskpart from the command line.

diskpart
select disk 0
list partition
list volume


Save the output of commands to the USB disk for later reference. For convenience, print the data.

10. CloneZilla
Power down and connect both the old and new disks. Insert the USB disk containing CloneZilla Live and boot from it. After entering some configuration settings, select mode device-device, select Expert mode, select part_to_local_part. Then choose the source and target partitions. Double check and make sure the right partitions are selected, it would be most unfortunate to copy the new disk partitions to the old disk!

The parameters to use are: -e1 auto -e2 -r -m -v

Copy each of the old partitions to the corresponding partitions on the new disk. The drive letters are useful to identify the right partition.

11. Hive loading and registry editing
When copying is ready, disconnect the old drive. Boot again from the USB disk and press Shift-F10.
First, create a backup of the original D:\Windows\System32\Config\system registry hive file. Next, start regedit from the command line. Navigate to this location in regedit:
HKEY_LOCAL_MACHINE.
In the pull-down menu, select File, Load Hive... D:\Windows\System32\Config\system. Load this hive into key name: systemhive.

Open notepad and edit driveletters.reg. Replace HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices with
HKEY_LOCAL_MACHINE\systemhive\MountedDevices. Save the file to driveletters2.reg. From the command line, import the settings by typing driveletters2.reg and hitting the enter key. If it worked, you can check the result under the systemhive key name. Next, unload the hive. This saves the changes to the D: drive.

12. Finishing & notes
To check if everything works, boot from the newly created hard disk. You may see chkdsk verifying the disks, let it do its job. After this is finished, Windows should boot as before.

If it seems to take ages before Windows shows a login screen or if it takes a long time before the start menu is shown, press Ctrl-Alt-Del and start the Task Manager. If you start a command prompt (cmd), you'll probably see that the volumes are not using the drive letters they should be using. In that case, go back and perform the procedure again.

You may see this error message if the drive letters are mixed up:
The user Profile Services failed to logon. User Profile cannot be loaded.
Drive letters are mixed up after booting to the new disk.

During installing Windows on the new disk drive, you may see this error message:
Windows cannot be installed to this disk. The selected disk is not of the GPT partition style.
The USB disk has not booted in UEFI mode, or Windows did not recognize a UEFI booted USB disk.

Windows Setup uses that to decide if GPT is supported, and it is picky: booting as an UEFI USB disk was not enough. The USB disk was specifically formatted as FAT32 with GPT layout and it was booted from the boot menu as a UEFI USB disk.
The type of BIOS may be of influence too. My system has an AMI BIOS which does not have a clear EFI enabling setting. This BIOS does not show hard disks as UEFI disk unless it is a GPT disk.