grub4dos
grub4dos copied to clipboard
Grub4dos/Grub4efi: BUG in cat --replace command on NTFS volumes
Bug in latest UDF-fixed grub4dos and also 2022-01-18 version. Works fine in older versions - e.g. 2019, 2020-08-09. Same bug in grub4efi
!BAT
# fill (rd) with 0's , 0x82d0 is rd-base mem address, Fn24 is memset - fill memory <addr> <string> <size>
call Fn.24 0x60000 0x20 102400 > nul ;; map (md)0x300+200 (rd) > nul
errorcheck on
debug 3
debug msg=3
dd if=(rd)+1 of=()/AutoUnattend.xml
dd if=(bd)/My.xml of=()/AutoUnattend.xml
cat --locatei=LOADISO --replace=XYZX (hd0,0)/AutoUnattend.xml
cat --locatei=LOADISO (hd0,0)/AutoUnattend.xml && echo FILE NOT PATCHED!

wrong place in file is patched!

raw cat also fails in same way.
Here is older grub4dos

Finds bytes at same position and replaces correctly.
Test with grub4dos-0.4.6a-2022-01-18, normal. The problem did not recur.

Occurs for me in VBox 5 and Lenovo IdeaPad 300 real system
File system is NTFS
problem does not occur on FAT32 !!!

!BAT
# fill (rd) with 0's , 0x82d0 is rd-base mem address, Fn24 is memset - fill memory <addr> <string> <size>
call Fn.24 0x60000 0x20 102400 > nul ;; map (md)0x300+200 (rd) > nul
errorcheck on
debug 3
debug msg=3
echo FAT32
dd if=(rd)+1 of=(hd0,1)/test/AutoUnattend.xml
dd if=(bd)/My.xml of=(hd0,1)/test/AutoUnattend.xml
cat --locatei=LOADISO --replace=XYZX (hd0,1)/test/AutoUnattend.xml
cat --locatei=LOADISO (hd0,1)/test/AutoUnattend.xml && echo FILE NOT PATCHED!
echo
echo
echo NTFS
dd if=(rd)+1 of=()/AutoUnattend.xml
dd if=(bd)/My.xml of=()/AutoUnattend.xml
cat --locatei=LOADISO --replace=XYZX (hd0,0)/AutoUnattend.xml
cat --locatei=LOADISO (hd0,0)/AutoUnattend.xml && echo FILE NOT PATCHED!
https://github.com/chenall/grub4dos/commit/edbca3ff07b7c455106471f1f4889838c61c9e9f#diff-97c5d5ae16bca1642c5cf4f6e32abb65c1e65211c16d2afbb89b00378294ecbc

Possible these changes caused issue?
Fixed write error when NTFS has offset.
Fixed bug with dd function moving backwards in the same file.
yes. Related to this. The EFI was corrected last time, which implicated the BIOS. Now it is found that EFI's NTFS cache requires 4K alignment. Testing.
have a try。 grldr.rar.txt BOOTX64.rar.txt
They both seem to work OK - many thanks! I tested for redir bug #297 , dd bug #336 and this cat --replace bug #361.
Problem with new grub4efi test version Can no longer load .efi files using chainloader ???
e.g.

Partition type is NTFS?
yes NTFS. FAT32 seems OK I think

UEFI shell does not support NTFS partitions.
First, execute in the fat partition: load /ntfs efi, Then execute in NTFS partition: chainloader /grubfmx64 efi boot
That works. I didnt realise that chainloader command used the shell. Why does chainloader need the shell and NTFS driver when grub4efi can read files on NTFS? Can error message be improved? e.g. "file/volume not found". Do any other commands require filesystem drivers/shell?
This means that we MUST have a FAT partition BUT I will work around this by making a floppy .ima image file with the ntfs.efi file inside and load the efi file after a map command.
#load filesystem drivers (for chainload *.efi and UEFI shell)
map --mem (bd)/%grub%/NTFS_EFI.ima.gz (5)
load (5)/NTFS.efi
map --unmap=5
Grub4dos itself has no disk drive. In BIOS mode, int13 function provided by firmware. In UEFI mode, through the shell function provided by the firmware. Usually, this shell does not contain NTFS drivers.
UEFI shell does not support NTFS partitions.
First, execute in the fat partition: load /ntfs efi, Then execute in NTFS partition: chainloader /grubfmx64 efi boot
启动 EFI 可执行程序不一定需要它在 FAT 分区上。你可以试一下 grub2,就可以启动任意分区下的 EFI 文件。
你只要在 grub 下预先为 EFI 文件分配好内存,把它复制过去,就可以用 LoadImage 加载内存中的 EFI 程序。
启动 EFI 可执行程序不一定需要它在 FAT 分区上。你可以试一下 grub2,就可以启动任意分区下的 EFI 文件。
下一个补丁会解决这个问题。
FYI
map command wipes out NTFS driver load NTFS.efi on FAT32 ptn Ubuntu on NTFS ptn
load (hd0,1)/EFI/NTFS.efi
map /ubuntu.iso (0xff)
chainloader (0xff)
boot
FAIL
map /ubuntu.iso (0xff)
load (hd0,1)/EFI/NTFS.efi
chainloader (0xff)
boot
BOOTS

NTFS.efi应当放在FAT分区。你提供的磁盘样本,(hd0,0)是FAT分区,(hd0,1)是NTFS分区吧。
no hd0,0 = NTFS - has Ubuntu iso hd0,1 = FAT32 - has NTFS.efi
