Monday, 16 January 2017

Find and boot to a Windows recovery.wim file (e.g. winre.wim)

Alex had a problem...

Often a Windows system cannot boot (not even to the recovery mode), but the recovery partition on that system will contain the correct WinRE.wim file that can be used to repair that OS.

He wanted to be able to boot to Easy2Boot and then boot to the WinRE.wim recovery file that was on the internal hard disk. That way, he could be sure he was using the correct version of the recovery .wim file for that system. Also, his E2B drive did not need to contain all of the possible Windows install ISO versions that there are in the world!

E2B can directly boot to an NT6 .wim file; you just need to specify the full path of the .wim file.

The problem is that different Windows systems keep the .wim file in different folders.

To further compound the issue, on his Windows 7 systems, the directory name often varied on different systems, e.g.

/Recovery/398cea27-6312-11e6-a670-10604b8d82a9/WinRe.wim


I have added a new grub4dos batch file (FindFile.g4b) which can be used to find a certain file (or a file with a specific file extension).

FindFile.g4b searches all sub-directories below the user-specified folder.

The first file it finds, that matches the specified name (or the specified file extension), is returned in the %FILE% parameter.

I have added a sample .mnu file into the \_ISO\docs\Sample mnu Files\Windows folder as an example (revised version for multiple OS systems):

# Example of how to use FindFile.g4b to find a file - e.g. .wim or .vhd
# Does not work for most .iso files if .iso file is not on E2B drive
#
# Search for a file by fullname or just the file extension
# Then boot to it using QRUN.g4b
#
# If you don't want to see any directories listed, then add 'SILENT' to the end of the findfile line
#

title Boot to Windows Recovery\n Boot the recovery .wim from the internal disk
set FILE=
# hd1 will be the first internal hard disk in the system (hd0 is USB drive)
if not exist FILE ls (hd1,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,0)/Recovery winre.wim
if not exist FILE ls (hd1,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,0)/Recovery .wim
if exist FILE set FILE1=%FILE% && set FILE=
# check second partition
if not exist FILE ls (hd1,1)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,1)/Recovery winre.wim
if not exist FILE ls (hd1,1)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,1)/Recovery .wim
if exist FILE set FILE2=%FILE% && set FILE=
# check third partition
if not exist FILE ls (hd1,2)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,2)/Recovery winre.wim
if not exist FILE ls (hd1,2)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,2)/Recovery .wim
if exist FILE set FILE3=%FILE% && set FILE=
# check fourth partition
if not exist FILE ls (hd1,3)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,3)/Recovery winre.wim
if not exist FILE ls (hd1,3)/ > nul && /%grub%/FindFile.g4b .findfile (hd1,3)/Recovery .wim
if exist FILE set FILE4=%FILE% && set FILE=

# check first partition of other drives...
if not exist FILE ls (hd2,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd2,0)/Recovery winre.wim
if not exist FILE ls (hd2,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd2,0)/Recovery .wim
if exist FILE set FILE5=%FILE% && set FILE=

if not exist FILE ls (hd3,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd3,0)/Recovery winre.wim
if not exist FILE ls (hd3,0)/ > nul && /%grub%/FindFile.g4b .findfile (hd3,0)/Recovery .wim
if exist FILE set FILE6=%FILE% && set FILE=
set CNT=0
if exist FILE1 echo 1 = %FILE1% && set /a CNT=%CNT%+1 > nul
if exist FILE2 echo 2 = %FILE2% && set /a CNT=%CNT%+1 > nul
if exist FILE3 echo 3 = %FILE3% && set /a CNT=%CNT%+1 > nul
if exist FILE4 echo 4 = %FILE4% && set /a CNT=%CNT%+1 > nul
if exist FILE5 echo 5 = %FILE5% && set /a CNT=%CNT%+1 > nul
if exist FILE6 echo 6 = %FILE6% && set /a CNT=%CNT%+1 > nul
set FILE=
if %CNT%==1 set FILE=%FILE1%%FILE2%%FILE3%%FILE4%%FILE5%%FILE6%
if not exist FILE echo && set /p ask=Choose a wim file: 
if "%ask%"=="1" set FILE=%FILE1%
if "%ask%"=="2" set FILE=%FILE2%
if "%ask%"=="3" set FILE=%FILE3%
if "%ask%"=="4" set FILE=%FILE4%
if "%ask%"=="5" set FILE=%FILE5%
if "%ask%"=="6" set FILE=%FILE6%
set FILE1= && set FILE2= && set FILE3= && set FILE4= && set FILE5= && set FILE6=
echo
set CNT=
if exist FILE pause --wait=5 Booting %FILE%
if exist FILE /%grub%/QRUN.g4b %FILE%
if not exist FILE pause SORRY: Cannot find a Recovery WIM file! && configfile (md)0x3000+0x50
set FILE=
boot

You can remove any lines which you don't want (the two green lines should be good enough for most systems). You can look for more filenames just by adding more lines.

The first green line looks for a winre.wim file anywhere under the /Recovery directory.
The second green line looks for any .wim file anywhere under the /Recovery directory.
The other lines search in other partitions or disks.

FindFile will display the path of each folder path before it searches it.
If you add an extra parameter to the FindFile line, it will prevent any output from being displayed, e.g.
/%grub%/FindFile.g4b .findfile (hd1,0)/Recovery .wim SILENT

Note that I have not tested this on a system with a GPT disk.

If you have any comments or suggestions about this feature, please feel free to contact me.

E2B v1.88j contains the new files.
See "\_ISO\docs\Sample mnu files\Windows\Boot_Recovery_WIM.mnu" for details.