USB boot
To boot USB-Stick (USB-HDD), some BIOSs will boot only first BIOS's detected
Boot-Record of first partition, and does not use partition geometry described in MBR.
To boot from MBR in this cases it is necessary to add a boot code in Boot-Record,
that read and execute MBR (i.e. in MBR is istalled LILO to boot second partition).
A suitable Boot-Record to do this is in zorosboot file (512 bytes) and the script
set-usb-boot.sh is used to read original first Boot-Record and link this with
zorosboot code, retaining Boot-Record informations (i.e. FAT32 structure).
The script make file "ZZ_BOOT"; this new Boot-Record will replace original using
"dd" command.
Source code (masm)
- Code: Select all
;----------------------------------------------------------------------------
; zorosboot.asm copyleft Fabio Zorba 2002-2009
; Date: 18-11-02 (ZZ-BOOT idea is now zoros)
; Last reviewed: 17-03-09
;----------------------------------------------------------------------------
;
BITS 16
;
section .data
;
Start equ 7C00h
ZZ_CS equ 2000h
;
Part_Table equ 01BEh
;
section .text
ORG 0
global MAIN
;----------------------------------------------------------------------------
MAIN:
;----------------------------------------------------------------------------
jmp Start_ZZ
times 147 db 0 ;reserved for boot sector description
ZZ_Name db 'ZZB'
ZZ_Disk db 80h
ZZ_Sect db 1,0
ZZ_Segm dw ZZ_CS
Start_ZZ:
cli ;no interrupts
xor ax, ax ;reset AX
mov ss, ax ;reset Stack Segment
mov si, Start ;offset start of code
mov sp, si ;set stack area
sti
mov di, 0 ;offset relocated code
mov ax, ZZ_CS
mov es, ax
mov ax, cs
mov ds, ax
mov word [7C00h+510],0 ;reset boot record signature
mov cx, 512
cli
cld
rep movsb ;relocate to 2000:0
sti
jmp ZZ_CS:Relocated
Relocated:
push cs
pop ds
xor ax, ax
mov es, ax
mov bx, Start ;offset 7C00
mov cx, 5
Loop_Disk_Read:
push cx
mov cl, [ZZ_Sect] ;start sector of ZZ-BOOT
mov al, 1 ;n. sectors to read
mov ch, 0 ;Track 0
mov dh, 0 ;Head 0
mov dl, [ZZ_Disk] ;Drive
mov ah, 2
int 13h ;Read MBR
pop cx
jnc OK_Disk_Read
loop Loop_Disk_Read
mov si, DiskError_Msg
call Stampa
jmp Wait_Key
xor ax, ax
int 16h
int 19h
OK_Disk_Read:
cmp word [es:7C00h+510], 0AA55h
jnz Error_MBR_Signature
mov ax, 0E07h ;speaker beep
int 10h
int 10h
jmp 0:7C00h
Error_MBR_Signature:
mov si, MBR_Error_Msg
call Stampa
Wait_Key:
xor ax, ax
int 16h
int 19h
;----------------------------------------------------------------------------
;print asciiz string
Stampa:
push si
loop_stampa:
cld
lodsb
or al, al
jnz next_ch
pop si
ret
next_ch:
mov ah, 0Eh
int 10h
jmp loop_stampa
;
;----------------------------------------------------------------------------
;
MBR_Error_Msg db 13,10,'MBR err',0
DiskError_Msg db 13,10,'no DISK',0
;
times 192 db 0
end_ss db 55h,0AAh
;
;----------------------------------------------------------------------------
END_OF_CODE:
Note:
when this code boot properly, it send two consecutive beeps.
Warning !
Pay attention, you can destroy filesystem if you does not operate carefully.
