Jump to content











Photo
- - - - -

Please help me to go ahead ?

cmd winpe boot.wim usb booting multibooting

  • Please log in to reply
146 replies to this topic

#101 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 02 August 2017 - 07:34 PM

.
Use parenthesis and several lines.

 

:thumbup: 

... or use a sub-routine:

IF DEFINED Removable CALL :Is_removable
...
GOTO :EOF

:Is_removable
ECHO Command 1
ECHO Command 2
ECHO Command 3
ECHO Command 4
GOTO :EOF

using the one or the other way depends on personal preference, scripting style, etc.

 

As a general rule the more simple is "main" the more is readable the script, but in some cases it is easier to "skip" over with a GOTO:

IF NOT DEFINED Removable GOTO :No_removable
FOR %%A IN (%Removable%) DO CALL :Sort_Rval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET RFree_') DO SET MostFreeRem=%%A
SET MostFreeRemMB=!VOL_%MostFreeRem%!
SET MostFreeRemMB=%MostFreeRemMB: =%
SET MostFreeRemMB=%MostFreeRemMB:~0,-6%
SET MostFreeRem 
:No_removable

:duff:

Wonko


  • devdevadev likes this

#102 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 03 August 2017 - 02:27 PM

Thanks 'Zharif' and 'Wonko' for the great help and support. I just loved the ways you Expert guys solve the difficult problems in simple tricks..

@ECHO OFF
pushd "%~dp0"
SETLOCAL ENABLEDELAYEDEXPANSION

set DATETIME=%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
set DATETIME=%DATETIME: =0%

SET OSPART1=
SET OSPART2=
SET SYSPART=
SET SOURCEVOL=
FOR %%w IN (C D E F G H I J K L N M O P Q R S T U V W Y Z) DO (
if not "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe set OSPART2=%%w:& set SOURCEVOL=!OSPART2!& CALL :START_BACKUP
if "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe set OSPART1=%%w:& set SOURCEVOL=!OSPART1!& CALL :START_BACKUP
)
ECHO TOTAL BACKUP SIZE=%BACKUP_SIZE% MB
SET ALL_USERS
CALL :FREEDRIVE
ECHO SMART BACKUP HAS BEEN DONE !!!
cmd /k


:START_BACKUP
ECHO SOURCEVOL is %SOURCEVOL%
SET ALL_USERS=
SET ALL_USERSDIR=
SET SOURCE_SIZE=
SET BACKUP_SIZE=
SET "SOURCEDIR=%SOURCEVOL%\Users"
FOR /F "tokens=*" %%A IN ('DIR /B /A:D-H "%SOURCEDIR%"^|FIND /V "Public"') DO (
SET PREFIX=%SOURCEDIR%\
SET "USER_%%A=%SOURCEDIR%\%%A"
SET "ALL_USERS=!ALL_USERS!	%%A"
SET "ALL_USERSDIR=!ALL_USERSDIR!	%SOURCEDIR%\%%A"
)
FOR /F "tokens=2* delims=_=" %%A IN ('SET USER_') DO (
SET USER=%%A& SET USERDIR=%%B
CALL :BACKUP_SIZE
)
GOTO :EOF


:BACKUP_SIZE
SET SOURCE_SIZE=
FOR /F "tokens=1 delims=. " %%A in ('DIRUSE /M "%USERDIR%\Music" "%USERDIR%\Videos" "%USERDIR%\Desktop" "%USERDIR%\Documents" "%USERDIR%\Downloads"') DO SET SOURCE_SIZE=%%A
ECHO !USER!  !USERDIR!  SIZE=%SOURCE_SIZE% MB
SET /a BACKUP_SIZE=BACKUP_SIZE+%SOURCE_SIZE%
GOTO :EOF


:FREEDRIVE
SET Partition=
SET Removable=
FOR /F "tokens=*" %%A IN ('ECHO LIST VOLUME ^| DISKPART ^|FIND "Healthy" ^|FIND "NTFS"') DO CALL :parse_volumes %%A
SET EXCLUDEDRIVES=%SYSPART%  %SYSPART11% %SystemDrive%
FOR %%A in (%EXCLUDEDRIVES%) DO SET Partition=!Partition:%%A =!
SET Partition
SET Removable

FOR %%A IN (%Partition% %Removable%) DO (
FOR /F "skip=2 tokens=2 delims=:" %%B IN ('fsutil volume diskfree %%A') DO (
ECHO %%A %%B
SET Vol_%%A=%%B
)
)

FOR %%A IN (%Partition%) DO CALL :Sort_Pval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET PFree_') DO SET MostFreePart=%%A
SET MostFreePartMB=!VOL_%MostFreePart%!
SET MostFreePartMB=%MostFreePartMB: =%
SET MostFreePartMB=%MostFreePartMB:~0,-6%
SET MostFreePart

IF NOT DEFINED Removable GOTO :NO_Removable
FOR %%A IN (%Removable%) DO CALL :Sort_Rval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET RFree_') DO SET MostFreeRem=%%A
SET MostFreeRemMB=!VOL_%MostFreeRem%!
SET MostFreeRemMB=%MostFreeRemMB: =%
SET MostFreeRemMB=%MostFreeRemMB:~0,-6%
SET MostFreeRem 
:NO_Removable
IF NOT DEFINED MostFreeRemMB SET /A MostFreeRemMB=0

SET FREEDRIVE=
IF %MostFreePartMB% GEQ %BACKUP_SIZE% (
SET FREEDRIVE=%MostFreePart%
) ELSE (
IF %MostFreeRemMB% GEQ %BACKUP_SIZE%  (
SET FREEDRIVE=%MostFreeRem%
)
)
IF DEFINED FREEDRIVE (CALL :DO_BACKUP) ELSE (ECHO NOT ENOUGH FREE SPACE TO BACKUP AUTOMATICALLY. YOU HAVE TO DO IT MANUALLY & Explorer ,)
GOTO :EOF


:DO_BACKUP
ECHO FREEDRIVE is %FREEDRIVE%
ECHO.
FOR /F "tokens=2* delims=_=" %%A IN ('SET USER_') DO (
SET USER=%%A& SET USERDIR=%%B
ECHO User is "!USER!" and User Directory is "!USERDIR!"
mkdir "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%" & Explorer.exe "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%"
robocopy "!USERDIR!\Music" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Music" /E /MT:1
robocopy "!USERDIR!\Videos" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Videos" /E /MT:1
robocopy "!USERDIR!\Desktop" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Desktop" /E /MT:1
robocopy "!USERDIR!\Pictures" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Pictures" /E /MT:1
robocopy "!USERDIR!\Documents" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Documents" /E /MT:1
robocopy "!USERDIR!\Downloads" "%FREEDRIVE%\BACKUP_!USER!_%DATETIME%\Downloads" /E /MT:1
)
GOTO :EOF


:Sort_Pval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET PFree_%Num%=%1
GOTO :EOF 

:Sort_Rval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET RFree_%Num%=%1
GOTO :EOF

:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET %Line:~37,9%=!%Line:~37,9%! %Line:~13,1%:
GOTO :EOF

Works perfect but sometimes DISKPART section becomes a bit slow ?



#103 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 August 2017 - 03:16 PM

 

Works perfect but sometimes DISKPART section becomes a bit slow ?

Yep, this is "normal".

For *whatever* reasons sometimes (especially when you invoke it the first time) Diskpart access is slow, there is nothing you can do about that.

 

:duff:

Wonko



#104 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 04 August 2017 - 03:03 PM

In WinPE, How  can I automatically detect and get Drive Letter of 'System Reserved'  or 'System' partition or a *Active Partition ( containing '/Boot/BCD' or '/EFI/Microsoft/Boot/BCD' ) in Disk0?



#105 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 04 August 2017 - 04:13 PM

You look for \boot\BCD?

You look for \EFI\Microsoft\Boot\BCD?

You assign a drive letter to any drive (of the "Partition" type) that hasn't already one and look for both \boot\BCD and \EFI\Microsoft\Boot\BCD?

You check that the disk is either GPT or MBR?

The "System Partition" on a GPT disk has a given GUID and it will normally be FAT32.

There is NO active partition on GPT.

The active partition on MBR may (or may not) contain the \boot\BCD.

 

:duff:

Wonko



#106 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 05 August 2017 - 04:17 AM

AFAIK, In WinPE, All drives (of the "Partition" type) already have Drive Letter assigned (specially 'System Reserved' partition) 

