Good-to-know recovery in Windows 8

If you haven’t started to play around in the snow yet (in Sweden at least) and you’re stuck inside because you’re sick (like me) you can always do things like back-ups (and no I’m not talking about the exercise), and other file cleaning things…. and in Windows 8, why not create a recove Wim-file with recimg?

If you run cmd as administrator and execute

recimg /?
Configures the recovery image Windows uses to refresh your PC.
RECIMG.EXE <command> <arguments>
The recimg.exe command line tool lets you configure a custom recovery image for Windows to use when you refresh your PC.
When you create a custom recovery image, it will contain the desktop apps you've installed, and the Windows system files in their current state. 
Recovery images do not contain your documents, personal settings, user profiles, or apps from Windows Store, because that information is preserved at the time you refresh your PC.
When you create a custom recovery image, recimg will store it in the specified directory, and set it as the active recovery image. 
If a custom recovery image is set as the active recovery image, Windows will use it when you refresh your PC. 
You can use the /setcurrent and /deregister options to select which recovery image Windows will use. 
All recovery images have the filename CustomRefresh.wim. If no CustomRefresh.wim file is found in the active recovery image directory, 
Windows will fall back to the default image (or to installation media) when you refresh your PC.
Note that you cannot reset your PC using a custom recovery image. Custom recovery images can only be used to refresh your PC.
The following commands can be specified:
/createimage <directory>         Captures a new custom recovery image in the location specified by         <directory>, and sets it as the active recovery image.
/setcurrent <directory>         Sets the active recovery image to the CustomRefresh.wim file in the         location specified by <directory>. Windows will use this image when you
refresh your PC, even if a recovery image provided by your PC's         manufacturer is present.
/deregister         Deregisters the current custom recovery image. If a recovery image         provided by your PC's manufacturer is present, Windows will use that         
image when you refresh your PC. Otherwise, Windows will use your         installation media when you refresh your PC.
/showcurrent         Displays the path to the directory in which the current active recovery         image is stored.
/help, /?         Displays this help text.

So! Away we go, and might I suggest you place the recovery wim file on a different drive than your windows drive 🙂

recimg /createimage e:\recimg

If you navigate to that folder you will see that windows will create a CustomRefresh.wim file.

When it is complete execute recimg /showcurrent to view the settings.

AND if you got a little bit over excited as I did with the cleaning up files and what not’s and you tried to refresh your Windows 8 machine with Windows Recovery by pressing Shift and F8 while booting…
but all you got was “The drive where Windows is installed is locked. Unlock the drive and try again”
Refresh your PC

Well have no fear you probably just messed upp BCD so press cancel, go back to Windows Recovery, select Troubleshoot, Advanced Options and then Command Prompt and execute

diskpart

and then

list volume

And note which volume letter (Ltr) that has the operating system files for Windows 8 – you better know the size of the partition 😉

then execute the following where you replace D: with the drive letter of your Windows 8 partition.

bcdboot d:\windows /s d:\

And if THAT fails you need to find out the GUID {identifier} for your installation and use that information with bcdboot to repair it.

bcdeditwin8

And then use that information instead (with the driveletter of your volume as explained in the previous steps):

bcdboot d:\windows /m {2980d3a5-1dfc-11e2-a3bb-2c768ae43499}

Powershell cmdlets one-by-one or How to replace diskpart with powershell

Yes, yes I know… The Swedish Powershell MVP Niklas Goude will probably kick my ass if he ever found out I wrote this blog post…
 
But not all of us were born composing powershell scripts with our eyes closed, so here are some baby steps (one-by-one cmdlets) to help you get started with understanding how awesome powershell is 🙂
 
What I did was that I sat down and got-help in powershell and actually figured out how to create a virtual machine and a virtual disk a.k.a I’m trying to step away from diskpart (that we all know and love)
 
Creating a virtual machine, mounting an ISO and starting it, FTW
 
First of all, you need Powershell 3.0 to accomplish this, that either means you need a Windows Server 2012 or Windows 8 host with Hyper-V installed. (Yes Hyper-V is included in both the client and the server)
 
Create, start a virtual machine and mount an ISO with Powershell
 
Run Powershell as administrator and execute the following:
New-VM -Name VM01 -MemoryStartupBytes 1024MB
The command creates a new virtual machine named VM01 with 1024 MB memory.
 
Now you need to create a virtual disk for the machine:
 
New-VHD -Path C:\VM\VM01.vhdx -SizeBytes 30GB -Dynamic
After creating the disk you’d want to attach it to the virtual machine
Add-VMHardDiskDrive -VMName VM01 -Path C:\VM\VM01.vhdx
Then to mount an ISO you execute
Set-VMDvdDrive -VMName VM01 -ControllerNumber 1 -Path C:\ISO\windows.ISO
And then start the machine!
 
Start-vm –name VM01
 
 
Create, select, partition and format VHD in Powershell or…
“How to replace diskpart with powershell”
 
So diskpart, create vdisk and so on, how-to do the same thing in powershell…
 
Create a virtual disk
 
New-VHD -Path C:\VM\windows.vhdx -SizeBytes 30GB -Dynamic
 
Mount the VHD (instead of attaching it in diskpart)
 
Mount-VHD -Path C:\VM\windows.vhdx
 
Find out which disk number the mounted VHD got
 
Get-Disk
 
Bring the disk online (and YES you specify 1 instead of 0 if you want to take it offline)
 
Set-Disk -Number 2 -IsOffline 0
 
Make the disk writable (and YES you specify it to be Read only with 1)
 
Set-Disk -Number 2 -isReadOnly 0
 
Initialize the disk
 
Initialize-Disk -Number 2 -PartitionStyle MBR
 
Create a partition on disk 2 and automatically assign a driveletter
 
New-Partition -Disknumber 2 -UseMaximumSize -AssignDriveLetter
 
Format the volume
 
Get-Partition -Disknumber 2 | Format-Volume -FileSystem FAT32
By the way, if you try to eject the virtual disk in windows explorer or disk management you will most likely get an error message, so if you want to

Dismount the VHD execute the following
Dismount-VHD -Path C:\vm\windows.vhdx

And then there are the rest of the Storage Cmdelts awesomeness