China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-19 23:24
中国DOS联盟论坛 » GRUB4DOS、SYSLINUX及其它启动管理软件讨论专区 » Experiences in Making USB Drive Boot Sectors View 4,473 Replies 7
Original Poster Posted 2008-07-11 13:31 ·  中国 山西 太原 联通
银牌会员
★★★
Credits 1,009
Posts 353
Joined 2003-09-04 00:00
22-year member
UID 9419
Gender Male
Status Offline
Install the grub4dos bootloader to the USB drive MBR (Langsheng N100, formatted as HDD) using grubinst_gui, but it fails to boot on Computer 1 (manufacturer LENOVO, chipset I945G/GZ, southbridge 82801GB(ICH7/R), BIOS version 2TKT51AUS).

Copy the 63E-7FF of grldr to the 03E-1FF of the USB drive boot sector DBR using WinHex, and it boots successfully on Computer 1 (the USB drive is recognized as A:), but fails to boot on Computer 2 where the USB drive is recognized as C:.

Examine the boot code:
7C00 EB3C JMP 7C3E
......
7C3E FA CLI
7C3F FC CLD
7C40 B6FF MOV DH,FF
7C42 80FEFF CMP DH,FF
7C45 7502 JNZ 7C49
7C47 B200 MOV DL,00
7C49 31C0 XOR AX,AX
7C4B BD007C MOV BP,7C00
7C4E 8ED0 MOV SS,AX
7C50 8D66E0 LEA SP,
7C53 FB STI
7C54 895624 MOV ,DX
7C57 60 PUSHA
7C58 B441 MOV AH,41
7C5A BBAA55 MOV BX,55AA
7C5D CD13 INT 13
......

Analyze the code: It always assigns 00 to DL and treats the USB drive as ZIP format, so it fails to boot on Computer 2 where the USB drive is recognized as C:.

Modify the code:
7C54 8B5624 MOV DX,

After modification, it boots successfully on both Computer 1 and 2. But on Computer 1 where the USB drive is recognized as A:, it prompts that menu.lst is not found. Then modify grldr, delete all '--ignore-floppies ' in the menu at the end of the file. At this point, everything is normal.

[ Last edited by yaya on 2008-9-11 at 09:30 AM ]
Floor 2 Posted 2008-07-11 16:36 ·  中国 河南 南阳 电信
银牌会员
★★★★
不甘寂寞的人
Credits 2,491
Posts 1,115
Joined 2003-09-24 00:00
22-year member
UID 10292
Gender Male
Status Offline
You understand assembly, so it's no problem for you, even using a scalpel. But your method can only work on your machine, and can't guarantee smooth passage under other motherboard BIOSes.

Some machines' BIOSes can't pass the correct DL value, then you'll encounter failure. And our code forces DL=0, which can avoid failure on floppy disks. When used for the partition boot sector of a hard disk, the operation of DL=0 won't be executed. The installer should set DH and DL to the correct values; you can see the README file for instructions.

When you use your USB flash drive as a hard disk, you even discard the partition table and MBR. Actually, this is taking a "non-conventional path". If you take this path while others don't, then you might run into obstacles somewhere and on some machine. It's better to "follow the crowd", while "going off the beaten track" may lurk with dangers.

You should make the USB flash drive into a FAT format containing MBR and partition table, then use the latest version of bootlace to install. Then this USB flash drive has two specifications: one is a bare FAT format, directly usable as a floppy disk; the other is a hard disk format containing partition table, directly usable as a hard disk. That is, the format of the USB flash drive becomes dual, and it can go smoothly whether the motherboard recognizes it as a floppy disk or a hard disk.
因为我们亲手创建,这个世界更加美丽。
Floor 3 Posted 2008-07-11 17:40 ·  中国 山西 太原 联通
银牌会员
★★★
Credits 1,009
Posts 353
Joined 2003-09-04 00:00
22-year member
UID 9419
Gender Male
Status Offline
My USB flash drive is formatted as a FAT16 hard disk, with an MBR and partition table. It has been heard that some machines' BIOS int13 cannot pass the correct DL value. However, at offset 7C24 in the USB flash drive boot sector, there is a physical drive number. When formatted as ZIP, it is 00 00; when formatted as HDD, it is 80 00. For a floppy disk, it is 00 00. When the USB flash drive is booted, the partition should be active, and as the first hard disk or floppy disk, so passing 00 or 80 to DL is correct.

