Jump to content











Photo
- - - - -

Is it possible to map ptn3:\uefi-ntfs.img to ptn3 of USB Drive using .cmd batch

uefi-ntfs.img rufus cmd .imgptn partimg

  • Please log in to reply
44 replies to this topic

#26 alacran

alacran

    Gold Member

  • .script developer
  • 2386 posts
  •  
    Mexico

Posted 17 December 2021 - 11:31 PM

All this topic seems to me as an interesting but unnecessary exercise.  And after a month and 24 replies not solved yet.

 

Why to invest time in map uefi-ntfs.img to a (desired) partition?

 

If you can already have it (easily) installed into a 1 MB FAT-16 (same desired) partition, see info on this post.

 

NOTE: For MBR partitioned device it has to be a primary partition.

 

alacran


Edited by alacran, 17 December 2021 - 11:48 PM.


#27 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 17 December 2021 - 11:54 PM

All this topic seems to me as an interesting but unnecessary exercise.  And after a month and 24 replies not solved yet.
 
Why to invest time in map uefi-ntfs.img to a (desired) primary partition?
 
If you can already have it (easily) installed into a 1 MB FAT-16 (same desired) primary partition, see info on this post.
 
alacran


I wish to thank you for your insightful and constructive comment.
I failed to notice how this thread exceeded the time a thread can be non-productive.
I hope you can accept my sincere apologies about my overlooking this essential unwritten rule and that hopefully this unfortunate episode won't affect my annual productivity evaluation card.

:duff:
Wonko

#28 alacran

alacran

    Gold Member

  • .script developer
  • 2386 posts
  •  
    Mexico

Posted 18 December 2021 - 12:45 AM

Hi Wonko, it's nice to talk with you.

 

I was waiting one of your (usual) smart and ironic comments, but this one was very good my friend, you went well beyond my expectatives and made me laugh a lot.

 

Thanks for make me have a nice time.

 

By the way, hope you or any other member/reader can help me about my comment in the post I mentioned:

 

By the way I know dd is a command-line utility for Linux, but I don't know a good program capable to clone uefi-ntfs.img into a device partition in Windows, Any suggestion will be highly appreciated.

 

EDIT: Please any suggestions are welcome in the mentioned post, as I would not like to disturb anymore this topic.

 

alacran


Edited by alacran, 18 December 2021 - 04:57 AM.


#29 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 18 December 2021 - 08:45 AM

CASE1 - dsfo.exe/dsfi.exe


Filename="I:\_ISO\UEFI_NTFS.imgPTNrep3"
Start_LBA=58847640
Length_LBA=2048

Creating my_MBR.mbr and my_PBR.pbr from 1 using dsfo.exe
Press any key to continue . . .

dsfo \\.\PHYSICALDRIVE1 0 512 my_MBR.mbr
OK, 512 bytes, 0.000s, MD5 = 3a2f74201824e5bae4c78af0cc65b11f

dsfo \\.\PHYSICALDRIVE1 65220608 512 my_PBR.pbr
OK, 512 bytes, 0.000s, MD5 = 264e9da486db80e6cd9bf708305c0e88

Patching my_MBR.mbr and my_PBR.pbr using bytepatch.exe
Press any key to continue . . .
loaded "my_MBR.mbr" / 512 (0x200) bytes
replacing byte sequence 80 FE FF FF 07 FE FF FF 00 D8 7A 03 01 18 40 00
                 *WITH* 00 18 E2 FF 06 39 C2 FF 98 F1 81 03 00 08 00 00
successfully patched offset 0x1DE with 16 bytes.
loaded "my_PBR.pbr" / 512 (0x200) bytes
replacing byte sequence 2E A3 58 AD
                 *WITH* 98 F1 81 03
successfully patched offset 0x1C with 4 bytes.

Writing modified my_MBR.mbr and my_PBR.pbr to 1 using dsfi.exe
Press any key to continue . . .

dsfi \\.\PHYSICALDRIVE1 0 512 my_MBR.mbr
OK, written 512 bytes at offset 0

dsfi \\.\PHYSICALDRIVE1 65220608 512 my_PBR.pbr
\\.\PHYSICALDRIVE1 - Access is denied.
Press any key to continue .

CASE2 - dd.exe


Filename="I:\_ISO\UEFI_NTFS.imgPTNrep3"
Start_LBA=58847640
Length_LBA=2048

Creating my_MBR.mbr and my_PBR.pbr from 1 using dd.exe
Press any key to continue . . .

dd.exe if=\\.\physicaldrive1 of=my_MBR.mbr bs=512 count=1
rawwrite dd for windows version 0.3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL.  See copying.txt for details
1+0 records in
1+0 records out

dd.exe if=\\.\physicaldrive1 of=my_PBR.pbr bs=512 count=1 skip=58847640
rawwrite dd for windows version 0.3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL.  See copying.txt for details
1+0 records in
1+0 records out

Patching my_MBR.mbr and my_PBR.pbr using bytepatch.exe
Press any key to continue . . .
loaded "my_MBR.mbr" / 512 (0x200) bytes
ABORT: file already contains desired 16 patch bytes at offset 0x1DE
loaded "my_PBR.pbr" / 512 (0x200) bytes
replacing byte sequence 00 00 00 00
                 *WITH* 98 F1 81 03
successfully patched offset 0x1C with 4 bytes.

Writing modified my_MBR.mbr and my_PBR.pbr to 1 using dd.exe
Press any key to continue . . .

dd.exe if=my_MBR.mbr of=\\.\physicaldrive1 bs=512 count=1
rawwrite dd for windows version 0.3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL.  See copying.txt for details
1+0 records in
1+0 records out

dd.exe if=my_PBR.pbr of=\\.\physicaldrive1 bs=512 count=1 seek=58847640
rawwrite dd for windows version 0.3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL.  See copying.txt for details
Error writing file: 5 Access is denied
1+0 records in
0+0 records out
Press any key to continue . . .

In both CASE1 and CASE2 my_MBR.mbr is sucessfully written and UEFI_NTFS.imgPTNrep3 is successfully mapped to Partition 3 of USB Drive. But in both CASE1 and CASE2, it gives Access Denied error when trying to write my_PBR.pbr to startLBA of UEFI_NTFS.imgPTNrep3 file in USB Drive ?

 

Currently I have to reconnect USB Drive to see the changes. Is there any solution so that changes will be visible without any Disconnecting of USB Drive ? Should I use LockDismount.exe to solve this issue ??

 

Maybe writing my_PBR.pbr will be required only for MBR booting ? And it should not be required for UEFI booting ?

Why I have to face 'Access Denied' error ? Where I am doing WRONG ??

 

Regards..

Attached Files



#30 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 18 December 2021 - 09:45 AM

@devdevadev

On recent windows (Vista and later) the PBR is "protected".

You need to put the volume offline in order to be able to write to it (Lockdismount should do)

http://reboot.pro/in...showtopic=12413

The PBR MUST have correct data, no matter if on MBR or GPT.

 

@alacran

dsfo/dsfi or dd for windows are good correspondent programs to dd in Linux/Unix (particularly dd for windows is an almost perfect replica).

