(转)如何在Linux上使用Bochs

作者:王聪

http://wangcong.org/articles/bochs.html

引言

    最近在做操作系统方面的研究,不得不去下一个虚拟机 来用。由于我不使用Windows,所以选择很少了。因为在Linux上,差不多就只有两款好的 虚拟机——Bochs和Qemu。这两个之中,Bochs是用C++编写,能在很多平台上使用,而且不论什么平台, 它都不倚赖主机的指令系统,总是模拟x86。所以我选择了Bochs。但是,我惊讶地发现 关于如何在Linux上使用Bochs的资料很少。Bochs自带的文档中讲得也不很明确,而且还 是英文的。所以我写了这篇文章。

安装

    到Bochs的主页: http://bochs.sourceforge.net 上下载最新的Bochs RPM安装包。(写这篇文章时,最新的版本是2.2.1。)以root的身份安装:

#rpm -ivh bochs-2.2.1-1.i586.rpm
其实RPM安装包给你装上了四个新程序:bochs,bochs-dlx,bximage,bxcommit, 以及相关文档。安装完毕后,你可以先试试bochs-dlx,它是DLX Linux的一个demo。
$ bochs-dlx
---------------------------------------------------------------
            DLX Linux Demo, for Bochs x86 Emulator
---------------------------------------------------------------
Checking for bochs binary...ok
Checking for DLX linux directory...ok
Checking for /usr/bin/gzip...ok
Checking for /home/wangcong/.bochsdlx directory...ok
Entering /home/wangcong/.bochsdlx
Running bochs
00000000000i[APIC?] local apic in initializing
========================================================================
                        Bochs x86 Emulator 2.2.1
                Build from CVS snapshot on July 8, 2005
========================================================================
00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins'
00000000000i[ ] BXSHARE not set. using compile time default '/usr/share/bochs'
00000000000i[ ] reading configuration from bochsrc.txt
00000000000i[ ] lt_dlhandle is 0x8bac490
00000000000i[PLGIN] loaded plugin libbx_x.la
00000000000i[ ] installing x module as the Bochs GUI
00000000000i[ ] using log file bochsout.txt
马上,你就会看到一个X11窗口。

显示的是VGA BIOS信息,然后是加载Linux的信息。以root身份登录,试试DLX Linux。安装成功。

使用

    下面是一些重要的文件:

/usr/bin/bochs
Bochs启动程序

/usr/bin/bximage
Bochs带的制作磁盘镜像文件的工具

/usr/bin/bxcommit
把redolog放进flat磁盘镜像文件中去的交互工具

/usr/share/doc/bochs/bochsrc-sample.txt
Bochs配置文件的例子

/usr/share/bochs/BIOS-bochs-*
ROM BIOS镜像文件

/usr/share/bochs/VGABIOS-*
与VGA BIOS镜像文件相关的文件

/usr/bin/bochs-dlx
启动Bochs中DLX linux的程序

/usr/share/bochs/dlxlinux/
DLX Linux的目录,包含它的磁盘镜像文件和配置文件

/usr/share/bochs/keymaps/*.map
X11和SDL的keymap列表

    命令bohcs可以接受4个参数:-q 加载配置文件后跳过开始菜单;-f configfile 识别指定的配制文件;-n 不加载配置文件;-h 打印帮助信息;-qf configfile 相当于同时使用-q和-f两个选项。使用Bochs,你必须有一个配置文件,或者你通 过-f参数指定,或者让Bochs自己搜索。配置文件的作用是告诉Bochs到哪里寻找镜像 文件,模拟层如何工作等。Bochs搜索配置文件的顺序是:

  1. .bochsrc 在当前目录中</TT CLASS="FILENAME">

  2. bochsrc 在当前目录中

  3. bochsrc.txt 在当前目录中</TT CLASS="FILENAME">

  4. .bochsrc 在用户的主目录中

  5. bochsrc/etc 目录中

以dlx-linux的配置文件为例,讲一下如何定制你需要的配置文件。dlx-linux的 配置文件是/usr/share/doc/bochs目录中的bochsrc-sample.txt。它的内容 如下:
###############################################################
# bochsrc.txt file for DLX Linux disk image.
###############################################################
# how much memory the emulated machine will have
megs: 32
# filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
# what disk images will be used
floppya: 1_44=floppya.img, status=inserted
floppyb: 1_44=floppyb.img, status=inserted
# hard disk
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4, spt=17
# choose the boot disk.
boot: c
# default config interface is textconfig.
#config_interface: textconfig
#config_interface: wx
#display_library: x
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga
# where do we send log messages?
log: bochsout.txt
# disable the mouse, since DLX is text only
mouse: enabled=0
# enable key mapping, using US layout as default.
#
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X windows.
# However, the key mapping tables are used in the paste function, so
# in the DLX Linux example I'm enabling keyboard_mapping so that paste
# will work. Cut&Paste is currently implemented on win32 and X windows only.
keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map

以#开头的每一行都是注释。注释写得很明白。

megs: 32
指明想要模拟32M的内存。注意:后面的数字最大为2048,但是因为主机系统的限制,在 大多数系统上,Bochs甚至不能支持1024M。
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000
指明ROM的镜像文件在哪,开机时ROM BIOS被加载到哪里。$BXSHARE是环境变量,指明 Bochs的share目录,在Linux上为/usr/share/bochs。这一般不用改动。下面的vgaromimage 指明VGA ROM的镜像文件位置。
floppya: 1_44=floppya.img, status=inserted
floppyb: 1_44=floppyb.img, status=inserted
floppya是第一软驱,floppyb是第二软驱。后面标明的是软驱镜像文件的位置,软盘 是否插入。可以根据你的需要做适当的修改。
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4, spt=17
打开ata0通道,另外还有ata1,ata2,ata3。对于每一个通道,都必须指明两个IO地址和IRQ。 ata0是默认被打开的,它的ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14。ata0-master 是主ata0通道,后面指明它附带的设备是硬盘,硬盘镜像文件路径,硬盘柱面数,磁头数等参数。
boot: c
指明启动次序,可以是cdrom,floppy,disk。不过由于历史的原因a和c也能被接受。 也可以这样来写:
boot: cdrom, floppy, disk
mouse: enabled=0
指明鼠标是否可见。
keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
打开对虚拟US键盘的重映射,keymap必须被指明。
    更多的配置文件选项说明见/usr/share/doc/bochs/user/bochsrc.html。 如何编写键盘的keymap列表见/usr/share/doc/bochs/user/keymap.html。

制作磁盘镜像

    bximage是Bochs自带的制作磁盘镜像的工具,具有 良好的交互性,使用很方便。运行bximage,你会看到:

========================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
      $Id: bximage.c,v 1.25.2.1 2005/07/06 20:40:00 vruppert Exp $
========================================================================
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd]
询问我们是建立一个软盘镜像还是硬盘镜像,默认的是硬盘。我们直接按回车,选择硬盘 镜像。
What kind of image should I create?
Please type flat, sparse or growing. [flat]
我们想建立一个简单的镜像,选择默认的flat。回车。
Enter the hard disk size in megabytes, between 1 and 32255
[10]
想要多少Mbyte的大小?键入你想要的大小。
I will create a 'flat' hard disk image with
  cyl=2
  heads=16
  sectors per track=63
  total sectors=2016
  total size=0.98 megabytes
What should I name the image?
[c.img]
在上一步中输入“1”后,显示相关的硬盘信息。询问想要什么镜像文件名字?默认的是 c.img。输入hd.img回车。
Writing: [] Done.
I wrote 1032192 bytes to hd.img.
The following line should appear in your bochsrc:
  ata0-master: type=disk, path="hd.img", mode=flat, cylinders=2, heads=16, spt=63
建立完毕。然后你就可以使用这个镜像,用Bochs做实验了。

    另外Bochs还有强大的调试功能,详细请参阅用户 手册第8章。Bochs主页上还有一些做好的系统镜像,比如:OpenBSD,FreeDOS等。 不妨下载一个来试试。 Bochs的确是一款优秀的工具,我推荐给每一位做操作系统研究的朋友。

转载于:https://www.cnblogs.com/kuainiao/archive/2012/12/20/2825981.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值