grub4dos icon indicating copy to clipboard operation
grub4dos copied to clipboard

Grub4dos/Grub4efi: BUG in cat --replace command on NTFS volumes

Open steve6375 opened this issue 3 years ago • 21 comments
trafficstars

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!

image image

wrong place in file is patched!

image

testcat.zip

steve6375 avatar Jul 13 '22 16:07 steve6375

raw cat also fails in same way.

steve6375 avatar Jul 13 '22 16:07 steve6375

Here is older grub4dos image

Finds bytes at same position and replaces correctly.

steve6375 avatar Jul 13 '22 21:07 steve6375

Test with grub4dos-0.4.6a-2022-01-18, normal. The problem did not recur.

yaya2007 avatar Jul 14 '22 00:07 yaya2007

image

Occurs for me in VBox 5 and Lenovo IdeaPad 300 real system

File system is NTFS

steve6375 avatar Jul 14 '22 06:07 steve6375

problem does not occur on FAT32 !!! image

!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!

steve6375 avatar Jul 14 '22 06:07 steve6375

https://github.com/chenall/grub4dos/commit/edbca3ff07b7c455106471f1f4889838c61c9e9f#diff-97c5d5ae16bca1642c5cf4f6e32abb65c1e65211c16d2afbb89b00378294ecbc image

Possible these changes caused issue?

  Fixed write error when NTFS has offset.
  Fixed bug with dd function moving backwards in the same file.

steve6375 avatar Jul 17 '22 07:07 steve6375

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.

yaya2007 avatar Jul 17 '22 07:07 yaya2007

have a try。 grldr.rar.txt BOOTX64.rar.txt

yaya2007 avatar Jul 17 '22 09:07 yaya2007

They both seem to work OK - many thanks! I tested for redir bug #297 , dd bug #336 and this cat --replace bug #361.

steve6375 avatar Jul 17 '22 11:07 steve6375

Problem with new grub4efi test version Can no longer load .efi files using chainloader ???

e.g. image image

steve6375 avatar Jul 17 '22 12:07 steve6375

Partition type is NTFS?

yaya2007 avatar Jul 17 '22 12:07 yaya2007

yes NTFS. FAT32 seems OK I think

steve6375 avatar Jul 17 '22 13:07 steve6375

image

steve6375 avatar Jul 17 '22 13:07 steve6375

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

yaya2007 avatar Jul 18 '22 00:07 yaya2007

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

steve6375 avatar Jul 18 '22 07:07 steve6375

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.

yaya2007 avatar Jul 18 '22 08:07 yaya2007

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 文件。 1 你只要在 grub 下预先为 EFI 文件分配好内存,把它复制过去,就可以用 LoadImage 加载内存中的 EFI 程序。

a1ive avatar Jul 18 '22 12:07 a1ive

启动 EFI 可执行程序不一定需要它在 FAT 分区上。你可以试一下 grub2,就可以启动任意分区下的 EFI 文件。

下一个补丁会解决这个问题。

yaya2007 avatar Jul 19 '22 03:07 yaya2007

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 image

map /ubuntu.iso (0xff)
load (hd0,1)/EFI/NTFS.efi
chainloader (0xff)
boot

BOOTS

image image

steve6375 avatar Jul 19 '22 08:07 steve6375

NTFS.efi应当放在FAT分区。你提供的磁盘样本,(hd0,0)是FAT分区,(hd0,1)是NTFS分区吧。

yaya2007 avatar Jul 19 '22 11:07 yaya2007

no hd0,0 = NTFS - has Ubuntu iso hd0,1 = FAT32 - has NTFS.efi

steve6375 avatar Jul 19 '22 11:07 steve6375