BUT the whole point you missed is that dd (on Linux) is the tool used to copy the (RAW) data, but you need other programs to actually create the partition entry in the MBR (or in the GPT partition table).

If you prefer, devdevadev is trying to assemble in a batch a series of programs that will (hopefully) allow to do in an automated/command line way the WHOLE process described by Akeo, i.e. - albeit too slowly/late by your standards - a direct answer to your questions.

 

:duff:

Wonko



#31 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 18 December 2021 - 01:09 PM

Lots of Thanks to Wonko, Steve Si and alacran for providing great help and support....Finally I successfully mapped PTN3:/_ISO/UEFI_NTFS.imgPTNrep3 to Partition 3 of USB Drive.

 

ImgPart.cmd -

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
SET /A comline=0
FOR %%A IN (MAP HELP) DO IF /I %%A.==%1. SET /A comline=!comline!+1
IF NOT %comline%==1 GOTO :Syntax
GOTO :PARTIMG%1

:Syntax
ECHO.
ECHO %~nx0 batch file to map Partition Image to a Partition entry of USB Drive
ECHO by jaclaz, this file is licensed under my "CAREWARE" license:
ECHO http://home.graffiti.net/jaclaz:graffiti.net/careware.html
ECHO.
ECHO General syntax is %~nx0 COMMAND [parameters], commands are:
ECHO.
ECHO MAP [Disk] [parameters]   - Map Partition Image to a partition of USB Drive
ECHO HELP                      - Displays help for the given command
ECHO.
GOTO :EOF

:DEC2BIN
SET BINnum=
SET DECnum=%1
SET /A Val32768=%DECnum% / 32768
SET /A Mod32768=%DECnum% %% 32768
FOR %%A in (%Powers%) DO CALL:BINcalc %%A
FOR %%A in (%Powers%) DO SET BINnum=!BINnum!!Val%%A!
GOTO :EOF

:BINcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /2
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:BIN2DEC
SET DECnum=
SET BINnum=%1
SET BINLength=%2
Set Counter=0
FOR %%A IN (%Powers%) DO (
CALL :DECcalc %%A
SET /A Counter=!Counter!+1
)
FOR %%A IN (%Powers%) DO SET /A DECnum=!DECnum!+!Digit%%A!*%%A
GOTO :EOF

:DECcalc
SET digit%1=!BINNum:~%Counter%,1!
IF %Counter%==%BINLength% GOTO :EOF
GOTO :EOF

:DEC2hex
SET DECnum=%1
SET Numdig=%2
SET HEXnum=
SET Powers=268435456 16777216 1048576 65536 4096 256 16 1
::=======================================================
::| WARNING! Limit is 2147483647 i.e. 7FFFFFF  WARNING! |
::=======================================================
SET /A Limit=%DECnum%/16
IF %Limit% LSS 0 ECHO Out of Range &GOTO :EOF
SET /A Val268435456=%DECnum% / 268435456
SET /A Mod268435456=%DECnum% %% 268435456
FOR %%A in (%Powers%) DO CALL:HEXcalc %%A
FOR %%A in (%Powers%) DO CALL:HEXchar %%A
FOR %%A in (%Powers%) DO SET Hexnum=!Hexnum!!Val%%A!

SET /A Length=8
SET HexnumF=%Hexnum%
CALL :RemoveLead

GOTO :EOF

:RemoveLead
Set/A Length=%Length%-2
IF %HexnumF:~0,2%==00 set HEXnumF=!HexnumF:~-%Length%!&GOTO :RemoveLead
SET HexnumF=!Hexnum:~-%NumDig%!
SET Hexnum=%HexnumF:~6,2%%HexnumF:~4,2%%HexnumF:~2,2%%HexnumF:~0,2%
GOTO :EOF

:HEXcalc
IF %1==1 GOTO :EOF
SET /A Div=%1 /16
SET /A Val%Div%=!Mod%1! / %Div%
SET /A Mod%Div%=!Mod%1! %% %Div%
GOTO :EOF

:HEXchar
IF !Val%1!==10 SET Val%1=A
IF !Val%1!==11 SET Val%1=B
IF !Val%1!==12 SET Val%1=C
IF !Val%1!==13 SET Val%1=D
IF !Val%1!==14 SET Val%1=E
IF !Val%1!==15 SET Val%1=F
GOTO :EOF

:PARTIMGMAP
:parseparams
REM Needed parameters are:
REM 1) Disk= Disk Number
REM 2) Geometry= Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63, but values accepted are 255/63, 128/63, 16/63, 64/32
REM 3) Partnum=number of partition entry - can be 1, 2, 3 or 4
REM 4) PartType= Partition type - can be:
REM    01 FAT12
REM    04 FAT16 <32Mb (obsolete)
REM    06 FAT16 CHS mapped
REM    07 NTFS
REM    0B FAT32 CHS mapped
REM    0C FAT32 LBA mapped
REM    0E FAT16 LBA mapped
REM    NO support for extended partitions of any kind!
REM 5) Active= whether the partition is Active or not - can be 0 (NOT Active) or 80 (Active)
REM 6) StartLBA= LBA address of first sector
REM 7) SectorsLBA= Number of sectors in partition
REM 8) (Optional) /S to make the batch operate silently
REM and the preceding CHS ones are calculated by the batch
REM Due to number and complexity of parameters, this batch is better suited to be
REM either called from within another batch or in interactive mode
SET neededfiles=gsar.exe dsfo.exe dsfi.exe dumphex.exe
FOR %%A IN (%neededfiles%) DO IF NOT EXIST %%A ECHO Missing file: %%A& GOTO :ERROR1
SHIFT
SET OK=0
Set Disk=%1
Set Geometry=%2
Set Partnum=%3
Set Parttype=%4
Set Active=%5
Set StartLBA=%6
Set SectorsLBA=%7
Set Silent=%8
FOR %%A IN (1 2 3 4 5 6 7 8 9) DO IF %Disk%.==%%A. SET Disk=%%A&SET /A OK+=1
FOR %%A IN (255/63 128/63 16/63 64/32) DO IF /I %Geometry%.==%%A. SET Geometry=%%A&SET /A OK+=10
FOR %%A IN (1 2 3 4) DO IF %Partnum%.==%%A. SET Partnum=%%A&SET /A OK+=100
FOR %%A IN (01 04 06 07 0B 0C 0E) DO IF /I %PartType%.==%%A. SET PartType=%%A&SET /A OK+=1000
FOR %%A IN (00 80) DO IF %Active%.==%%A. SET Active=%%A&SET /A OK+=10000
FOR %%A IN (StartLBA SectorsLBA) DO IF NOT DEFINED %%A SET DATA=0
IF %OK% lss 11111 GOTO :PARTIMGHELP
IF %DATA%.==0. GOTO :PARTIMGHELP
GOTO :isLBA