Both in UEFI/BIOS and GPT/MBR, First look for a partition labelled as either 'System Reserved' or 'System' . If found then assign it's drive letter to SYSPART. If not found any 'System Reserved' or 'System' labelled partition in 'Disk 0' then look either of \boot\BCD and \EFI\Microsoft\Boot\BCD. If either /boot/BCD or /EFI/Microsoft/Boot/BCD found in any partition in Disk 0, then assign it's drive letter to SYSPART.

 

The active partition on MBR may (or may not) contain the \boot\BCD.

in MBR if the partition containing \boot\BCD is not ACTIVE, then how Windows OS will boot in that system ?

Can you mention a case when active partition on MBR not contains \boot\BCD ?

May be you are talking about that case when no partition in Disk0 contains any Windows OS installed ?



#107 paraglider

paraglider

    Gold Member

  • .script developer
  • 1716 posts
  • Location:NC,USA
  •  
    United States

Posted 05 August 2017 - 08:28 AM

When you are using a boot manager like grub4dos to initiate the the boot of multiple os. In those circumstances only grub4dos needs to be on the active partition.



#108 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 05 August 2017 - 09:23 AM

When you are using a boot manager like grub4dos to initiate the the boot of multiple os. In those circumstances only grub4dos needs to be on the active partition.

Yes, exactly :).

And not only.

Using the original grldr.mbr or nowadays using the UMBR of grub4dos you can even have NO Active partition at all.

 

And NO, do not EVER trust a volume label, it may well have remained "System" or similar after a reinstall on another volume/partition.

 

:duff:

Wonko



#109 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 05 August 2017 - 04:24 PM

And NO, do not EVER trust a volume label, it may well have remained "System" or similar after a reinstall on another volume/partition.

i think in that case 'System' will still remains 'Boot Partition' ?

'SYSPART' will be the current 'Boot Partition' if Windows is already installed. If there is no windows OS already installed. then I will use 'Diskpart Script' to create 'System Reserved' partition (Boot Partition) and then assign it's drive letter to SYSPART. In my location most of the PC uses Bootmgr as the default boot manager. And rarely seen an PC which uses 'grub4dos' as a default bootloader. So I am considering only those cases which are native and recommended by MS.

 

So I am looking for drive letter of the currently or upcoming Boot Partition ('System Reserved' or 'System'). In some cases 'Boot Partition' and 'Installation Partition' remains same. So what I should consider as per my understanding is -

1- First look for volume label 'System Reserved' or 'System'. If exist then just check if contains either of /boot/BCD and /EFI/Microsoft/boot/BCD

2- If there is no 'System Reserved' or 'System' partition exist then just look for a partition having  either of /boot/BCD and /EFI/Microsoft/boot/BCD.

 

I think in most New PCs (UEFI+GPT), 'System Reserved' partition always exist ? So how I can get drive letter of current or upcoming 'Boot Partition' (System Reserved) through cmd batch file ? 



#110 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 05 August 2017 - 05:16 PM

Sometimes you sound really queer, you cannot cite me suggesting you to NEVER trust a volume label replying "OK, I understand, so I will use volume label first".  :unsure:

 

