There are many articles on the Internet that introduce and write a simple operating system, most of which are to create a floppy disk image file and then boot from the virtual floppy drive. I want to be able to put the system directly into the USB flash drive and boot directly from the USB flash drive. After some attempts, it worked.
1. A centos linux physical machine
2, as86, ld86 tools
Download address ftp://rpmfind.net/linux/centos/6.8/os/x86_64/Packages/dev86-0.16.17-15.1.el6.x86_64.rpm
install rpm -ivh dev86-0.16.17-15.1.el6.x86_64.rpm
3. Create a new assembly file boot.s
- BOOTSEG = 0x07c0
- entry start
- start:
- jmpi go, BOOTSEG
- go:
- mov ax , cs
- movdx,ax
- moves,ax
- mov[msg+17],ah
- movcx, #20
- movdx, #0x1004
- mov bx, #0x000c
- movbp, #msg
- movax, #0x1301
- int 0x10
- loop0:
- jmp loop0
- msg:
- .ascii "Loading system..."
- .byte 0x0d, 0x0a, 0x00
- .org 510
- .word 0xaa55
boot.bin: boot.o
ld86 -0 -d -s -o boot.bin boot.o
boot.o: boot.s
as86 -0 -o boot.o boot.s
5. Execute make to get boot.bin
6. Insert the u disk into the machine
7. Switch to root user
8. The fdisk command checks the device name of the U disk. What I found here is /dev/sdb
9. Write boot.bin to the U disk
dd if=boot.bin of=boot.bin bs=512 count=1
10. Restart the system and set the U disk as the boot device
11. Great success
You can see that the system starts up, and the red Loding system is displayed on the screen...
Attached:
If you are making a software image file Makefile can be written like this
boot.img: boot.img_
dd if=/dev/zero of=boot.img seek=1 bs=512 count=2879
boot.img_: boot.bin
dd if=boot.bin of=boot.img_ bs=512 count=1
boot.bin: boot.o
ld86 -0 -d -s -o boot.bin boot.o
boot.o: boot.s
as86 -0 -o boot.o boot.s