:isLBA
CALL :LBAtoCHS Start %StartLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%StartCHS%") DO SET /A BCyl=%%A&SET /A BHd=%%B&SET /A BSec=%%C
SET /A EndLBA=%StartLBA%+%SectorsLBA%-1
CALL :LBAtoCHS End %EndLBA% %Geometry%
FOR /F "tokens=1,2,3 delims=/" %%A in ("%EndCHS%") DO SET /A ECyl=%%A&SET /A EHd=%%B&SET /A ESec=%%C

:ConfirmParams
IF %BCyl% gtr 1023 SET /A BCyl=1023
IF %ECyl% gtr 1023 SET /A ECyl=1023
IF /I %Silent%.==/S. GOTO :DoSilent
ECHO Parameters are as follows:
:display
SET partline=³
FOR %%A IN ( 
Partnum.6
Parttype.11
Active.16
BCyl.23
BHd.27
BSec.32
ECyl.39
EHd.43
ESec.48
StartLBA.60
SectorsLBA.74
) DO (
CALL :adddata partline %%~nA %%~xA
)
CALL :display3 NOOLD
ECHO %partline%
IF %BCyl% gtr 1023 SET /A WBCyl=1023
IF %ECyl% gtr 1023 SET /A WECyl=1023
IF DEFINED WBCyl ECHO (The Beginning Cylinder will be written as %WBCyl%)
IF DEFINED WECyl ECHO (The Ending Cylinder will be written as %WECyl%)
GOTO :DoEdit

:DoEdit
echo EDIT
PAUSE
ECHO Are you sure you want to write the above values to file %source%?
SET Confirm=NO
SET /P Confirm=Type YES to confirm: 
IF /I NOT %Confirm%.==YES. goto :EOF
ECHO Writing data....
:DoSilent
SET Powers=32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
CALL :DEC2BIN %BCyl%
SET BCyl=%BINNUM:~-10,10%
CALL :DEC2BIN %BSec%
SET BSec=%BINNUM:~-6,6%
SET BSec=%BCyl:~0,2%%BSec%
SET BCyl=%BCyl:~-8,8%

CALL :DEC2BIN %ECyl%
SET ECyl=%BINNUM:~-10,10%
CALL :DEC2BIN %ESec%
SET ESec=%BINNUM:~-6,6%
SET ESec=%ECyl:~0,2%%ESec%
SET ECyl=%ECyl:~-8,8%
SET Powers=128 64 32 16 8 4 2 1

FOR %%A IN (BCyl BSec ECyl ESec) DO (
CALL :BIN2DEC !%%A! 8
SET %%A=!DECnum!
)

FOR %%A IN (BCyl BHd BSec ECyl EHd ESec) DO (
CALL :DEC2hex !%%A! 2
SET %%A=!HEXnum!
)
FOR %%A IN (StartLBA SectorsLBA) DO (
CALL :DEC2hex !%%A! 8
SET %%A=!HEXnum!
)
IF /I NOT %Silent%.==/S. FOR %%A IN ( PartType Active BCyl BHd BSec ECyl EHd ESec StartLBA SectorsLBA) DO SET %%A

REM Partition Data offset: 1=446 2=462 3=478 4=494
Set /A MBR_Offset=430+%Partnum%*16
Set /A PBR_Offset=%6*512

IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
REM dd.exe if=\\.\physicaldrive%DD% of=my_MBR.mbr bs=512 count=1
REM dd.exe if=\\.\physicaldrive%DD% of=my_PBR.pbr bs=512 count=1 skip=%6
dsfo \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfo \\.\PHYSICALDRIVE%Disk% %PBR_Offset% 512 my_PBR.pbr

bytepatch.exe my_MBR.mbr -a %MBR_Offset% %Active% %BHd% %BSec% %BCyl% %Parttype% %EHd% %ESec% %ECyl% %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2% %SectorsLBA:~0,2% %SectorsLBA:~2,2% %SectorsLBA:~4,2% %SectorsLBA:~6,2%
bytepatch.exe my_PBR.pbr -a 0x01C %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2%

LockDismount.exe -force %Disk% dsfi \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
LockDismount.exe -force %Disk% dsfi \\.\PHYSICALDRIVE%Disk% %PBR_Offset% 512 my_PBR.pbr
REM LockDismount.exe -force %Disk% dd.exe if=my_MBR.mbr of=\\.\physicaldrive%DD% bs=512 count=1
REM LockDismount.exe -force %Disk% dd.exe if=my_PBR.pbr of=\\.\physicaldrive%DD% bs=512 count=1 seek=%6
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
GOTO :EOF

:LBAtoCHS
REM %1 is Variable name
REM %2 is the LBA value to convert
REM %3 is the disk geometry like 255/63
REM To get CHS from LBA:
REM CYL = LBA / (THds * TSec)
REM TEMPVAL = LBA % (THds * TSec)
REM HEAD = TEMP / TSec
REM SECT = TEMP % TSec + 1
REM Where:
REM LBA: linear base address of the block
REM CYL: value of the cylinder CHS coordinate
REM THds: Total number of heads per cylinder for the disk
REM HEAD: value of the head CHS coordinate
REM TSec: Total number of sectors per head for the disk
REM SECT: value of the sector CHS coordinate
REM TEMPVAL: buffer to hold a temporary value
SET /A LBA=%2
FOR /F "tokens=1,2 delims=/" %%A in ("%3") DO SET THds=%%A&SET TSec=%%B
SET /A TEMPVAL = THds * TSec
SET /A CYL = LBA/TEMPVAL
SET /A TEMPVAL = "%LBA% %% %TEMPVAL%"
SET /A HEAD = TEMPVAL/TSec
SET /A SECT = "%TEMPVAL% %% %TSec% + 1"
SET %1CHS=%CYL%/%HEAD%/%SECT%
GOTO :EOF

:checklength
SET /A Counter=0
SET data=!%1!
:LoopLength
SET /A Counter=%Counter%+1
IF NOT "%data%"=="!data:~0,%Counter%!" GOTO :LoopLength
SET /A %1Length=Counter
GOTO :EOF

:Padzeroes
SET /A sCounter=%sCounter%+1
SET String=%String%$00
IF NOT %sCounter%==%1 goto :Padzeroes
IF %2.==MagSig. SET String=%String%$55$AA
ECHoo.com %String%>> test.mbr
GOTO :EOF

:checkstrings
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset
FOR %%A IN (%Range%) DO IF /I !%1!.==%%A. SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:checkvalues
REM Parameters are:
REM Variable Goodnumber Goodvalue Sep_offset min max 
IF !%1! Geq %5 IF !%1! Leq %6 SET /A Goodparam=%Goodparam%+%2
IF NOT %Goodparam%==%3 GOTO :EOF
CALL :adddata partline %1 %4
CLS&CALL :display3
ECHO %partline%
GOTO :EOF

:display3
IF %1.==NOOLD. goto :NOOLD
For %%A IN (a b c d e 1 f 2 f 3 f 4 g) DO ECHO !Line%%A!
:NOOLD
ECHO.
ECHO Drive geometry: %Geometry% Program Mode: %PMode%
ECHO ÚÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³Part ³Type³Boot³  Begin   CHS  ³   End   CHS   ³ LBA Start ³ LBA Sectors ³
ECHO ³  #  ³    ³    ³ BCyl ³BHd³BSec³ ECyl ³EHd³ESec³           ³             ³
ECHO ÃÄÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÅÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
GOTO :EOF

