自己写个操作系统《一》制作启动U盘,真机启动

来源:互联网 发布:什么阅读软件最好 编辑:程序博客网 时间:2024/05/20 16:00

网络上不少介绍写个简易操作系统的文章,大都是制作一个软盘映像文件,然后从虚拟软驱中启动。我希望能直接将系统放入U盘,直接从U盘启动。经过一番尝试,成功了。

1、一台centos linux物理机

2、as86、ld86工具

下载地址 ftp://rpmfind.net/linux/centos/6.8/os/x86_64/Packages/dev86-0.16.17-15.1.el6.x86_64.rpm

安装  rpm -ivh dev86-0.16.17-15.1.el6.x86_64.rpm

3、新建汇编文件 boot.s

  1.     BOOTSEG= 0x07c0
  2.     entry     start
  3. start:
  4.     jmpi    go, BOOTSEG
  5. go:    
  6.     mov    ax,cs
  7.     mov     dx,ax
  8.     mov     es,ax
  9.     mov     [msg+17],ah
  10.     mov     cx, #20
  11.     mov     dx, #0x1004
  12.     mov     bx, #0x000c
  13.     mov     bp, #msg
  14.     mov     ax, #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、新建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、执行make,得到boot.bin

6、机器上插入u盘

7、切换到root用户

8 、fdisk指令查看U盘设备名称,我这里查到的是 /dev/sdb

9、将boot.bin写入到u盘

dd if=boot.bin of=boot.bin bs=512 count=1

10、重启系统,将u盘设置为启动设备

11、大功造成

可以看到系统启动起来,屏幕上显示 红色的 Loding system...


附:

如果是制作软件映像文件Makefile可以这样写

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

0 0
原创粉丝点击