GRUB4DOS installed in the MBR may have perfect judgment and booting functions, but when installed in the DBR, due to the limited code length, the functions may be reduced. But referring to the code of Microsoft's boot IO.SYS or boot NTLDR, they all pass 7C24 to DL, which is relatively safe and effective.

The reason for going through a lot of trouble is not to "take a unique path," mainly because the grubinst_gui installation of grub4dos was not successful. It may also be that installing with bootlace will be successful.
Floor 4 Posted 2008-07-11 18:50 ·  中国 河南 南阳 电信
银牌会员
★★★★
不甘寂寞的人
Credits 2,491
Posts 1,115
Joined 2003-09-24 00:00
22-year member
UID 10292
Gender Male
Status Offline
When grub4dos is installed in the DBR, the disk number at offset 24h you mentioned has been ignored, refer to the README file. We assume that the DL passed to the boot sector is always correct. We can ensure this as long as the MBR uses the boot code of GRLDR. It may not be guaranteed with other MBRs, but usually it's okay. And in the case of a floppy disk, we force the use of DL=0 because some buggy machines are found to use incorrect DL values for floppy disks. Since there is no MBR code when booting from a floppy disk, but it's directly called by the BIOS, we can't guarantee that the BIOS will definitely assign DL=0. That is, in this context, we force DL=0 when booting from a floppy disk, which is implemented by code. Our DH represents the partition number, which is what you should pay attention to. For a floppy disk, its so-called "partition number" is determined as 0xFF. Of course, the partition number of a hard disk can't be 0xFF. Therefore, if you are installing to a hard disk, you must modify 0xFF to an appropriate partition number.

We don't limit that it must boot from 0x80. If the DBR boot sector is installed at 0x81, we can also boot. If as you said, when your 0x80 disk is used as 0x81 for some reason, the grldr inside will not be able to boot (you must modify 80h at offset 24h to 81h).
因为我们亲手创建,这个世界更加美丽。
Floor 5 Posted 2008-07-11 21:36 ·  中国 山西 太原 联通
新手上路
Credits 12
Posts 5
Joined 2007-07-12 16:08
18-year member
UID 93799
Gender Male
Status Offline
Brothers. Since you're so capable. Help me take a look at my problem.
http://www.cn-dos.net/forum/viewthread.php?tid=41369&fpage=1

Now there's still a little bit left. That is, the installation of g2hdr.bin by IBM's BMGR is not successful.
Floor 6 Posted 2008-07-18 22:51 ·  中国 辽宁 辽阳 联通
初级用户
★★
DOS之迷
Credits 174
Posts 81
Joined 2007-11-07 21:13
18-year member
UID 102004
Gender Male
Status Offline
Personally, I think the best way to make a bootable USB drive is to boot into a DOS system on a computer that supports USB booting, then use DISKGEN to partition and format the removable disk or the SD card via the card reader. Then, using DSPTW to write the code in the XP system has a high success rate. I'm using a 1G removable disk and a 2G SD card.

The code is as follows

@echo off
color 0A

:mmbr
title Install GRUB MBR!
set hd=
cls
echo Please select the hard disk number where you want to install GRUB.
echo 0 1 2 3 4 5
echo Enter the number and press Enter to execute!
set /p hd="">nul
if not %hd%'==0' if not %hd%'==1' if not %hd%'==2' if not %hd%'==3' if not %hd%'==4' if not %hd%'==5' goto mmbr
if %hd%'==' goto mmbr