You could also assume that any 350 Mb (since most new PC's run Windows 10 with a default install) in size (FAT32 if GPT or NTFS if MBR) volume is the right one, so just check for a volume that is 350 Mb in size and be done with it. :whistling:

 

:duff:

Wonko



#111 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 05 August 2017 - 05:32 PM

You could also assume that any 350 Mb (since most new PC's run Windows 10 with a default install) in size (FAT32 if GPT or NTFS if MBR) volume is the right one, so just check for a volume that is 350 Mb in size and be done with it. :whistling:

Will be nice. But AFAIR, When I was using Win 7, then size of 'System Reserved' partition in my Dell Inspiron 1545 was only '100 MB' ? Does size of 'System Reserved' partition is related total size of Disk 0 ? Does 'Win 7' always create 'System Reserved' partition of 100 MB ?

Should not i look for a partition having size 350 MB or lower ?

Should not I also check for /boot/BCD in case there is no 350 MB partition in MBR Disk0. And boot partition and installation are the same ? 



#112 paraglider

paraglider

    Gold Member

  • .script developer
  • 1716 posts
  • Location:NC,USA
  •  
    United States

Posted 05 August 2017 - 09:56 PM

Its 500mb on my windows 10 dell laptop. For a GPT disk there is a unique embedded guid that determines the volume type. Diskpart will show it as system in the final column of the list volume output.



#113 Zharif

Zharif

    Frequent Member

  • .script developer
  • 149 posts
  • Location:Germany
  •  
    Germany

Posted 06 August 2017 - 09:14 AM

On my Toshiba KIRA and Samsung 530-U3C Ultrabooks (GPT and MBR) with a clean win10 install it is alway 100mb (after removing manufacturer default configurations). Original sizes were 100mb and 350mb resprectively. For me, they're always signed as "System" in the Info-column of diskpart. I'm able to confirm that you don't have to trust the volume label as shown e.g. in diskpart. In my experience, during several OS installations I made on these laptops, windows changed/removed the volume labels without any user intervention.

So, sizes may change but the info column denotation seems to remain unchanged in diskpart (but this is not really verified).

 

You've been provided the appropriate loop for diskpart, the searchstring (system or System?) as well as as the appropriate "search field" (Info=71,8). It should be quite easy for you to add this to your :FREEDRIVE routine (or wherever you think it belongs to).

Please consider that searching for the word "system" is still localised.

It is also questionable if the Info "(S)system" is a "fixed" (localised) denotation for diskpart.

 



#114 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 06 August 2017 - 10:37 AM

And AGAIN it is WRONG to look for "System" or "System Reserved" as a volume LABEL, NOR looking for it as the value in the "Info" (last) column of Diskpart "list volume".

 

Everyone is of course free :) to use that method to determine which is the "system" volume, and of course everyone is also free to suggest it as a surely working method, but it isn't.

 

The "System" in diskpart view is present (called "Sistema" in Italian) ONLY from the "booted OS", it won't be there when a PE (or another OS) is booted.

In a PE this would normally be seen as "Hidden" (with all the issue of different names in different languages) and in any case this would apply only when the "system" and "boot" are distinct volumes.

https://docs.microso...top/winpe-intro

dep-blue-winpe-overview.png

 

The "right way" is for GPT to look for the appropriate GUID, as paraglider suggested.  :thumbup: [1]

 

The "right way" for MBR is more complex.

Being an active partition is a hint (but not a proof).

Being a very small partition (100, 200, 300 or 350 Mb) is a hint (not a proof) and ONLY valid when the OS is installed with a separate "boot" and "system" partition.

Dinding a \BOOTMGR is a hint (not a proof).

Finding a \boot\BCD is a hint (not a proof).

Analyzing the contents of the \Boot\BCD AND comparing (if present) the info in there with the Dosdevices keys of the Registry of the OS might be a proof.

 

BUT IF:
1) an Active partition is found

2) AND the MBR code is the standard Windows one

3) AND the PBR code is the standard Windows one

4) AND a BOOTMGR is found in root of the active partition

5) AND a \boot\BCD is found in root of the active partition

THEN it is a "standard" windows install (no matter if one with "system" and "boot" in the same volume or in two separate volumes).

 

If any of the 5 above tests fail, then it is not a "standard" setup and could be any among several different non-standard setups.

 

 

:duff:

Wonko

 

 

 

[1] and still there might be the case of the UMBR or other "Windows on BIOS GPT" setup, very rare, but possible.

So, besides the GPT GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B one needs to make sure that the GPT protective MBR has no code.

And - to be picky - the right GPT GUID only means that that volume will be searched by the UEFI for one of the UEFI bootloaders/bootmanagers, not entirely unlike to whaat "just checking for the active partition" does on MBR so you may well have (say) GRUB2 on that volume that then chainloads a BOOTMGR.EFI and a \EFI\MICROSOFT\BOOT\BCD *somewhere else* so a similar multi-point list would probably be needed for GPT as well.


  • devdevadev likes this

#115 Zharif

Zharif

    Frequent Member

  • .script developer
  • 149 posts
  • Location:Germany
  •  
    Germany

Posted 06 August 2017 - 02:49 PM

Thanks much for your explaination and provided procedure.

I went on search and to make things more "confusing" I found this diskpart output for one of my vm's:

(drive layout MBR; booted from Win10PESE). Size here is 500mb. System partition is NOT hidden.

BTW, for me it's never hidden when trying to boot via Win10PESE in a virtual machine.

x:\windows\system32>diskpart

Microsoft DiskPart-Version 10.0.14393.0

Copyright (C) 1999-2013 Microsoft Corporation.
Auf Computer: Win10PESE

DISKPART> list vol

  Volume ###  Bst  Bezeichnung  DS     Typ         Größe    Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     Y   Win10PESE    UDF    DVD-ROM     2773 MB  Fehlerfre
  Volume 1     D   System-rese  NTFS   Partition    500 MB  Fehlerfre
  Volume 2     C                NTFS   Partition     59 GB  Fehlerfre

DISKPART> list disk

  Datenträger ###  Status         Größe    Frei     Dyn  GPT
  ---------------  -------------  -------  -------  ---  ---
  Datenträger 0    Online           60 GB      0 B

DISKPART>

Just for record, this is the output of diskpart for my Toshiba KIRA that confirms Wonkos explainations

(drive layout GPT; bootet from Win10PESE):

x:\windows\system32>diskpart

Microsoft DiskPart-Version 10.0.14393.0

Copyright (C) 1999-2013 Microsoft Corporation.
Auf Computer: MININT-PEDO97

DISKPART> list vol

  Volume ###  Bst  Bezeichnung  DS     Typ         Größe    Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     Y   Win10PESE    UDF    CD          2773 MB  Fehlerfre
  Volume 1     C                NTFS   Partition    119 GB  Fehlerfre
  Volume 2     D   Data         NTFS   Partition    107 GB  Fehlerfre
  Volume 3         Wiederherst  NTFS   Partition    450 MB  Fehlerfre  Versteck
  Volume 4                      FAT32  Partition    100 MB  Fehlerfre  Versteck
  Volume 5     E   Recovery     NTFS   Partition     10 GB  Fehlerfre  Versteck

DISKPART>


#116 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 06 August 2017 - 04:41 PM

Yep, and most probably various PE versions will show different things.

 

The "boot" volume (that the good MS guys insist on calling "system") is (if NTFS) often given a partition ID of 0x27 (which is NOT technically a "hidden" partition ID, that would be 0x17 or "normal" partition ID 0x07+0x10).

 

https://technet.micr...itionStructures

 

But in a number of cases the use of various disk/volume related utilities may have made that a "normal" 0x07 (and the lack of drive letter asssignment set in the Registry or simply "allowed" for convenience).

 

:duff:

Wonko

 



#117 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 07 August 2017 - 05:04 AM

In Full Windows OS, WinNTSetup assigns the Z:\ to 'System Reserved' partition as a dosdevice, so disk management or unelevated explorer will not show it. But in case of WinPE (where 'System Reserved' already have drive letter assigned) how WinNTSetup detect and get drive letter of 'BOOT PARTITION *(normally 'System Reserved') is KEY point here ? According to JFX
 

for MBR disk scheme there is only 1 active primary partion 
for EFI there is only 1 partition which have the PARTITION_SYSTEM_GUID guid.

 

IF:

1) an Active partition is found

2) AND the MBR code is the standard Windows one

3) AND the PBR code is the standard Windows one

4) AND a BOOTMGR is found in root of the active partition

5) AND a \boot\BCD is found in root of the active partition

THEN it is a "standard" windows install (no matter if one with "system" and "boot" in the same volume or in two separate volumes).

 

If any of the 5 above tests fail, then it is not a "standard" setup and could be any among several different non-standard setups.

I have opened 'WinNTSetup' within WinPE (HKBOOT 2017) and seen that it also detect Drive Letter of 'System Reserved' partition of Disk 0 within WinPE environment.  It's looking WinNTSetup approach is exactly the same as Wonko mentioned in above points. Will be nice If we found what exactly 'WinNTSetup' look in MBR* and GPT systems to automatically detect drive letter of BOOT PARTTITION (normally 'System Reserved'). So that we can do exactly the same thing with command prompt ?

 

System_Reserved.png

Does RED highlighted section in above screenshot give any info about what WinNTSetup look in MBR Disk0 to find 'Boot Partition' ?



#118 cdob

cdob

    Gold Member

  • Expert
  • 1337 posts

