自己动手写操作系统:3.搭建虚拟机并验证系统bootloader

本次制作操作系统 所有的程序编译都运行在 ubuntu 14中,虚拟机也是安装在ubuntu中的,我们把ubuntu作为我们的编译运行环境,程序的编写我们在windows中。 

前面在第一节中介绍了怎么搭建samba环境,现在我们介绍写怎么搭建虚拟机环境。

ubuntu中使用命令 apt-get install kvm qemu libvirt-bin virtinst virt-manager virt-viewer安装好虚拟机运行环境

使用下面的脚本配置虚拟机:

<domain type='kvm'>

  <name>30OS</name>

  <memory unit='KiB'>838</memory>

  <currentMemory unit='KiB'>838</currentMemory>

  <vcpu placement='static'>1</vcpu>

  <os>

    <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>

    <boot dev='fd'/>

  </os>

  <features>

    <acpi/>

  </features>

  <clock offset='utc'/>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>destroy</on_crash>

  <devices>

    <emulator>/usr/bin/kvm</emulator>

    <disk type='file' device='floppy'>

      <driver name='qemu' type='raw'/>

      <source file='/home/xj/30OPS/Source/system.img'/>

      <target dev='fda' bus='fdc'/>

      <address type='drive' domain='0x0000' bus='0' unit='0'/>

    </disk>

    <controller type='ide' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

    </controller>

    <controller type='usb' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>

    </controller>

    <controller type='pci' index='0' model='pci-root'/>

 

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>

      <listen type='address' address='0.0.0.0'/>

    </graphics>

    <video>

      <model type='cirrus' vram='9216' heads='1'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>

    </video>

    <memballoon model='virtio'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>

    </memballoon>

  </devices>

</domain>

 

上面配置最重要的是要设置为从软驱启动系统!

虚拟机命令介绍:

virsh define HelloOS.xml   用来生成虚拟机

virsh unfefine HelloOs 删除虚拟机

virsh start HelloOS 启动虚拟机

virsh destroy HelloOS 关闭虚拟机

 

我们使用上面的配置文件生成虚拟机:

 virsh define HelloOS.xml  

接着启动虚拟机:

 virsh start HelloOS

 

因为我们在终端上面操作,看不到虚拟机启动界面,使用VNC工具

连接 10.46.75.99:3 表示这是系统中的第四个虚拟机,可以看到虚拟机显示的画面。

可以看到我们跑在操作系统的第一个程序已经成功!

 

有的朋友习惯使用vmare,这里也提供vmare验证的方式:

需要把我们生成的img文件设置为上电启动。

启动后的效果如图所示:表明我们的程序有效了!


为了简化我们每次的操作,我把命令嵌入SCRT的快捷按钮中:

nasm A.asm -o A.boot && gcc ReadWrite.c -o ReadWrite &&./ReadWrite\r   一键编译并生成img文件

virsh destroy 30OS && virsh start 30OS\r 一键重启系统(装载我们新生成的img文件)(使用kvm建立虚拟机时适用)


下一步我们将突破512字节的限制,毕竟操作系统需要实现复杂的功能需要的空间远大于512字节!

 

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值