0

I captured an image and I'm trying to restore it to a different VM without using Sysprep since I'm actively using the vm server I want to clone and I don't want to have to set it back up again, I could but it would be a waste of time:

Started the original VM from a WinPE ISO, and brought up the cmd prompt:

Capture Shared read/write : \DESKTOP-O8ESL65\wsus_img

start /w wpeinit

Connected up to the share with

net use i: \\DESKTOP-O8ESL65\wsus_img /user:someuser /password

Captured the image with the following command:

dism /capture-image /ImageFile:i:\install.wim /CaptureDir:C:\ /Name:"winserver_wsus2016"


Restore without Sysprep

Created a new vm and booted it with WinPE, then created GPT partitions on it:

start /w wpeinit
net use f: \\DESKTOP-O8ESL65\wsus_img
diskpart

Microsoft DiskPart version 10.0.14393.0Copyright (C) 1999-2013 Microsoft Corporation.On computer: MININT-TJ84J7UDISKPART> select disk 0
Disk 0 is now the selected disk.
DISKPART> list vol  
Volume ###  Ltr  Label        Fs     Type        Size     Status     Info  
----------  ---  -----------  -----  ----------  -------  ---------  --------  
Volume 0     D   DVD_ROM      UDF    DVD-ROM      6649 MB Healthy  
Volume 1                      RAW    Partition    126 GB  Healthy      
Volume 2     C   Recovery     NTFS   Partition    450 MB  Healthy    Hidden  
Volume 3     E                FAT32  Partition    100 MB  Healthy    HiddenDISKPART> select volume 1
DISKPART> format fs="ntfs" quick label="data"
DISKPART> assign letter=g
DISKPART> list vol

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info  
----------  ---  -----------  -----  ----------  -------  ---------  --------  
Volume 0     D   DVD_ROM      UDF    DVD-ROM      6649 MB Healthy  
Volume 1     G   data         NTFS   Partition    126 GB  Healthy      
Volume 2     C   Recovery     NTFS   Partition    450 MB  Healthy    Hidden  
Volume 3     E                FAT32  Partition    100 MB  Healthy    Hidden
    
DISKPART> exit

Then I ran this to apply the image, but then the new VM wouldn't boot afterwards:

dism /apply-image /Imagefile:f:\install.wim /index:1 /applydir:g:\

And after that I couldn't boot the machine from the drive, so I repeated the steps above and then added this after I read that the following commands could be used as a replacement for sysprep:

bcdedit /set {default} device partition=c:
The boot configuration data store could not be opened.
The system cannot find the file specified.

bcdedit /set {default} osdevice partition=c:
The boot configuration data store could not be opened.
The system cannot find the file specified.

bcdedit /set {bootmgr} device partition=c:
The boot configuration data store could not be opened.
The system cannot find the file specified.

But the commands do not work in WinPE. I even tried it from G:\Windows\System32\bcdedit.exe, and I still get the same message.

I'd like to setup the windows bootloader so the vm will boot and I can create a second WSUS Server. I was thinking maybe I needed to do a runas, but since I'm in WinPE, what user would I run the command as? Also I found some documentation on bcdedit.exe but I'm new to GPT partitions and UEFI so I'm at a bit of a loss in how to proceed.

leeand00
  • 4,869
  • 15
  • 69
  • 110

1 Answers1

0

Okay, so I was able to get things going again, but only after following the manual on Microsoft's website.

First I started reading Capture and Apply a Windows .wim file, it linked to another document (CreatePartitions-UEFI.txt) about GPT partition structure and how to create it using diskpart and a script (named CreatePartions-UEFI.txt), and when I returned again to the original document the instructions stated that we were to run diskpart /s CreatePartitions-UEFI.txt, and then apply the image and finally copy some files around to the GPT partitions; see below:

1. Create Partitions:

So first I needed to hook up all the UNC drives to pull the image from, which I did first.

The instructions are as follows, and they start off with the creation of the script to be used after we boot to WindowsPE to create the partitions:

rem == CreatePartitions-UEFI.txt ==
rem == These commands are used with DiskPart to
rem     create four partitions
rem     for a UEFI/GPT-based PC.
rem     Adjust the partition sizes to fill the drive
rem     as necessary. ==
select disk 0
clean 
convert gpt
rem == 1. System partition ==============
create partition efi size=100
rem     ** NOTE: For Advanced Format 4Kn drives, 
rem            change this value to size = 260 **
format quick fs=fat32 label="System"
assign letter="S"
rem == 2. Microsoft Reserved (MSR) partition ==============
rem == 3. Windows partition ==============
rem ==     a. Create the Windows partition ==============
rem ==     b. Create space for the recovery tools ===
rem           ** Update this size to match the size of 
rem               the recovery tools (winre.wim)
rem               plus some free space.
shrink minimum=650
rem ===     c. Prepare the Windows partition ==============
format quick fs=ntfs label="Windows"
assign letter="W"
rem === 4. Recovery tools partition ==============
create partition primary
format quick fs=ntfs label="Recovery Tools"
assign letter="R"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
list volume
exit

CreatePartitions-UEFI.txt

Next we have to boot the PC with Windows PE, and from the cmd prompt window I ran the following to create the partitions:

DiskPart /s F:\CreatePartitions-UEFI.txt

2. Change the Power Scheme

So it doesn't go to sleep while the image is restoring...

call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

3. Apply Image:

Then from an external UNC share I applied the image I had captured earlier with dism (where F:\ is the UNC share):

dism /apply-image /Imagefile:F:\images\install.wim /index:1 /applydir:W:\

5. Setup Partitions with the boot files:

W:\Windows\System32\bcdboot W:\Windows /s S:

6. Setup Partitions with Windows Recovery Environment:

6.1 Add Windows Recovery Environment from ???

Attempted to install the Windows Recovery Image, the documentation says it should be in W:\Windows\System32\Recovery\Winre.wim but it was not there, so I salvaged it from an old Windows 10 installation and copied it via my UNC share instead (but I still don't know where to get it officially, or if it's something that Microsoft changed how they do, and never updated the documentation for...please let me know if you know the answer to this...)

md R:\Recovery\WindowsRE
xcopy /h W:\Windows\System32\Recovery\Winre.wim R:\Recovery\WindowsRE

6.2 Register Location of Recovery Tools

I also registered the location of the Windows Recovery Tools and it worked:

W:\Windows\System32\Reagentc /Setreimage /Path R:\Recovery\WindowsRE /Target W:\Windows

6.3 Verify Configuration of the image

W:\Windows\System32\Regentc /Into /Target W:\Windows

7. Reboot into Windows Server 2016 and do what sysprep would have done?

I rebooted the vm into Windows Server and after a short time was able to generalize the machine without sysprep at least that's what it says here where I got the following commands that I ran after the reboot:

bcdedit /set {default} device partition=c:
bcdedit /set {default} osdevice partition=c:
bcdedit /set {bootmgr} device partition=c:

Summary

Everything worked out, but I am still a little confused as to where the winre.wim file would come from if I had not retrieved it from that old Windows 10 installation, does anyone have an idea about that?

leeand00
  • 4,869
  • 15
  • 69
  • 110
  • So seriously, nobody knows where `winre.wim` comes from initially? I found it in an old backup, but I don't know where it is now. – leeand00 Sep 22 '20 at 16:56