:mmbr1
set h=
ECHO The hard disk number you selected is %hd%! The following is the partition situation of this hard disk!
dsptw %hd% /l /y
ECHO Starting to install GRUB MBR!
echo Please select the operation you want.
echo Restore, enter Y Other keys to exit
echo Enter and press Enter to execute!
set /p h="">nul
if not %h%'==y' if not %h%'==Y' goto exit
if %h%'==' goto exit
ECHO Backing up the original MBR to the file mbry%hd%.bin before installing GRUB MBR!
dsptw %hd% 0 1 /s mbry%hd%.bin /y
ECHO Backup completed!
ECHO @
ECHO Backing up to the second sector...
dsptw %hd% 0 1 /D %hd% 1 /y
ECHO Backup to the second sector completed!
ECHO @
ECHO Writing 00h...
dsptw %hd% 0 0 /m /hex:EB5E01026D32FFFF0000000000000000 /Y
if errorlevel 1 goto err
ECHO Writing 00h completed!
ECHO @
ECHO Writing 10h...
dsptw %hd% 0 16 /m /hex:00000000000000000000000000000000 /Y
ECHO Writing 10h completed!
ECHO @
ECHO Writing 20h...
dsptw %hd% 0 32 /m /hex:00000000000000000000000000000000 /Y
ECHO Writing 20h completed!
ECHO @
ECHO Writing 30h...
dsptw %hd% 0 48 /m /hex:00000000000000000000000000000000 /Y
ECHO Writing 30h completed!
ECHO @
ECHO Writing 40h...
dsptw %hd% 0 64 /m /hex:00000000000000000000000000000000 /Y
ECHO Writing 40h completed!
ECHO @
ECHO Writing 50h...
dsptw %hd% 0 80 /m /hex:00000000000000000000000000000000 /Y
ECHO Writing 50h completed!
ECHO @
ECHO Writing 60h...
dsptw %hd% 0 96 /m /hex:E800005B81EB6300C1EB048CC801C38E /Y
ECHO Writing 60h completed!
ECHO @
ECHO Writing 70h...
dsptw %hd% 0 112 /m /hex:DB536A75CBF606020004740F31C08EC0 /Y
ECHO Writing 70h completed!
ECHO @
ECHO Writing 80h...
dsptw %hd% 0 128 /m /hex:BFFC0566B84455434566AB68002017BC /Y
ECHO Writing 80h completed!
ECHO @
ECHO Writing 90h...
dsptw %hd% 0 144 /m /hex:009031C951BA8000B408E8D800581607 /Y
ECHO Writing 90h completed!
ECHO @
ECHO Writing a0h...
dsptw %hd% 0 160 /m /hex:721580E13FF9740F91B40289C531DB41 /Y
ECHO Writing a0h completed!
ECHO @
ECHO Writing b0h...
dsptw %hd% 0 176 /m /hex:E8C2007202F6DC0E1F9C31F631FFB9DF /Y
ECHO Writing b0h completed!
ECHO @
ECHO Writing c0h...
dsptw %hd% 0 192 /m /hex:00FCF3A5BBFC2166B8475255AA663907 /Y
ECHO Writing c0h completed!
ECHO @
ECHO Writing d0h...
dsptw %hd% 0 208 /m /hex:7503E8401BEADA000020161F66390774 /Y
ECHO Writing d0h completed!
ECHO @
ECHO Writing e0h...
dsptw %hd% 0 224 /m /hex:336660A1180083F83F77223C11721E48 /Y
ECHO Writing e0h completed!
ECHO @
ECHO Writing f0h...
dsptw %hd% 0 240 /m /hex:BF0300B40299BB0002B9020060E87500 /Y
ECHO Writing f0h completed!
ECHO @
ECHO Writing 100h...
dsptw %hd% 0 256 /m /hex:61730A6031C0E86C00614F75E6666166 /Y
ECHO Writing 100h completed!
ECHO @
ECHO Writing 110h
dsptw %hd% 0 272 /m /hex:390775599D72400E1FAD88E6AD89C124 /Y
ECHO Writing 110h completed!
ECHO @
ECHO Writing 120h...
dsptw %hd% 0 288 /m /hex:3F742129E848F6D8BF0300B40268000D /Y
ECHO Writing 120h completed!
ECHO @
ECHO Writing 130h...
dsptw %hd% 0 304 /m /hex:0731DB60E83E0061730B6031C0E83500 /Y
ECHO Writing 130h completed!
ECHO @
ECHO Writing 140h...
dsptw %hd% 0 320 /m /hex:614F75E7F9E830110F87E21A83C60C81 /Y
ECHO Writing 140h completed!
ECHO @
ECHO Writing 150h...
dsptw %hd% 0 336 /m /hex:FEFE0172C27716BEB231B4089952E814 /Y
ECHO Writing 150h completed!
ECHO @
ECHO Writing 160h...
dsptw %hd% 0 352 /m /hex:005872099991243F740341EBBBBEA001 /Y
ECHO Writing 160h completed!
ECHO @
ECHO Writing 170h...
dsptw %hd% 0 368 /m /hex:E82600EBFE1E0652565755F9CD135D5F /Y
ECHO Writing 170h completed!
ECHO @
ECHO Writing 180h...
dsptw %hd% 0 384 /m /hex:5E5A071FC3FAB800208ED0BCDC8FFB66 /Y
ECHO Writing 180h completed!
ECHO @
ECHO Writing 190h...
dsptw %hd% 0 400 /m /hex:61071FEBB7B40ECD102EAC3C0075F6C3 /Y
ECHO Writing 190h completed!
ECHO @
ECHO Writing 1a0h...
dsptw %hd% 0 416 /m /hex:0D0A4D697373696E67204D42522D6865 /Y
ECHO Writing 1a0h completed!
ECHO @
ECHO Writing 1b0h...
dsptw %hd% 0 432 /m /hex:6C7065722E0000000000000000008001 /Y
ECHO Writing 1b0h completed!
ECHO @
ECHO Clearing data from sectors 3 to 62...
dsptw %hd% 2 60 /e /y
ECHO Clearing data from sectors 3 to 62 completed!
ECHO @
echo GRUB MBR installation completed!
echo The following is the MBR content after installing GRUB MBR
echo Press any key to continue!
pause >nul
ECHO Writing GRUB MBR to the file GRmbrx%hd%.bin...
dsptw %hd% 0 1 /s GRmbrx%hd%.bin /y
ECHO Writing completed!
dsptw %hd% 0 1 /l /p /a
ECHO Installing other GRUB MBR codes to sectors 3-17
dsptw %hd% 2 15 /R axyqd.bin /Y
ECHO Other codes installed completed!
goto exit