:adddata
if %3.==. GOTO :EOF
set templine=%1
set thisline=!%templine%!
set pad=%2
set pad=!%pad%!³
set sepoffset=%3
set sepoffset=%sepoffset:.=%
:dataloop
SET templine=%thisline%%pad%
set pad= %pad%
IF NOT "!templine:~%sepoffset%,1!"=="³" goto :dataloop
SET %1=%templine%
GOTO :EOF

:PARTIMGHELP
ECHO.
ECHO Syntax :
ECHO.
ECHO %~nx0 MAP [Disk] [Geometry] [Partnum] [PartType] [Active] [StartLBA] [SectorsLBA] [/S]
ECHO.
ECHO Disk       = Disk Number
ECHO.
ECHO Geometry   = Drive Geometry, Heads/Sectors, under 2K/XP/2003 255/63,
ECHO              but values accepted are 255/63, 128/63, 16/63, 
ECHO.
ECHO Partnum    = number of partition entry - can be 1, 2, 3 or 4
ECHO.
ECHO PartType   = Partition type - can be:
ECHO 		  01 FAT12			³
ECHO 		  04 FAT16 ^<32 Mb (obsolete)	³
ECHO 		  06 FAT16 CHS mapped 		³ NO support for
ECHO 		  07 NTFS             		³
ECHO 		  0B FAT32 CHS mapped 		³ extended partitions
ECHO 		  0C FAT32 LBA mapped 		³
ECHO 		  0E FAT16 LBA mapped 		³
ECHO.
ECHO Active     = Active flag for entry - can be 0 (NOT Active) or 80 (Active)
ECHO.
ECHO StartLBA   = LBA address of first sector
ECHO.
ECHO SectorsLBA = Number of sectors in partition
ECHO.
ECHO EXAMPLES:
ECHO %~nx0 MAP 1 255/63 1 0B 80 63 2056257 /S
PAUSE
GOTO :EOF


:error
ECHO An error has occurred
GOTO :EOF

:error1
ECHO Please add the missing file in the same directory where %~nx0 is
GOTO :EOF

:Temporary_Code
if not exist echoo.com (
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6
echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg
echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0
)>>echoo.com 

Set /A Length=512
SET /A sCOUNTER=0
SET /A BCOUNTER=0
SET String=
FOR /F "tokens=2 delims=: " %%A IN ('dumphex /s%Offset% /L%Length% /w1 /nc %SystemRoot%\System32\dmadmin.exe') DO (
SET /A sCOUNTER=!sCOUNTER!+1
SET String=!String!$%%A
IF !sCOUNTER!==32 (
ECHoo.com !String!>> %2
SET sCOUNTER=0
SET /A BCOUNTER=!BCOUNTER!+1
SET STRING=
)
IF !BCOUNTER!==13 IF !sCOUNTER!==30 GOTO :PartData
)

:PartData
SET Active=80
SET PartType=0E
SET EHd=0F
SET ESec=3F
SET ECyl=24
SET SecBef=3F000000
SET TotSec=71910000
SET String=%String%$%Active%$01
ECHoo.com !String!>> test.mbr
SET String=$01$00$%PartType%$%EHd%$%ESec%$%ECyl%$%SecBef:~0,2%$%SecBef:~2,2%$%SecBef:~4,2%$%SecBef:~6,2%$%TotSec:~0,2%$%TotSec:~2,2%$%TotSec:~4,2%$%TotSec:~6,2%
SET /A sCounter=14
CALL :Padzeroes 32
SET /A sCounter=0
SET String=
CALL :Padzeroes 30 MagSig
GOTO :EOF

Any suggestions are welcomed for any improvement required....

 

Thanks & Regards...

Attached Files



#32 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 18 December 2021 - 01:28 PM

Good. :)

 

@All

Remember this warning:

 

 

::=======================================================
::| WARNING! Limit is 2147483647 i.e. 7FFFFFF WARNING! |
::=======================================================

 

The whole staff is suited to very small devices or to volumes very near the beginning of a larger device.

dsfo/dsfi use bytes, the "key" limit should be in:

Set /A PBR_Offset=%6*512

using dd for windows instead of dsfo/dsfi[1], i.e. using offset in sectors instead of bytes, the "reach" of the tool would increase noticeably (though still remaining limited to not-so-large devices).

 

:duff:

Wonko

 

[1] the limit is not in dsfo/dsfi, only in the batch math operations, it would be possible to keep using dsfo/dsfi using alternate batch math or using external programs for multiplication and dec-hex conversion.



#33 alacran

alacran

    Gold Member

  • .script developer
  • 2386 posts
  •  
    Mexico

Posted 18 December 2021 - 02:30 PM

@devdevadev

On recent windows (Vista and later) the PBR is "protected".

You need to put the volume offline in order to be able to write to it (Lockdismount should do)

http://reboot.pro/in...showtopic=12413

The PBR MUST have correct data, no matter if on MBR or GPT.

 

@alacran

dsfo/dsfi or dd for windows are good correspondent programs to dd in Linux/Unix (particularly dd for windows is an almost perfect replica).

BUT the whole point you missed is that dd (on Linux) is the tool used to copy the (RAW) data, but you need other programs to actually create the partition entry in the MBR (or in the GPT partition table).

If you prefer, devdevadev is trying to assemble in a batch a series of programs that will (hopefully) allow to do in an automated/command line way the WHOLE process described by Akeo, i.e. - albeit too slowly/late by your standards - a direct answer to your questions.

 

:duff:

Wonko

 

I wonder:

 

Couldn't it be easier to make the partitions using diskpart, and after this use dd for windows, to copy/clone uefi-ntfs.img into the desired device partition?

 

alacran



#34 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 18 December 2021 - 03:44 PM

I wonder:

 

Couldn't it be easier to make the partitions using diskpart, and after this use dd for windows, to copy/clone uefi-ntfs.img into the desired device partition?

 

alacran

Actually it would be easier to use grub4dos, that has both dd [1] and partnew as "internal commands" and of course they could be automated into a grub4dos batch.

 

I may be wrong, but I don't think that diskpart has the "sensibility" to create partitions at a given sector offset and of an exact (to sector) size, but this could be "reversed" i.e. make the partition image with size compatible with diskpart.

 

Still it would remain the need of a small program capable of correcting the "sectors before" in the PBR, but   :idea: this can be "not-calculated" as one could simply dd the "sectors before" from the just created MBR partition entry, thankfully they are both the same number (32 bit or 4 bytes) avoiding any calculation.

 

As well, one could use diskpart to create a new partition (essentially using diskpart to just detect and place the partition at a "right" place on disk) then dd from the MBR to the image this placement (sectors before) AND dd back from the image to the MBR the LBA extents (sectors in partition).

 

This way the LBA would be correct in both the MBR and in the PBR of the (dd-ed to disk) image, while the CHS data would remain in a state of "undefined".

 

