Jump to content

Need help: Partition order windows UEFI


congnt92

Recommended Posts

Hi everyone,

I'm sorry for my bad English and I'm sorry again if this box is not right place to create this topic.

 

I'm creating .bat file will mount EFI partition by diskpart. But I'm not sure what partition order in Windows UEFI

 

By default, this order is

 

Par1: WinRE

Par2: EFI

Par3: Microsoft system reserved

Par4: May recovery partition or C:

 

If EFI is always par1 or par2, then I will create .bat like that

 

echo select disk 0 > par.txt

echo select partiton 2 >> par.txt

echo assign letter = S: >> par.txt

diskpart /s par.txt

copy abc.efi  to S:\EFI\Boot

 

But problem is, I'm not sure that EFI is always par1 or par2 or even par3.... par n.

Can anyone have any idea ? How to detect EFI par if user do not use default partition order??

Tks :)

Edited by congnt92
Link to comment
Share on other sites


Sure, partition order is NOT compulsory.

But the EFI System partition (the FAT32 formatted one containining the EFI bootmanager will always be of the EFIsys type.

 

Something like this:

http://stackoverflow.com/questions/8714675/how-to-detect-if-efi-partition-is-already-mounted-in-windows-via-batch-script

might do nicely.

 

JFYI, and as a side note, there is a trick to avoid making the temporary file to feed commands in diskpart, see here:

http://www.msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/

http://www.msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/?p=817388

You can find here another example of the technique:

http://www.msfn.org/board/topic/173642-mkprilog-batch-to-access-a-same-disk-under-two-different-interfaces/

 

jaclaz

Link to comment
Share on other sites

Sure, partition order is NOT compulsory.

But the EFI System partition (the FAT32 formatted one containining the EFI bootmanager will always be of the EFIsys type.

 

Something like this:

http://stackoverflow.com/questions/8714675/how-to-detect-if-efi-partition-is-already-mounted-in-windows-via-batch-script

might do nicely.

 

JFYI, and as a side note, there is a trick to avoid making the temporary file to feed commands in diskpart, see here:

http://www.msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/

http://www.msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/?p=817388

You can find here another example of the technique:

http://www.msfn.org/board/topic/173642-mkprilog-batch-to-access-a-same-disk-under-two-different-interfaces/

 

jaclaz

 

Oh, I was found that link before create this topic. But it is not same with my problems.

That is detect if EFI partition was assign a letter for it.

Mine is how to determine what is EFI partition number to select it from diskpart then use diskpart to assign a letter.

If there is no way to do that, may I must create a semi-automatic .bat

- Ask some one use disk manager to check EFI partition number, it's FAT32, label is system, size about 100Mb, ... then if it is partition 2 (show as disk manager) then

- type 2 to .bat prompt then .bat will run diskpart sel disk 0 sel par 2 assign letter=s and copy file to here ...

I hope that it's last solution. But now maybe it's only one solution.

 

---

About running diskpart without need a config file I will try it. Many tks for greate guide, Jaclaz.

Link to comment
Share on other sites

Oh, I was found that link before create this topic. But it is not same with my problems.

That is detect if EFI partition was assign a letter for it.

Mine is how to determine what is EFI partition number to select it from diskpart then use diskpart to assign a letter.

 

Sure, it is not EXACTLY what you want, but it does show you an EXAMPLE on how to parse the diskpart list volume.

An EXAMPLE is something that you need to ADAPT to your needs.

In this specific case, the diskpart  command is a single one, so a simpler pipe should do:

Try on your system running this and post the output:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND /I "efisys"') DO ECHO %%A

I havent' handy a winows 7 or later system with a EFI/GPT disk to check the output of diskpart, this might also do:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND "FAT32"^|FIND /I "System"') DO ECHO %%A

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

 

Oh, I was found that link before create this topic. But it is not same with my problems.

That is detect if EFI partition was assign a letter for it.

Mine is how to determine what is EFI partition number to select it from diskpart then use diskpart to assign a letter.

 

Sure, it is not EXACTLY what you want, but it does show you an EXAMPLE on how to parse the diskpart list volume.

An EXAMPLE is something that you need to ADAPT to your needs.

In this specific case, the diskpart  command is a single one, so a simpler pipe should do:

Try on your system running this and post the output:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND /I "efisys"') DO ECHO %%A

I havent' handy a winows 7 or later system with a EFI/GPT disk to check the output of diskpart, this might also do:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND "FAT32"^|FIND /I "System"') DO ECHO %%A