:err
echo GRUB MBR installation failed!

:exit
echo Press any key to exit!
echo Love Makes The World Go Ronud
echo Because of the illusory, so beautiful
echo Because of the illusory, so eternal
echo When you are lonely & when you are down
echo When you are helpless & when you are upset
echo The endless love @ Lingxi! Will bring you eternal happiness
echo Mtel:13050788308
echo QQ:71216716 E_mail:l.h.r.@163.com
pause >nul
愛意之无尽@灵犀!
QQ:71216716 E_mail:l.h.r.@163.com
Floor 7 Posted 2008-09-11 09:58 ·  中国 山西 太原 联通
银牌会员
★★★
Credits 1,009
Posts 353
Joined 2003-09-04 00:00
22-year member
UID 9419
Gender Male
Status Offline
Install GRUB4DOS on a USB drive using bootlace. Since the USB drive is assigned the drive letter B, the command is:
bootlace --floppy --chs 0x01

After installation, when checked with WinHex, the code was not written to track 0, and the boot sector of track 1 had 1 sector of code written, which is the code from 600-7FF of grldr (with different BPB).

It started successfully on a computer where the USB drive was recognized as A, but did not start successfully on a computer where it was recognized as C.

Because track 0 did not have the 16-sector grldr boot code written, the powerful boot function of grldr was not reflected. The problem with the boot sector code of track 1 still existed, as in floor 1.

At this time, the code still needs to be modified:
1. Change the code at 7C54 from 89 to 8B.
2. Change the code at 7C1C from 00 to 3F (implicit number of sectors), and change the code at 7C24 from 00 to 80 (physical drive number of the disk).
3. Modify grldr, and delete all '--ignore-floppies ' in the menu at the end of the file.

After modification, it can start normally regardless of whether the USB drive is recognized as A or C.

[ Last edited by yaya on 2008-9-11 at 10:03 AM ]
Floor 8 Posted 2008-09-11 16:30 ·  中国 河南 南阳 电信
银牌会员
★★★★
不甘寂寞的人
Credits 2,491
Posts 1,115
Joined 2003-09-24 00:00
22-year member
UID 10292
Gender Male
Status Offline
This little difficulty shouldn't be a problem for you, right? You should be fine if you operate on a machine that recognizes the USB flash drive as a hard disk.
因为我们亲手创建,这个世界更加美丽。
Forum Jump: