『楼 主』:
usb-hdd模式的u盘被识别为软盘初探
使用 LLM 解释/回答一下
u盘格式化为usb-hdd,启动时主板一般识别为硬盘,分配盘符c。但是有的主板会识别为软盘,分配盘符a。这两种情况都能正常启动。
我们知道,硬盘的0-0-1(或逻辑扇区0)是主引导记录MBR,内含分区表。间隔3f扇区(隐含扇区数)即0-1-1(或逻辑扇区3f)是启动扇区DBR,内含BPB参数。启动硬盘时,首先加载主引导记录,然后由主引导记录再加载启动扇区。启动程序查找引导文件(io.sys、ntldr或grldr等)时,要计算文件分配表、目录区、数据区扇区的起始位置(CHS或LBA),此时要用到隐含扇区数(3F)这个参数。执行读操作int13/02(或42)时,把磁盘的物理驱动器号80赋给dl。
而软盘的0-0-1(或逻辑扇区0)是启动扇区DBR,内含BPB参数。启动软盘时,直接加载启动扇区。启动程序查找引导文件(io.sys、ntldr或grldr等)时,也要计算文件分配表、目录区、数据区扇区的起始位置(CHS或LBA),此时要用到隐含扇区数(00)这个参数。执行读操作int13/02(或42)时,把磁盘的物理驱动器号00赋给dl。
这就产生了疑问。u盘格式化为usb-hdd,其BPB参数的磁盘物理驱动器号是80(偏移7C24处),隐含扇区数是00 00 00 3F(偏移7C1C处),此时按硬盘正常启动可以理解。而按软盘启动,本应该赋给dl的00成了80,隐含扇区数00成了3F,怎么会正确地找到引导文件?
为了探明这个奥秘,编了一段测试代码,经探测后发现:
1.启动后首先加载启动扇区到7C00,为0-0-1(或逻辑扇区0),看不到主引导记录。
2.修改7C24处为00(磁盘物理驱动器号),修改7C1C处为00 00 00 00(隐含扇区数)。(修改内存,不是u盘!)
3.然后从7C00处开始执行启动代码。
原来是主板修改了BPB参数,所以能正确地找到引导文件,成功启动。
另外探测到:BIOS加载0-0-1(对于硬盘是主引导记录,对于软盘是启动扇区)时,dl代入的参数是磁盘物理驱动器号,u盘被识别为硬盘时DX=0080,被识别为软盘时DX=0000。
BIOS加载0-1-1(u盘被识别为硬盘时)时,DX=0180。
u盘格式化为usb-hdd被主板识别为软盘,好处是不占用盘符c,对安装操作系统有好处。提醒:如果u盘分为2个分区,另一个分区会分配盘符c!
u盘格式化为usb-hdd被主板识别为软盘,此时用bootlace.com安装grub4dos,不能在识别为硬盘时正常启动,需修改启动扇区:
1.用WinHex打开磁盘;
2.将7E1C处00改为3F,将7E24处00改为80,将7E54处89改为8B。
3.修改grldr,把文件末尾菜单中的‘--ignore-floppies ’全删除。
或者在被主板识别为硬盘的电脑上用bootlace.com安装grub4dos.
Last edited by yaya on 2008-9-12 at 04:10 PM ]
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 ]
|