jaclaz

 

 

Run both code it just pop up diskpart dialogue, not display or run anything

My diskpart list volume in case you need

 

 Volume ###  Ltr  Label        Fs     Type        Size     Status     Info

  ----------  ---  -----------  -----  ----------  -------  ---------  --------

  Volume 0     J                       DVD-ROM         0 B  No Media

  Volume 1     C   WINDOWS 10   NTFS   Partition     70 GB  Healthy    Boot

  Volume 2     G   UBUNTU       FAT32  Partition     14 GB  Healthy

  Volume 3     D   BACKUP       NTFS   Partition    100 GB  Healthy

  Volume 4     E   DATA         NTFS   Partition     47 GB  Healthy

  Volume 5         Windows RE   NTFS   Partition    300 MB  Healthy    Hidden

  Volume 6         SYSTEM       FAT32  Partition    100 MB  Healthy    System           <<<< EFI Par

  Volume 7     F   HP_TOOLS     FAT32  Partition    700 MB  Healthy    Hidden        

 

 

And if run diskpart list partition

 

Partition ###  Type              Size     Offset

  -------------  ----------------  -------  -------

  Partition 1    Recovery           300 MB  1024 KB

  Partition 2    System             100 MB   301 MB    <<<<< EFI par

  Partition 3    Reserved           128 MB   401 MB

  Partition 4    Primary             70 GB   529 MB

  Partition 5    Primary             14 GB    70 GB

  Partition 6    Primary            100 GB    85 GB

  Partition 7    Primary             47 GB   185 GB

  Partition 8    Recovery           700 MB   232 GB

 

list partition not the same list vol.

Edited by congnt92
Link to comment
Share on other sites

This should work then:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND "FAT32"^|FIND /I "System"') DO ECHO %%A

 

Maybe it is another issue with copy/paste through the board? :unsure:, it should "filter" the only line with both "FAT32" and "System" in it.

Try separating the issues:

ECHO list volume|Diskpart>result.txt

TYPE result.txt|FIND "FAT32"

TYPE result.txt|FIND /I "System"

TYPE result.txt|FIND "FAT32"|FIND /I "System"

 

jaclaz

Link to comment
Share on other sites

This should work then:

FOR /F "tokens=* delims= " %%A IN ('ECHO list volume^|diskpart^|FIND "FAT32"^|FIND /I "System"') DO ECHO %%A

 

Maybe it is another issue with copy/paste through the board? :unsure:, it should "filter" the only line with both "FAT32" and "System" in it.

Try separating the issues:

ECHO list volume|Diskpart>result.txt

TYPE result.txt|FIND "FAT32"

TYPE result.txt|FIND /I "System"

TYPE result.txt|FIND "FAT32"|FIND /I "System"

 

jaclaz

 

Oh i'm sorry. Your code work fine, even very perfect. All i need is run as admin .bat file.

I think that just need to turn off UAC then reboot but no luck. Must run as admin.

Now, there only one thing that i'm not sure. it's using "system" (in info column) to get EFI partition.

Can we say that: Microsoft EFI partition is always show as "system" (in info column) by diskpart ??

Link to comment
Share on other sites

Can we say that: Microsoft EFI partition is always show as "system" (in info column) by diskpart ??

As often happens, yes and no. :w00t:

It is IF seen from the booted OS from that disk.

The "System" or "Boot" in the "Info" column are not a "fixed" attribute, if you boot another OS (from another media/device) that volume will be a volume like any other one with no such attribute.

Looking for cAsE UnSeNsItIve string "System" might work in your case because also the volume label is "SYSTEM", but cannot say if this is a (recent) Windows "standard", in any case, if you have more that one disk with independent Windows installs this latter "feature" may be unwanted. :unsure:

jaclaz

Link to comment
Share on other sites

 

Can we say that: Microsoft EFI partition is always show as "system" (in info column) by diskpart ??

As often happens, yes and no. :w00t:

It is IF seen from the booted OS from that disk.

The "System" or "Boot" in the "Info" column are not a "fixed" attribute, if you boot another OS (from another media/device) that volume will be a volume like any other one with no such attribute.

Looking for cAsE UnSeNsItIve string "System" might work in your case because also the volume label is "SYSTEM", but cannot say if this is a (recent) Windows "standard", in any case, if you have more that one disk with independent Windows installs this latter "feature" may be unwanted. :unsure:

jaclaz

 

OK, tks for your hint. Label SYSTEM may can be edit by some partition tool (not sure). But i think that system (in info column) is fixed and not any tool can change this.

And as you say, it may change with latter Windows OS, or it may change when boot from another OS (WinPE ??), so i must add some conditions to .bat to make sure that, user only run .bat from within Windows 7 or above (and of course, with GPT disk).

And may I need to add "if exist" command, after mount EFI partition (that say S:), then check if exist S:\EFI\Boot\microsoft\bcd to make sure.

Thank you very much, Jaclaz. :thumbup :thumbup

Edited by congnt92
Link to comment
Share on other sites

Please note that I am saying something slightly different.

If you have one disk (GPT) with a UEFI Windows installed on the default EFIsys type partition, if you run the command from that booted OS (the one that was booted from that disk) then you will have the "System" in "Info".

If you boot a PE from (say) CD/DVD, there won't be a "System" in "Info" (and then the label of "SYSTEM" might be of use).

But if you have two disks, each with a EFIsys partition you will have a problem as two volumes with FAT32 in Fs and with EITHER "SYSTEM" as label OR "System" in "Info" will be found and listed.

And BOTH will have a \EFI\Boot\microsoft\bcd in them.

So you may need to LIST DISKs, and then DETAIL each of them.

jaclaz

Link to comment
Share on other sites

I'm creating .bat file will mount EFI partition by diskpart. But I'm not sure what partition order in Windows UEFI

How many disks do you use at one machine?

Did you boot windows from this UEFI disk?

mountvol.exe S: /S
.

Did you like to support another disk, not booted from this one?

The specs request a EFI system partition GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B https://en.wikipedia.org/wiki/EFI_system_partition

There may be two hard disks with this GUID at one machine.

Link to comment
Share on other sites

Please note that I am saying something slightly different.

If you have one disk (GPT) with a UEFI Windows installed on the default EFIsys type partition, if you run the command from that booted OS (the one that was booted from that disk) then you will have the "System" in "Info".

If you boot a PE from (say) CD/DVD, there won't be a "System" in "Info" (and then the label of "SYSTEM" might be of use).

But if you have two disks, each with a EFIsys partition you will have a problem as two volumes with FAT32 in Fs and with EITHER "SYSTEM" as label OR "System" in "Info" will be found and listed.

And BOTH will have a \EFI\Boot\microsoft\bcd in them.

So you may need to LIST DISKs, and then DETAIL each of them.

jaclaz

 

Oh, Sorry for my confusion and thanks for the clarification.

 

 

 

I'm creating .bat file will mount EFI partition by diskpart. But I'm not sure what partition order in Windows UEFI

How many disks do you use at one machine?

Did you boot windows from this UEFI disk?

mountvol.exe S: /S
.

Did you like to support another disk, not booted from this one?

The specs request a EFI system partition GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B https://en.wikipedia.org/wiki/EFI_system_partition

There may be two hard disks with this GUID at one machine.

 

 

 Your question may same with Jaclaz. Thank you, too.

 

So I think problem is simple, but it does not. As both of you say, I have to create a .bat in "general" way.

I create .bat from my Windows, from my laptop, and test from my laptop. It work fine for me but not sure that it will work with others.

 

Now may I will create a .bat which only allow user copy .efi file to EFI partition of hard disk which user boot from. Not boot from this harddisk then install some .efi boot menu (Ubuntu,...) to another hard disk.

 