This is the exact opposite of the limits I was talking about in the previous post, as past 1023/254/63 i.e. 1024*255*63*512=8,422,686,720 these values become a constant, so if the partition is created (starts) past this address, the CHS data will be 1023/254/63 no matter at what LBA address the partition actually is.

 

:duff:

Wonko

 

[1] the dd in grub4dos although much slower than any OS's version, is not too shabby, and if I get it right (from your other thread) the image is so small that it is not an issue.



#35 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 18 December 2021 - 03:56 PM

I wonder:

Couldn't it be easier to make the partitions using diskpart, and after this use dd for windows, to copy/clone uefi-ntfs.img into the desired device partition?

alacran

Yes...Your method will be useful and easier to implement if someone want to permanently reserved PTN2/PTN3 entry just for containing uefi-ntfs.img files.

But in my SMART USB, I want to keep PTN3 as NTFS so that I can keep multiple Secure UEFI Bootable Partition Images, Large macOS_Installer.hfs files and my Secret/Hidden Personal files within it. Normally I will always keep PTN3:/UEFI_NTFS.imgPTNrep3 mappped as PTN3. But I will always have freedom to switch different Partition Images to PTN3 as per requirement without any format/Re-Partition of USB Partitions. And all IMP files and folders will always be safe within original NTFS PTN3 Sectors.

PTN1 - NTFS - E2B (ISOs+imgPTN+WINAIO+WIN10PE+VHD_WIMBOOT)
PTN2 - FAT32 - (AGFM+VT4E) / ventoy-disk.img
PTN3 - NTFS - (DATA+imgPTNrep3+macOS.hfsPTN) / uefi-ntfs.img

PTN3:/IMP FILES
PTN3:/_ISO/UEFI_NTFS.imgPTNrep3
PTN3:/_ISO/SWITCH_PE.imgPTNrep3
PTN3:/_ISO/macOS_Installer.imgPTNrep3

Do you still think I should permanently reserve PTN3 entry just for uefi-ntfs.img ? Please suggest any better configuration for USB Drive Partitions if possible.

Regards

#36 alacran

alacran

    Gold Member

  • .script developer
  • 2386 posts
  •  
    Mexico

Posted 18 December 2021 - 11:41 PM

@ devdevadev

Ok, now it makes sense to me, once you explained in detail how you want to use it.

 

alacran



#37 alacran

alacran

    Gold Member

  • .script developer
  • 2386 posts
  •  
    Mexico

Posted 19 December 2021 - 02:28 AM

Actually it would be easier to use grub4dos, that has both dd [1] and partnew as "internal commands" and of course they could be automated into a grub4dos batch.

.........

 

:duff:

Wonko

 

[1] the dd in grub4dos although much slower than any OS's version, is not too shabby, and if I get it right (from your other thread) the image is so small that it is not an issue.

@ Wonko

Yes my friend, I'm agree, grub4dos is a good option.

 

But if the user prefer to install the uefi-ntfs.img file to a real physical partition, I think doing all in Win and without requiring a reboot to grub4dos could be better.

 

Additionally:  In fact using an EFI partition with ID: EF is not required, and doing it this way only unnecessarily complicate the task. Then if not using an EFI partion (ID: EF) the uefi-ntfs.img does not need to be dd cloned/copied, and just creating a FAT-16 or FAT-32 primary partition and only extacting the uefi-ntfs.img content with 7-Zip to the partition, is the faster and easier way to do it, and it works very fine as I can confirm.

 

For readers convenience I attached uefi-ntfs.img content as a zip file on this post:

Experiments with UEFI:NTFS - Booting internal MBR HDD in UEFI from NTFS

.......

uefi-ntfs.zip   440.45KB

 

@ devdevadev

 

Please excuse me my friend, this wasn't an intent to hijack your topic, the only intention is let future readers have alternative options to let them select the option that fits better their needs/preferences.

 

alacran


  • devdevadev likes this

#38 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 19 December 2021 - 12:17 PM

 In fact using an EFI partition with ID: EF is not required, and doing it this way only unnecessarily complicate the task. 

 

Which is good :) as noone (in this thread) even thought of making an EF EFI partition.

 

:duff:

Wonko



#39 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 20 December 2021 - 03:16 PM

[1] the limit is not in dsfo/dsfi, only in the batch math operations, it would be possible to keep using dsfo/dsfi using alternate batch math or using external programs for multiplication and dec-hex conversion.

How exactly alternate batch math will be performed ? And which external program can be used for multiplication ? And why we will do dec-hex conversion while we need PBR_Offset_Bytes from PBR_Offset_LBA ? Please provide required code for conversion.

:DoEdit
echo EDIT
PAUSE
ECHO Are you sure you want to write the above values to file %source%?
SET Confirm=NO
SET /P Confirm=Type YES to confirm: 
IF /I NOT %Confirm%.==YES. goto :EOF
ECHO Writing data....
:DoSilent
SET Powers=32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
CALL :DEC2BIN %BCyl%
SET BCyl=%BINNUM:~-10,10%
CALL :DEC2BIN %BSec%
SET BSec=%BINNUM:~-6,6%
SET BSec=%BCyl:~0,2%%BSec%
SET BCyl=%BCyl:~-8,8%

CALL :DEC2BIN %ECyl%
SET ECyl=%BINNUM:~-10,10%
CALL :DEC2BIN %ESec%
SET ESec=%BINNUM:~-6,6%
SET ESec=%ECyl:~0,2%%ESec%
SET ECyl=%ECyl:~-8,8%
SET Powers=128 64 32 16 8 4 2 1

FOR %%A IN (BCyl BSec ECyl ESec) DO (
CALL :BIN2DEC !%%A! 8
SET %%A=!DECnum!
)

FOR %%A IN (BCyl BHd BSec ECyl EHd ESec) DO (
CALL :DEC2hex !%%A! 2
SET %%A=!HEXnum!
)

SET /A P1LENMOD=%StartLBA%-2048
FOR %%A IN (StartLBA SectorsLBA P1LENMOD) DO (
CALL :DEC2hex !%%A! 8
SET %%A=!HEXnum!
)
IF /I NOT %Silent%.==/S. FOR %%A IN ( PartType Active BCyl BHd BSec ECyl EHd ESec StartLBA SectorsLBA P1LENMOD) DO SET %%A

REM Partition Data offset: 1=446 2=462 3=478 4=494
Set /A MBR_Offset=430+%Partnum%*16
Set /A PBR_Offset_LBA=%6
Set /A PBR_Offset_Bytes=%6*512

IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
REM dd.exe if=\\.\physicaldrive%DD% of=my_MBR.mbr bs=512 count=1
REM dd.exe if=\\.\physicaldrive%DD% of=my_PBR.pbr bs=512 count=1 skip=%PBR_Offset_LBA%
dsfo \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
dsfo \\.\PHYSICALDRIVE%Disk% %PBR_Offset_Bytes% 512 my_PBR.pbr