Posted 07 August 2017 - 10:20 PM

Well, which kind of machines do you like to support?
Machines, you know very well, self installed ones?
With a typically installation? Created by regular setup, not prepared by WinNTSetup.
Unknown ones, with strange installations?

There is no way to create 100 per cent solution.
Do you accept a 50 per cent, a 90 per cent or 99 per cent solution?
Of course the numbers are guessed only, true values will differ.

Be aware, you may destroy data.

E.g. disk 0 is a good guess. Booting a PE the ording may be changed.
The PE may miss drivers for the RAID controller. A second data disk gets disk 0.

A PE mounts a 'System Reserved' MBR partiton by default, but not a EFI GPT partiton.

At BIOS mode you may assume a MBR disk. At UEFI mode you may assume a GPT disk.
A hard disk may be at GPT, the booted PE at BIOS or UEFI mode. Or vice versa.
In addition there are ways to break default setttings http://reboot.pro/to...in-bios-to-gpt/
A multi operating boot gives a nightmare at automac detection.

The EFI partiton should be GUID c12a7328-f81f-11d2-ba4b-00a0c93ec93b
https://en.wikipedia...Partition_Table

Given a seldom UEFI with NTFS drivers embedded, the FAT32 EFI parttion may be missing.
EFI files could be at the \windows\ partition.

Assuming GUID c12a7328-f81f-11d2-ba4b-00a0c93ec93b and free letter s:
 
@echo off
FOR /L %%a IN (1,1,9) DO (echo sel disk 0
echo sel par %%a
echo det par ) | diskpart.exe | find.exe /I "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && (
 echo disk 0 partition %%a
 (echo assign letter=S 
 ) | diskpart.exe
)
This is a example to show the idea, not to be copied verbatim.
  • devdevadev likes this

#119 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 08 August 2017 - 05:15 AM

I will support at least 90% machines either having regular setup or setup prepared by WinNTSetup and any other setup as long as having a 'Boot Partition *(/boot/BCD or /EFI/Microsoft/boot/BCD)' and 'Installation Partition (\Windows\explorer.exe)'.

 

As I will use ChrisR 'Win10SEPE' which I think is best WinPE ? In case if second data disk gets 'Disk0', then NO Problem. I will always first check if Disk0 have any 'Boot Partition' and 'Windows Installation' partition. If they exist then I will do automatic backup of User directory folders and then do format of 'OS partition' and re-install of Windows otherwise I will use manual Installation using WinNTSetup for any ODD/Unknown/Strange Installation.



#120 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 08 August 2017 - 01:59 PM

Meantime on MSFN:

http://www.msfn.org/...comment=1142559

 

we have a brand new DLEDIT.EXE thanks to JFX :thumbup: :

http://www.msfn.org/...comment=1142580

 

 (and a listdevices.cmd, just in case).

 

:duff:

Wonko



#121 cdob

cdob

    Gold Member

  • Expert
  • 1337 posts

Posted 09 August 2017 - 08:14 PM

I will support at least 90% machines ... otherwise I will use manual Installation

Yes, it's a godd idea to limit a script to default configurations.
And do exceptions manually.

Define simple rules first.
assume disk 0
assume a active partition at MBR disk, no need to verify
Search one boot partition and one installation partition.
Break if there are double finds.


Simple, brute force, half broken design, should work at 90% machines:

Assume disk 0
Try to mount "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" always, ignore a error if it's missing.

set 'Boot_BIOS' to zero.
set 'Boot_EFI' to zero.
set 'Installation Partition' to zero.

Search at disk 0:
Boot Partition /boot/BCD. Count the Boot_BIOS Partition's.
Boot Partition /EFI/Microsoft/boot/BCD. Count the Boot_EFI Partition's.
'Installation Partition (\Windows\explorer.exe)'. Count the Installation Partition's.

Backup the data.

Breal, if zero or greater one 'Installation Partition'

Calculate Boot_found = Boot_BIOS + Boot_EFI
Break, if zero or greater one 'Boot_found'
E.g. BIOS and EFI mode at the same disk. Or two /boot/BCD at disk 0.

Verify the backup data manually. Break, if data are missing.
Format the partitons manually.

Apply a install.wim to the 'Installation Partition'
If Boot_BIOS equal 1 write BIOS boot data to the 'Boot Partition'.
If Boot_EFI equal 1 write EFI boot data to the 'Boot Partition'.

#122 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 10 August 2017 - 11:08 PM

BIOS and EFI mode at the same disk.

I think this is common when we do windows installation using WinNTSetup as default setting ? It uses /bcd:{ALL} as default. So there should be no problem if both BIOS and EFI files are within same Boot Partition ?



#123 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 12 August 2017 - 04:46 PM

@echo off
FOR /L %%a IN (1,1,9) DO (echo sel disk 0
echo sel par %%a
echo det par ) | diskpart.exe | find.exe /I "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && (
 echo disk 0 partition %%a
 (echo assign letter=Z
 ) | diskpart.exe
)

SET SYSPART=
SET OSPART1=
SET OSPART2=
SET SOURCEVOL=
FOR %%w IN (C D E F G H I J K L N M O P Q R S T U V W Y Z) DO (
IF EXIST %%w:\boot\BCD SET SYSPART=%%w:
IF EXIST %%w:\EFI\Microsoft\boot\BCD SET SYSPART=%%w:
IF NOT "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe SET OSPART2=%%w:& SET SOURCEVOL=!OSPART2!& CALL :START_BACKUP
IF "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe SET OSPART1=%%w:& SET SOURCEVOL=!OSPART1!& CALL :START_BACKUP
)

This search all Drive Letter for Boot partition and OS partition. I want to search drive letters of only Disk 0 ? Is there any way to do so with diskpart ?



#124 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13690 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 12 August 2017 - 05:14 PM

FOR /L %%a IN (1,1,9) DO (echo sel disk 0
echo sel par %%a
echo det par ) | diskpart.exe


 
That selects disk 0 ... then ....

The idea is that you understand the snippet by cdob (which is about GPT) and adapt it.

You were already taught how to make a list of volumes by parsing the output of "list volumes" in diskpart.

Now find your way to do the same from the output of the above snippet.

 
:duff:
Wonko

#125 devdevadev

devdevadev

    Frequent Member

  • Advanced user
  • 406 posts
  •  
    India

Posted 13 August 2017 - 04:25 AM

Thanks 'Wonko'...

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET INTERNAL=
SET SYSPART=
SET OSPART1=
SET OSPART2=
SET SOURCEVOL=

FOR /L %%a IN (1,1,9) DO (echo sel disk 0
echo sel par %%a
echo det par ) | diskpart.exe | find.exe /I "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && (
 echo disk 0 partition %%a
 (echo assign letter=Z
 ) | diskpart.exe
)

FOR /L %%A IN (1,1,9) DO (
FOR /F "delims=*" %%B IN ('
^(
ECHO SEL DISK 0^&ECHO SEL PAR %%A^&ECHO DET PAR
^)^|DISKPART^|FIND "*" 
') DO CALL :parse_volumes %%B
)

FOR %%w IN (%INTERNAL%) DO (
IF EXIST %%w:\boot\BCD SET SYSPART=%%w:
IF EXIST %%w:\EFI\Microsoft\boot\BCD SET SYSPART=%%w:
IF NOT "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe SET OSPART2=%%w:& SET SOURCEVOL=!OSPART2!& CALL :START_BACKUP
IF "!OSPART1!"=="" IF EXIST %%w:\Windows\explorer.exe SET OSPART1=%%w:& SET SOURCEVOL=!OSPART1!& CALL :START_BACKUP
)

ECHO %INTERNAL%
ECHO %SYSPART%
ECHO %OSPART1%
ECHO %OSPART2%
PAUSE

:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET INTERNAL=!INTERNAL! %Line:~13,1%
GOTO :EOF

Output-

 Z C H F G
Z:
C:
ECHO is off.

Any suggestions PLEASE...!!!

 

Can we not use something like ???

FOR /L %%A IN (1,1,9) DO (
FOR /F "delims=*" %%B IN ('
^(
ECHO SEL DISK 0^&ECHO SEL PAR %%A^&ECHO DET PAR
^)^|DISKPART^|FIND "*" 
') DO SET INTERNAL=!INTERNAL! %%B:~13,1
)






Also tagged with one or more of these keywords: cmd, winpe, boot.wim, usb booting, multibooting

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users