Search code examples
x86usbbootloaderdd

why newer computer unable to boot from usb drive?


I simply made a following bootloader

jmp $
times 510 - ($ - $$) db 0
db 0x55
db 0xaa

then I did following

nasm bootloader.asm -o bootloader

dd if=bootloader of=/dev/sdb bs=512 count=1

I tested on 2 computers. I set usb hdd as highest boot priority for both computer.

Old computer with Intel Pentium M process (lenovo) boot with the bootloader from usb drive

but Newer computer with Intel i5 process(lenovo) says that there's no operating system.

(if there's hdd on boot sequence, the usb led blinks several times and the computer boot from hdd drive. if there's no hdd on boot sequence, An error Operating System Missing occurs)

I opened a ubuntu utility called 'Bless' as super user and check /dev/sdb

indeed there is 0x55 0xaa at the 0x1fe and 0x1ff respectively.

I have no idea why I can't boot with it on some computer.

both computer has same UEFI setting, boot priority, no password.

please help


Solution

  • Some BIOS require that you add the BPB standard code to easily identify the the USB and its filesystem.

    You can add this to the start of your code to be identified with all BIOS. And Most of them with load it properly.

    Adding this works for all types of media. Floppy as well as HDD, USB, etc.
    This will add a recognised FAT12 file system to your drive as well.
    Check out osdev wiki.

    ;bits   16                      ; we are in 16 bit real mode
    use16
    org     0                   ; we will set regisers later
    
    start:  jmp main                    ; jump to start of bootloader
    ;nop                ; Pad out before disk description
    
    ; ------------------------------------------------------------------
    ; Disk description table, to make it a valid floppy
    ; Note: some of these values are hard-coded in the source!
    ; Values are those used by IBM for 1.44 MB, 3.5" diskette
    
    bpbOEM          db "My OS   " ; Disk label
    bpbBytesPerSector:      DW 512 ; Bytes per sector
    bpbSectorsPerCluster:   DB 1 ; Sectors per cluster
    bpbReservedSectors:     DW 1 ; Reserved sectors for boot record
    bpbNumberOfFATs:    DB 2 ; Number of copies of the FAT
    bpbRootEntries:     DW 224 ; Number of entries in root dir
    ; (224 * 32 = 7168 = 14 sectors to read)
    bpbTotalSectors:    DW 2880 ; Number of logical sectors
    bpbMedia:       DB 0xf0  ;; 0xF1 ; Medium descriptor byte
    bpbSectorsPerFAT:   DW 9 ; Sectors per FAT
    bpbSectorsPerTrack:     DW 18 ; Sectors per track (36/cylinder)
    bpbHeadsPerCylinder:    DW 2 ; Number of sides/heads
    bpbHiddenSectors:   DD 0 ; Number of hidden sectors
    bpbTotalSectorsBig:     DD 0 ; Number of LBA sectors
    bsDriveNumber:          DB 0 ; Drive No: 0
    bsUnused:       DB 0
    bsExtBootSignature:     DB 0x29;0x41 ; Drive signature: 41 for floppy
    bsSerialNumber:         DD 0xa0a1a2a3 ; Volume ID: any number
    bsVolumeLabel:          DB "MOS FLOPPY " ; Volume Label: any 11 chars
    bsFileSystem:           DB "FAT12   " ; File system type: don't change!
    
    maincode:
    
    jmp $
    times 510 - ($ - $$) db 0
    db 0x55
    db 0xaa
    

    Compile it as usual with nasm. And set it as MBR with dd.