bytepatch.exe my_MBR.mbr -a %MBR_Offset% %Active% %BHd% %BSec% %BCyl% %Parttype% %EHd% %ESec% %ECyl% %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2% %SectorsLBA:~0,2% %SectorsLBA:~2,2% %SectorsLBA:~4,2% %SectorsLBA:~6,2%
bytepatch.exe my_PBR.pbr -a 0x01C %StartLBA:~0,2% %StartLBA:~2,2% %StartLBA:~4,2% %StartLBA:~6,2%
IF %Partnum%==2 bytepatch.exe my_MBR.mbr -a 458 %P1LENMOD:~0,2% %P1LENMOD:~2,2% %P1LENMOD:~4,2% %P1LENMOD:~6,2%

LockDismount.exe -force %Disk% dsfi \\.\PHYSICALDRIVE%Disk% 0 512 my_MBR.mbr
LockDismount.exe -force %Disk% dsfi \\.\PHYSICALDRIVE%Disk% %PBR_Offset_Bytes% 512 my_PBR.pbr
REM LockDismount.exe -force %Disk% dd.exe if=my_MBR.mbr of=\\.\physicaldrive%DD% bs=512 count=1
REM LockDismount.exe -force %Disk% dd.exe if=my_PBR.pbr of=\\.\physicaldrive%DD% bs=512 count=1 seek=%PBR_Offset_LBA%
IF EXIST my_MBR.mbr DEL my_MBR.mbr
IF EXIST my_PBR.pbr DEL my_PBR.pbr
GOTO :EOF 

In case I want to patch 4 Bytes of Partition 1 Length in MBR, then what Offset I should use in Bytepatch command ?

 

Regards...



#40 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 20 December 2021 - 03:40 PM

There are command line calculators that go past the batch math limit, or (the poor man's way) my multiply batch would do:

http://reboot.pro/in...?showtopic=2986

http://reboot.pro/in...=15799&p=141469

 

 

From the batch you posted:

 

REM Partition Data offset: 1=446 2=462 3=478 4=494

 

Those are the offsets of the 4 partition entries, each 16 bytes.

The LBA length is 4 bytes, and they are last 4 bytes of the entry, so either 446+12(16-4)=458 or 462-4=458 would do.

 

If you try using Tiny Hexer with my MBRview "Structure Viewer" offsets for the MBR partition table  will be clear:

http://reboot.pro/in...?showtopic=8734

 

Attached an example screenshot.

 

:duff:

Wonko

Attached Files



#41 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 4 weeks ago


COMMAND LINE: DRIVE=1 USBINFO USBSTART=0 SURE 

RMPARTUSB v2.1.750 (c)2019 RM Education plc [SSi]
=================================================

Accessing Drive 1 - "Samsung Flash Drive" (32,086,425,600 bytes)

Sector at LBA 0

============= SECTOR DATA ================


[Sector 0]  0MB
0000 33 C0 EB 5C 80 00 20 39 - FF FF 00 00 00 00 00 00  3Àë\€. 9 ÿÿ......
0010 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0020 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0030 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0040 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0050 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0060 FA 31 DB 8E D3 BC 80 05 - E8 00 00 5B 81 EB 6B 00  ú1ÛŽÓ¼€. è..[ëk.
0070 C1 EB 04 8C C8 01 C3 8E - DB 53 6A 7D CB 68 00 20  Áë.ŒÈ.ÃŽ ÛSj}Ëh. 
0080 17 BC 00 90 FB 16 07 B9 - 12 00 B8 01 02 89 CB 4B  ¼.û.¹ .¸..‰ËK
0090 C1 E3 09 BA 80 00 51 53 - E8 A4 00 5B 59 72 04 E2  Áã.º€.QS è¤.[Yr.â
00A0 E9 F6 DC 0E 1F 9C 31 F6 - 31 FF B9 DF 00 FC F3 A5  éöÜœ1ö 1ÿ¹ß.üó¥
00B0 BB FC 1F 66 B8 05 4D CB - 93 66 39 07 75 03 E8 39  »üf¸.MË “f9.u.è9
00C0 1C EA C6 00 00 20 16 1F - 66 39 07 74 28 66 60 BF  êÆ..  f9.t(f`¿
00D0 03 00 B8 11 02 99 BB 00 - 02 B9 02 00 E8 80 00 73  ..¸.™». .¹..è€.s
00E0 02 75 EF 66 61 66 39 07 - 75 4D C7 06 08 00 00 FF  .uïfaf9. uMÇ....ÿ
00F0 80 26 04 00 FE 9D 72 33 - 0E 1F AD 88 E6 AD 89 C1  €&..þr3 ­ˆæ­‰Á
0100 24 3F 74 14 B0 01 BF 03 - 00 B4 02 68 00 0D 07 31  $?t°.¿. .´.h...1
0110 DB E8 4B 00 73 03 75 F1 - F9 E8 5C 11 0F 87 F3 1B  ÛèK.s.uñ ùè\‡ó
0120 83 C6 0C 81 FE FE 01 72 - CF 77 0C BE B2 31 B0 04  ƒÆ.þþ.r Ïw.¾²1°.
0130 B9 01 00 31 D2 EB CF BE - 91 01 E8 4D 00 EB FE 1E  ¹..1ÒëϾ ‘.èM.ëþ
0140 06 52 56 57 55 F9 CD 13 - 5D 5F 5E 5A 07 1F C3 FA  .RVWUùÍ ]_^Z.Ãú
0150 B8 00 20 8E D0 BC DC 8F - FB 66 61 07 1F EB C1 60  ¸. ŽÐ¼Ü ûfa.ëÁ`
0160 50 53 51 FE C8 00 C1 D0 - E0 00 C7 B0 01 E8 CF FF  PSQþÈ.ÁÐ à.Ç°.èÏÿ
0170 59 5B 58 72 04 FE C8 75 - E7 61 73 09 60 31 C0 E8  Y[Xr.þÈu ças.`1Àè
0180 BD FF 61 4F F9 C3 B4 0E - CD 10 2E AC 3C 00 75 F6  ½ÿaOùô Í.¬<.uö
0190 C3 0D 0A 4D 69 73 73 69 - 6E 67 20 4D 42 52 2D 68  Ã..Missi ng MBR-h
01A0 65 6C 70 65 72 2E 00 00 - 00 00 00 00 00 00 00 00  elper... ........
01B0 53 4D 41 52 54 55 53 42 - FA CD 6D B7 00 00 00 20  SMARTUSB úÍm·... 
01C0 21 00 07 FE FF FF 00 08 - 00 00 01 B8 61 03 00 FE  !..þÿÿ.. ...¸a..þ
01D0 FF FF 0B FE FF FF 00 C8 - 61 03 00 10 19 00 80 FE  ÿÿ.þÿÿ.È a...€þ
01E0 FF FF 07 FE FF FF 00 D8 - 7A 03 01 18 40 00 00 00  ÿÿ.þÿÿ.Ø z..@...
01F0 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 55 AA  ........ ......Uª

[Sector 1]  0MB
0200 EB 63 90 5C 80 00 20 39 - FF FF 00 00 00 00 00 00  ëc\€. 9 ÿÿ......
0210 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0220 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0230 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0240 00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ........ ........
0250 00 00 00 00 00 00 00 00 - 00 00 00 80 01 00 00 00  ........ ...€....
0260 00 00 00 00 FF FA 90 90 - F6 C2 80 74 05 F6 C2 70  ....ÿú ö€t.öÂp
0270 74 02 B2 80 EA 79 7C 00 - 00 31 C0 8E D8 8E D0 BC  t.²€êy|. .1ÀŽØŽÐ¼
0280 00 20 FB A0 64 7C 3C FF - 74 02 88 C2 52 BE 80 7D  . û d|<ÿ t.ˆÂR¾€}
0290 E8 17 01 BE 05 7C B4 41 - BB AA 55 CD 13 5A 52 72  è.¾.|´A »ªUÍZRr
02A0 3D 81 FB 55 AA 75 37 83 - E1 01 74 32 31 C0 89 44  =ûUªu7ƒ á.t21À‰D
02B0 04 40 88 44 FF 89 44 02 - C7 04 10 00 66 8B 1E 5C  .@ˆDÿ‰D. Ç..f‹\
02C0 7C 66 89 5C 08 66 8B 1E - 60 7C 66 89 5C 0C C7 44  |f‰\.f‹ `|f‰\.ÇD
02D0 06 00 70 B4 42 CD 13 72 - 05 BB 00 70 EB 76 B4 08  ..p´BÍr .».pëv´.
02E0 CD 13 73 0D 5A 84 D2 0F - 83 D8 00 BE 8B 7D E9 82  Ís.Z„Ò ƒØ.¾‹}é‚
02F0 00 66 0F B6 C6 88 64 FF - 40 66 89 44 04 0F B6 D1  .f¶Æˆdÿ @f‰D.¶Ñ
0300 C1 E2 02 88 E8 88 F4 40 - 89 44 08 0F B6 C2 C0 E8  Áâ.ˆèˆô@ ‰D.¶ÂÀè
0310 02 66 89 04 66 A1 60 7C - 66 09 C0 75 4E 66 A1 5C  .f‰.f¡`| f.ÀuNf¡\
0320 7C 66 31 D2 66 F7 34 88 - D1 31 D2 66 F7 74 04 3B  |f1Òf÷4ˆ Ñ1Òf÷t.;
0330 44 08 7D 37 FE C1 88 C5 - 30 C0 C1 E8 02 08 C1 88  D.}7þÁˆÅ 0ÀÁè..Áˆ
0340 D0 5A 88 C6 BB 00 70 8E - C3 31 DB B8 01 02 CD 13  ÐZˆÆ».pŽ Ã1Û¸..Í
0350 72 1E 8C C3 60 1E B9 00 - 01 8E DB 31 F6 BF 00 80  rŒÃ`¹. .ŽÛ1ö¿.€
0360 8E C6 FC F3 A5 1F 61 FF - 26 5A 7C BE 86 7D EB 03  ŽÆüó¥aÿ &Z|¾†}ë.
0370 BE 95 7D E8 34 00 BE 9A - 7D E8 2E 00 CD 18 EB FE  ¾•}è4.¾š }è..Íëþ
0380 47 52 55 42 20 00 47 65 - 6F 6D 00 48 61 72 64 20  GRUB .Ge om.Hard 
0390 44 69 73 6B 00 52 65 61 - 64 00 20 45 72 72 6F 72  Disk.Rea d. Error
03A0 0D 0A 00 BB 01 00 B4 0E - CD 10 AC 3C 00 75 F4 C3  ...»..´ ͬ<.uôÃ
03B0 00 00 00 00 00 00 00 00 - FA CD 6D B7 00 00 00 20  ........ úÍm·... 
03C0 21 00 07 FE FF FF 00 08 - 00 00 01 B8 61 03 00 FE  !..þÿÿ.. ...¸a..þ
03D0 FF FF 0B FE FF FF 00 C8 - 61 03 00 10 19 00 80 FE  ÿÿ.þÿÿ.È a...€þ
03E0 FF FF 07 FE FF FF 00 D8 - 7A 03 01 18 40 00 00 FE  ÿÿ.þÿÿ.Ø z..@..þ
03F0 FF FF 00 FE FF FF 38 D3 - C3 01 40 D5 7A 00 55 AA  ÿÿ.þÿÿ8Ó Ã.@Õz.Uª