But can I have a question?

 

If we have 2 (or 3 ...) hard disk with 2 case

- case1: both of hard disk is internal hard disk (HDD + SDD), then if we boot windows from HDD, diskpart will say HDD is disk 0 ??

- case2: if one is internal and one is external, then if we boot Windows from External, diskpart will say external is disk 0 or disk 1 ??

 

Tks all of you for your enthusiasm.

 

Edit: to cdob, tks for your hint but i found that mountvol not have /s parameter. Run from windows 10.

Edited by congnt92
Link to comment
Share on other sites

Now i recreate .bat file. It something like

- detect if user boot from real windows, not WinPE (just to make sure diskpart will show EFI par is system in info label)

- detect if user run .bat from windows which boot with UEFI mode. Base on this

if that's true next to step 3, exit if fail

- if windows boot with UEFI mode, then of course always have at least 1 EFI partition found and of course it is in harddisk which current windows running  and .bat will continue

- check to get order of EFI partition by combo "for /f  command"  + "diskpart" (tks to Jaclaz). (Jaclaz hint using signal SYSTEM label to detect but i worry about this label can be change by some partition tool, system in info column is shown by diskpart, it may cannot be change ??? )

- count EFI partition

+) if only 1 EFI partition found >> mount it as S: recheck to make sure it is EFI by EFI\Boot\Microsoft\BCD file

+) if there are more than 1 EFI par found >> echo more than 1 EFI par found !! this .bat will only copy .efi file to EFI partition of disk 0 (which windows boot from current ??) >> ask user for make sure, type Y to continue, type N to exit.

 

Can both of you give me some advices about my ideal ?? Such as it's will not work in some case (which case), or how can I improve this ideal ??

Tks :)

 

p/s: To cdob: Using EFI system partition GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B to detect EFI partition is a safety way but I do not know which command to get GUID of partition.

Edited by congnt92
Link to comment
Share on other sites

I will try again.
The data in the "Info" column in diskpart DOES NOT EXIST :w00t:, it is generated dynamically.
You can have n disks each with a FAT32 EFIsys partition, but only one partition on one disk will have the "System" tag in diskpart, the one that was actually used for booting the running system or, if you booted (say) a PE of some kind, NONE of them will have that tag.

Each of the FAT32 EFIsys partition on each of the n disks may instead have a "SYSTEM" label, which UNLIKE the "Info" is a "static" value.

 

So, looking for the "System" tag in "Info" can return one or no result, while looking for "SYSTEM" in "Label" may return more than one result.

 

I hope now the point is more clear.

 

jaclaz

Link to comment
Share on other sites

I will try again.

The data in the "Info" column in diskpart DOES NOT EXIST :w00t:, it is generated dynamically.

You can have n disks each with a FAT32 EFIsys partition, but only one partition on one disk will have the "System" tag in diskpart, the one that was actually used for booting the running system or, if you booted (say) a PE of some kind, NONE of them will have that tag.

Each of the FAT32 EFIsys partition on each of the n disks may instead have a "SYSTEM" label, which UNLIKE the "Info" is a "static" value.

 

So, looking for the "System" tag in "Info" can return one or no result, while looking for "SYSTEM" in "Label" may return more than one result.

 

I hope now the point is more clear.

 

jaclaz

 

As you say, I test diskpart list vol from WinPE, now it say that, EFI partition is Hidden (in Info column). So i must have some lines to detect if user run .bat from winPE. It must be run in real Windows, and diskpart will show as system.

About label SYSTEM, you're right again. diskpart still say SYSTEM in label column. But i run partition wizard and change this label to SYSTEM1 and boot again to windows 10, run diskpart, it say that label is SYSTEM1.

So, SYSTEM label is can be change if user want. system in info column is change to hidden when run diskpart from winPE.

>> Only one way is .bat must be run from real windows.

And now, only 1 problem as you and cdob say, in case computer has 2 disk. I think I must hard code that .bat will copy .efi file to disk0. But not sure what disk0 means in computer has 2 disk.

Edited by congnt92
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...