自己写操作系统 2 - 安装bochs虚拟机

 以ubuntu操作系统为例

一、命令行安装

sudo apt-get install vgabios bochs bochs-x bximage

此方法方便,不过都说这个方法安装的bochs没有调试功能,所以我没有尝试,有时间再补充验证吧

 

二、源码安装

1. 源码下载

https://sourceforge.net/projects/bochs/files/bochs/

直接下载当前最新的源码,准备在linux上安装,所以下载的 bochs-2.6.9.tar.gz

2. 安装前准备

sudo apt-get install build-essential xorg-dev libgtk2.0-dev bison

省掉config过程很多依赖编译报错

3. 编译安装

sudo tar xvzf bochs-2.6.9.tar.gz

cd bochs-2.6.9

./configure  --enable-debugger --enable-disasm --enable-readline -LIBS='lx11'

make

sudo make install

make install 会把bochs可执行文件拷贝到/usr/local/bin/目录下

重启linux或者让环境变量重新生效,可以直接在当前目录下调用bochs

4. 修改bochsrc配置文件

在bochs-2.6.9目录下,有一个配置文件 .bochsrc,我们需要修改,让他运行我们的a.img

#cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
cpu: model=amd_k6_2_chomper, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
cpu: cpuid_limit_winnt=0

memory: guest=512, host=256

romimage: file=$BXSHARE/BIOS-bochs-latest, options=fastboot

vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest

mouse: enabled=0

pci: enabled=1, chipset=i440fx

private_colormap: enabled=0

#floppya: 1_44=/dev/fd0, status=inserted
#floppya: image=../1.44, status=inserted
#floppya: 1_44=/dev/fd0H1440, status=inserted
#floppya: 1_2=../1_2, status=inserted
#floppya: 1_44=a:, status=inserted
floppya: 1_44=a.img, status=inserted, write_protected=1
#floppya: 1_44=/dev/rfd0a, status=inserted

ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata2: enabled=0, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11
ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9

#ata0-master: type=disk, mode=flat, path="30M.sample"
#ata0-master: type=disk, mode=flat, path="30M.sample", cylinders=615, heads=6, spt=17
#ata0-master: type=disk, mode=flat, path="c.img", cylinders=0 # autodetect
#ata0-slave: type=disk, mode=vvfat, path=/bochs/images/vvfat, journal=vvfat.redolog
#ata0-slave: type=cdrom, path=D:, status=inserted
#ata0-slave: type=cdrom, path=/dev/cdrom, status=inserted
#ata0-slave: type=cdrom, path="drive", status=inserted
#ata0-slave: type=cdrom, path=/dev/rcd0d, status=inserted 

boot: floppy
#boot: disk

floppy_bootsig_check: disabled=0

log: bochsout.txt

panic: action=ask
error: action=report
info: action=report
debug: action=ignore, pci=report # report BX_DEBUG from module 'pci'

debugger_log: -

parport1: enabled=1, file="parport.out"

#sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
#speaker: enabled=1, mode=sound

  有注释的地方基本都是改动过的,解决了下一步启动运行过程中,几个问题

5. 启动运行bochs虚拟机

bochs -f .bochsrc

 

能到这一步,如果有问题,大部分都是bochsrc配置的问题,可以查看报错点,尝试注释掉,确保最基本的几个配置基本就可以正常运行了

例如:

memory: guest=512, host=256
romimage: file=$BXSHARE/BIOS-bochs-latest, options=fastboot
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
floppya: 1_44=a.img, status=inserted, write_protected=1
boot: floppy

 

启动过程可能遇到的问题:

问题1:.bochsrc:187: cpu directive malformed

解决方法:

linux终端下:bochs -help cpu

 

我的电脑是AMD处理器,我就选amd_k6_2_chomper

修改配置文件即可

#cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
cpu: model=amd_k6_2_chomper, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"

问题2:.bochsrc:915: Bochs is not compiled with lowlevel sound support

解决方法:修改配置文件,注释掉以下两行

#sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
#speaker: enabled=1, mode=sound

 问题3:syntax error at 'dump_cpu'

解决方法:none

bochs 2.3.5 以上的版本没有dump_cpu了,可以用r,fp,mmx,sse,dreg,sreg,creg命令代替

 

 

参考:https://blog.csdn.net/time4/article/details/25079417

posted @ 2019-03-23 23:29  lr_ting  阅读(6019)  评论(0编辑  收藏  举报
simple statistics
Econo Lodge Coupons