========= END OF SECTOR DATA ================


Disk Signature bytes (1B8h-1BBh) = FA CD 6D B7

Partition 1   SIZE=27703MiB   Type: 07 NTFS\exFAT       
START POS   = CYL:0 HD:32 SEC:33       END POS = CYL:1023 HD:254 SEC:63
START (LBA) = 2,048 (00000800) SIZE (LBA) = 56,735,745 (0361B801) [End=56,737,792]

Partition 2   SIZE=802MiB   Type: 0B FAT32 (2047GB max)       
START POS   = CYL:1023 HD:254 SEC:63       END POS = CYL:1023 HD:254 SEC:63
START (LBA) = 56,739,840 (0361C800) SIZE (LBA) = 1,642,496 (00191000) [End=58,382,335]

Partition 3   SIZE=2051MiB   Type: 07 NTFS\exFAT  *ACTIVE*
START POS   = CYL:1023 HD:254 SEC:63       END POS = CYL:1023 HD:254 SEC:63
START (LBA) = 58,382,336 (037AD800) SIZE (LBA) = 4,200,449 (00401801) [End=62,582,784]

Partition 4   SIZE=0MiB   Type: 00        
START POS   = CYL:0 HD:0 SEC:0       END POS = CYL:0 HD:0 SEC:0
START (LBA) = 0 (00000000) SIZE (LBA) = 0 (00000000)

P1   Start=2,048 (1,048,576 bytes) End=56,737,792 (29,049,749,504 bytes)
P2   Start=56,739,840 (29,050,798,080 bytes) End=58,382,335 (29,891,755,520 bytes)
P3   Start=58,382,336 (29,891,756,032 bytes) End=62,582,784 (32,042,385,408 bytes)

Drive 1  Samsung Flash Drive  F/W Rev.=1100  Serial No.= [ bytes = 00 00 00 00 00 00 00 00 ]
Reported size 32,086,425,600 bytes (29.8828GiB)  Last LBA 62,668,799
RMPrepUSB Max 32,070,366,720 bytes (29.8678GiB)  Last LBA 62,637,434
if exist "%USBDRIVELETTER%\ventoy.disk.img"    call :install_ventoy "%USBDRIVELETTER%\ventoy.disk.img" 
if exist "%USBDRIVELETTER%\ventoyKAS.disk.img" call :install_ventoy "%USBDRIVELETTER%\ventoyKAS.disk.img"
if exist "%USBDRIVELETTER%\ventoyNS.disk.img"  call :install_ventoy "%USBDRIVELETTER%\ventoyNS.disk.img"


:install_ventoy
FOR /F "tokens=1,2,3,4,5,6 delims=:-" %%A IN ('extents-win32.exe "%~1"') DO (
SET ThisToken1=%%A
SET ThisToken1=!ThisToken1: =_!
SET my!ThisToken1!=%%B
IF !ThisToken1!==extents_[0]_ CALL :get_LBA Start_LBA %%E&&CALL :get_LBA Length_LBA %%F
)
SET Filename="%~1"

IF %myExtents_count_%==1 (
ECHO File is contiguous
) ELSE (
ECHO File is NOT contiguous
ECHO A suffusion of yellow ...
GOTO :EOF
)
ECHO Filename=%Filename%
ECHO Start_LBA=%Start_LBA%
ECHO Length_LBA=%Length_LBA%
pause
goto :eof

I used extents.exe in order to get extents of FAT32 (Type 0B) PTN2:\ventoy-disk.img . But it show starting LBA=0 ??

***************************
Bytes Per Sector:512
Sectors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoy.disk.img
File Cluster count :8192 -> in bytes: 33554432
File size in bytes :33554432
File cluster first :21072
Extents count :1

extents_[0] -  VCN : 0 LCN : 21072 Lba : 0 Sectors : 65536




***************************
Bytes Per Sector:512
Setors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoyKAS.disk.img
File Cluster count :8192 -> in bytes: 33554432
File size in bytes :33554432
File cluster first :29264
Extents count :1

extents_[0] -  VCN : 0 LCN : 29264 Lba : 0 Sectors : 65536




***************************
Bytes Per Sector:512
Sectors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoyNS.disk.img
File Cluster count :8192 -> in bytes: 33554432
File size in bytes :33554432
File cluster first :37456
Extents count :1

extents_[0] -  VCN : 0 LCN : 37456 Lba : 0 Sectors : 65536P

PTN2:\ventoy-disk.img , PTN2:\ventoyKAS-disk.img and PTN2:\ventoyNS-disk.img show same starting lba i.e. 0 ?

Does extentents.exe work only for NTFS ? How I can get extents of .img file located in FAT32 Partition 2 ?

 

Regards....



#42 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 4 weeks ago

It is possible that erwan.l's tool has a hiccup on FAT32, if it uses VCN to calculate LBA, if VCN is 0 than LBA will also be 0. :unsure:

You could make a post on the Extents thread reporting the issue:

http://reboot.pro/in...showtopic=18570

 

One can still calculate manually (or programmatically) the LBA, IF the LCN is correct.

 

It has to be tested/checked, of course.

 

 

Basically the formula is:

Sectors_Before+Reserved_Sectors+Number_of_FATs(normally 2) * Sectors_per_FAT+LCN * Cluster_size+(possibly) Cluster_bias

 

Sectors_Before is at offset 28 (0x1C) 4 bytes, example: 3F 00 00 00 -> 63

Reserved sectors is at offset 14 (0x0E) 2 bytes, example:20 00 ->32

Number _of_FATs is at offset 16 (0x10) 1 byte, almost always 2, example:02 ->2

Sectors per FAT is at offset 36 (0x24) 4 bytes, example AE 04 00 00 -> 1198

Depending on the exact way clusters are numbered by the program there could be the need of a correction of 0-2 (the first cluster of a FAT32 volume is cluster #2).

 

Here is a "full" example:

http://reboot.pro/in...e=2#entry209999

 

Can you try on the SAME images/volumes the myfragmenter?

 

And, since you are surely using a recent Windows, also the fsutil file queryextents

http://reboot.pro/in...571#entry219845

 

You can check the results of the calculations booting in grub4dos and using the blocklist command.

 

:duff:

Wonko



#43 erwan.l

erwan.l

    Platinum Member

  • Developer
  • 2991 posts
  • Location:Nantes - France
  •  
    France

Posted 4 weeks ago

Hi Gents,

 

Point taken : i can definitely confirm that listing extents for FAT32 does work but the LBA will always report 0 for each extent.

Indeed, i am using IOCTL_VOLUME_LOGICAL_TO_PHYSICAL and this wont work on FAT32 and/or removable disk (one and/or the other...).

 

Thus, for fat32 i need to change the way i calculate LBA and I tempted to go for this easy (but to be checked) formula : physical offset = LCN * bytes_per_cluster + offset to start of first cluster .

Thus, only for fat32 (removable) disks with one partition only (for now).

 

Regards,

Erwan



#44 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 536 posts
  •  
    India

Posted 4 weeks ago

C:\Users\SBI\Downloads\extents\console>extents-win32.exe "I:\ventoy.disk.img"
extents 1.4 by erwan2212@gmail.com
***************************
Bytes Per Sector:512
Sectors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoy.disk.img
File Cluster count :8192 (33554432 bytes)
File size in bytes :33554432
File cluster first :175000
Extents count :10

extents_[0] -  VCN : 0 LCN : 175000 Lba : 0 Sectors : 6560
extents_[1] -  VCN : 820 LCN : 130145 Lba : 0 Sectors : 6560
extents_[2] -  VCN : 1640 LCN : 152572 Lba : 0 Sectors : 6560
extents_[3] -  VCN : 2460 LCN : 107718 Lba : 0 Sectors : 6560
extents_[4] -  VCN : 3280 LCN : 189952 Lba : 0 Sectors : 6560
extents_[5] -  VCN : 4100 LCN : 163786 Lba : 0 Sectors : 6560
extents_[6] -  VCN : 4920 LCN : 96504 Lba : 0 Sectors : 6560
extents_[7] -  VCN : 5740 LCN : 118931 Lba : 0 Sectors : 6560
extents_[8] -  VCN : 6560 LCN : 141358 Lba : 0 Sectors : 6560
extents_[9] -  VCN : 7380 LCN : 182476 Lba : 0 Sectors : 6496

C:\Users\SBI\Downloads\extents\console>extents-win32.exe "I:\ventoyKAS.disk.img"
extents 1.4 by erwan2212@gmail.com
***************************
Bytes Per Sector:512
Sectors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoyKAS.disk.img
File Cluster count :8192 (33554432 bytes)
File size in bytes :33554432
File cluster first :29264
Extents count :1

extents_[0] -  VCN : 0 LCN : 29264 Lba : 0 Sectors : 65536

C:\Users\SBI\Downloads\extents\console>extents-win32.exe "I:\ventoyNS.disk.img"
extents 1.4 by erwan2212@gmail.com
***************************
Bytes Per Sector:512
Sectors per Cluster:8
Cluster size :4096
Filesystem :FAT32
***************************
Filename:I:\ventoyNS.disk.img
File Cluster count :8192 (33554432 bytes)
File size in bytes :33554432
File cluster first :37456
Extents count :1

extents_[0] -  VCN : 0 LCN : 37456 Lba : 0 Sectors : 65536

C:\Users\SBI\Downloads\extents\console>


#45 erwan.l

erwan.l

    Platinum Member

  • Developer
  • 2991 posts
  • Location:Nantes - France
  •  
    France

Posted 4 weeks ago

clear lacking feature : LBA for FAT32.

on it's way.

 

/Erwan







Also tagged with one or more of these keywords: uefi-ntfs.img, rufus, cmd, .imgptn, partimg

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users