Jump to content











Photo
- - - - -

How to delete a partition (ptn3) from MBR Partition Table of Removable USB Drive using Command Line Tools ?

edit mbr partition table removable usb drive hidden partition command line

  • Please log in to reply
16 replies to this topic

#1 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 11 April 2017 - 11:32 PM

There are 3 partitions in my Removable USB Drive. I want to delete/remove Partition 3 *(hidden) entry from MBR Partition Table of Removable USB Drive by using .cmd batch file in minimal WinPE Environment.

 

Is there any command line tool that will do exactly the same thing as following grub4dos partnew command do ?

 

partnew (hd0,2) 0 0 0 0

 

I am looking for It's equivalent code which I can keep in my batch file...

 

Thanks & Regards...



#2 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 13 April 2017 - 10:04 AM

You'll need a batch using a few tools.

 

More or less you want to:

1) duplicate the MBR (first sector of the device) to a file

2) hexedit the file at offset 446+PartSlot#*16, for slot #2, that will be 446+2*16=478 writing 16 00's

3) restore the file to the MBR

 

this is loosely:

dsfo \\.\Physicaldriven 0 512 c:\temp.mbr

hexalter C:\temp.mbr 0x01DE=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

dsfi \\.\Physicaldriven 0 512 C:\temp.mbr

del C:\temp.mbr

 

Or (easier) you can use the Freeware MBRWizard command line:
http://firesage.com/mbrwizard.php?x=4

that would be:

mbrwiz /Disk=n /Part=3 /Del

 

:duff:

Wonko



#3 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 13 April 2017 - 12:42 PM

Thanks for introducing very Nice CLI Tool...

 

What if I want to copy curretn MBR to Sector LBA32 before deleting PTN3 ? And then want to copy MBR to sector LBA24 just after deleting PTN3 ?

 

mbrwiz /Disk=n /copy x,y ??



#4 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 13 April 2017 - 03:20 PM

Should be:

mbrwiz /Disk=n /save=mbr /32

or:

mbrwiz /Disk=n /copy /source=0 /target=32

but you'll have to test.

 

:duff:

Wonko



#5 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 13 April 2017 - 05:06 PM

I want to get Disk Number %DD% of connected Removable USB Drive in WinPE Environment. If there are multiple USB Drives Connected then get the Disk Number of Removable USB with 'DEV' volume. Is there any native way to implement the same without any third party CLI tool ? I know It can be done with the help of RMPARTUSB.exe . But a logic with smallest code will be better to use ?



#6 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 April 2017 - 06:12 PM

What about just finding the drive with 'DEV' as a volume name? Would that be good enough?



#7 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 05:52 AM

What about just finding the drive with 'DEV' as a volume name? Would that be good enough?

Finding Physical Drive number from Volume name 'DEV' under WinPE will also be better....
Which smallest code can find Physical Drive Number from Volume Name 'DEV' ?


#8 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 14 April 2017 - 11:54 AM

If you want ONLY "native" tools (and NO third party tools) for *whatever* reasons, that's perfectly fine :thumbsup:

 

But if you already *need*  a third party tool for doing "chore #1", why not using that same tool to do "chore #2"?

 

What happens if you run:

mbrwiz /vol=DEV /list | FIND "Disk:"

 

:duff:

Wonko



#9 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 12:40 PM

mbrwiz /vol=DEV /list | FIND "Disk:" DO Set myDrive=Disk 

 

Don't know what is correct way to Set myDrive=Disk in above command ?? Something what we use in native codes ?

 

P.S. 'E2B' is the volume name of PTN2 (hidden) of my Removable USB Drive..And I have seen that MBRWiz can also get Disk Number from 'E2B' volume name (which I will definitely assign to PTN2). So now I will use only following code to get Drive Number of my Removable USB Drive...I have got something what I am just expecting to be possible !!!

 

mbrwiz /vol=E2B /list | FIND "Disk:"



#10 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 14 April 2017 - 01:23 PM

Well, as always, it's not like you can "Invent" batch syntax, you have to study and understand it, then experiment.

 

To assign a variable from an output you need a FOR /F loop and some characters inside a FOR /F command needs to be escaped.



@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
FOR /F "tokens=2 delims= " %%A IN ('mbrwiz /vol^=DEV /list ^| FIND "Disk:"') DO Set myDrive=%%A
SET myDrive

:duff:

Wonko



#11 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 01:41 PM

SET myDrive

Is last line also necessary ? Is it valid ? 

 

Should It not be as follows before FOR /F line ?

 

SET myDrive=



#12 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 02:05 PM

Thanks 'Wonko' for your great help and support in grasping CLI Tools....

Finally I will use following 'UEFI.cmd' in order to delete PTN3 of my Removable USB Drive in WInPE environment to Disable UEFI in my SMART USB whenever necessary...

 

UEFI.cmd -

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
color 1f
cls
pushd "%~dp0"
set myDrive=
set mbrwiz=mbrwiz.exe
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" set mbrwiz=mbrwiz64.exe
FOR /F "tokens=2 delims= " %%A IN ('%mbrwiz% /vol^=E2B /list ^| FIND "Disk:"') DO Set myDrive=%%A
IF NOT DEFINED mydrive ECHO Oh, oh, no volume with label "E2B" was found&PAUSE
%mbrwiz% /Disk=%myDrive% /save=mbr /32
%mbrwiz% /Disk=%myDrive% /Part=3 /Del
%mbrwiz% /Disk=%myDrive% /save=mbr /24
exit


#13 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 02:20 PM

I want to reduce size of Windows 10 'boot.wim' as smaller as possible to just execute above 'UEFI.cmd'. What tool I will need in order to reduce size of 'boot.wim' ? And what Index/Files/Foders of mounted 'boot.wim' I will have to remove ?



#14 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 14 April 2017 - 02:21 PM

You need to use %mbrwiz%  in last lines, not mbrwiz!



#15 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 14 April 2017 - 02:21 PM

... and NOT mbrfix ...

set mbrwiz=mbrwiz.exe
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" set mbrfix=mbrwiz64.exe

 
:whistling:
 
:duff:
Wonko
  • devdevadev likes this

#16 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 14 April 2017 - 02:28 PM

You need to use %mbrwiz%  in last lines, not mbrwiz!

Sorry...I just forget it...Is it now OK....

 

Thanks..



#17 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 15 April 2017 - 08:52 AM

I would add:

IF NOT DEFINED mydrive ECHO Oh, oh, no volume with label "E2B" was found&PAUSE

 

:duff:

Wonko





Also tagged with one or more of these keywords: edit mbr partition table, removable usb drive, hidden partition, command line

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users