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-24 23:39
中国DOS联盟论坛 » GRUB4DOS、SYSLINUX及其它启动管理软件讨论专区 » A Preliminary Exploration of USB - HDD Mode USB Flash Drives Recognized as Floppy Disks View 2,706 Replies 4
Original Poster Posted 2008-09-11 10:05 ·  中国 山西 太原 联通
银牌会员
★★★
Credits 1,009
Posts 353
Joined 2003-09-04 00:00
22-year member
UID 9419
Gender Male
Status Offline
When a USB flash drive is formatted as USB-HDD, when booting, the mainboard generally recognizes it as a hard disk and assigns drive letter C. But some mainboards will recognize it as a floppy disk and assign drive letter A. Both situations can boot normally.

We know that the 0-0-1 (or logical sector 0) of a hard disk is the Master Boot Record (MBR), which contains the partition table. There are 3F sectors (number of hidden sectors) apart, that is, 0-1-1 (or logical sector 3F) is the Boot Sector (DBR), which contains BPB parameters. When booting a hard disk, the Master Boot Record is loaded first, and then the Boot Sector is loaded by the Master Boot Record. When the boot program looks for the boot file (io.sys, ntldr or grldr, etc.), it needs to calculate the starting positions (CHS or LBA) of the sectors of the File Allocation Table, Directory Area, and Data Area. At this time, the parameter of the number of hidden sectors (3F) is used. When performing the read operation int13/02 (or 42), the physical drive number 80 of the disk is assigned to dl.

And the 0-0-1 (or logical sector 0) of a floppy disk is the Boot Sector (DBR), which contains BPB parameters. When booting a floppy disk, the Boot Sector is directly loaded. When the boot program looks for the boot file (io.sys, ntldr or grldr, etc.), it also needs to calculate the starting positions (CHS or LBA) of the sectors of the File Allocation Table, Directory Area, and Data Area. At this time, the parameter of the number of hidden sectors (00) is used. When performing the read operation int13/02 (or 42), the physical drive number 00 of the disk is assigned to dl.

This gives rise to a question. For a USB flash drive formatted as USB-HDD, the physical drive number of the disk in its BPB parameters is 80 (at offset 7C24), and the number of hidden sectors is 00 00 00 3F (at offset 7C1C). At this time, it can be understood that it boots normally as a hard disk. But when booting as a floppy disk, the 00 that should be assigned to dl becomes 80, and the number of hidden sectors 00 becomes 3F. How can it correctly find the boot file?

In order to explore this mystery, a section of test code was compiled. After detection, it was found:
1. After booting, the Boot Sector is first loaded to 7C00, which is 0-0-1 (logical sector 0), and the Master Boot Record is not visible.
2. Modify 7C24 to 00 (physical drive number of the disk), and modify 7C1C to 00 00 00 00 (number of hidden sectors). (Modify memory, not the USB flash drive!)
3. Then execute the boot code from the 7C00 place. It turns out that the mainboard modifies the BPB parameters, so it can correctly find the boot file and boot successfully.

In addition, it was detected that when the BIOS loads 0-0-1 (for a hard disk it is the Master Boot Record, for a floppy disk it is the Boot Sector), the parameter substituted for dl is the physical drive number of the disk. When the USB flash drive is recognized as a hard disk, DX=0080, and when it is recognized as a floppy disk, DX=0000.
When the BIOS loads 0-1-1 (when the USB flash drive is recognized as a hard disk), DX=0180.

The advantage of a USB flash drive formatted as USB-HDD and recognized as a floppy disk by the mainboard is that it does not occupy drive letter C, which is beneficial for installing the operating system. Reminder: If the USB flash drive is divided into 2 partitions, the other partition will be assigned drive letter C!

When a USB flash drive formatted as USB-HDD is recognized as a floppy disk by the mainboard, using bootlace.com to install grub4dos cannot boot normally when recognized as a hard disk. It is necessary to modify the boot sector:
1. Open the disk with WinHex;
2. Change 00 at 7E1C to 3F, change 00 at 7E24 to 80, and change 89 at 7E54 to 8B.
3. Modify grldr, and delete all '--ignore-floppies ' in the menu at the end of the file.
Or install grub4dos with bootlace.com on a computer where it is recognized as a hard disk by the mainboard.

[ Last edited by yaya on 2008-9-12 at 04:10 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
fujianabc +3 2008-09-12 10:23
Floor 2 Posted 2008-09-12 10:23 ·  中国 上海 中国科学院上海分院
金牌会员
★★★★
Credits 3,467
Posts 1,616
Joined 2004-06-21 00:00
22-year member
UID 27148
Status Offline
That's a good analysis, quite profound.
Floor 3 Posted 2008-09-12 10:53 ·  中国 河南 南阳 电信
银牌会员
★★★★
不甘寂寞的人
Credits 2,491
Posts 1,115
Joined 2003-09-24 00:00
22-year member
UID 10292
Gender Male
Status Offline
Yaya, you've done a great job. If you could join the development of grub4dos, I think many people would be happy.
因为我们亲手创建,这个世界更加美丽。
Floor 4 Posted 2008-09-12 16:33 ·  中国 山西 太原 联通
银牌会员
★★★
Credits 1,009
Posts 353
Joined 2003-09-04 00:00
22-year member
UID 9419
Gender Male
Status Offline
Don't overpraise me. My understanding of DOS is still very superficial, and I have only initially dabbled in grub4dos. I don't think I'm qualified to be a grub4dos developer. However, if I can do something within my ability to contribute to the development of grub4dos, I am willing to offer my help.
Floor 5 Posted 2008-09-12 18:49 ·  中国 河南 南阳 电信
银牌会员
★★★★
不甘寂寞的人
Credits 2,491
Posts 1,115
Joined 2003-09-24 00:00
22-year member
UID 10292
Gender Male
Status Offline
yaya, you are very familiar with assembly language and also have a good understanding of boot sectors and the boot process. Therefore, I think you are the most suitable to participate in the development of grub4dos. Even if you don't participate in grub4dos, you should join the development of some other boot software. Why not join grub4dos? Or you can observe and understand for a period of time before making a decision. grub4dos needs someone like you. You can first join in an informal capacity, do some preparatory work, submit some patches and so on. Then, when you are sure that you have time or willingness in the future, you can join formally. There is no pressure at all in developing grub4dos, that's how I feel. So our main focus is entirely on: how to design grub4dos better?

Oh, I forgot to say, yaya, your name is very good, very grand, I appreciate this name. Originally, my name was chosen a bit casually, and now I'm not satisfied.

[ Last edited by 不点 on 2008-9-13 at 11:47 AM ]
因为我们亲手创建,这个世界更加美丽。
Forum Jump: