Write an operating system "One" by yourself, make a bootable U disk, and start the real machine

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

  1.     BOOTSEG = 0x07c0
  2.     entry     start
  3. start:
  4.     jmpi    go, BOOTSEG
  5. go:    
  6.     mov ax , cs    
  7.     movdx,ax     
  8.     moves,ax     
  9.     mov[msg+17],ah     
  10.     movcx, #20     
  11.     movdx, #0x1004     
  12.     mov     bx, #0x000c
  13.     movbp, #msg     
  14.     movax, #0x1301     
  15.     int     0x10
  16. loop0:    
  17.     jmp     loop0
  18. msg:   
  19.     .ascii    "Loading system..."
  20.     .byte     0x0d, 0x0a, 0x00
  21.     .org      510
  22.     .word     0xaa55
4. Create a new Makefile

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325370073&siteId=291194637