如何在Linux上使用Bochs
2010-04-09 23:02
204 查看
如何在Linux上使用Bochs
作者:王聪
引言
最近在做操作系统方面的研究,不得不去下一个虚拟机来用。由于我不使用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窗口。
![](http://www.wangcong.org/images/scrshot.jpg)
显示的是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列表 |
识别指定的配制文件;-n 不加载配置文件;-h 打印帮助信息;-qf configfile
相当于同时使用-q和-f两个选项。使用Bochs,你必须有一个配置文件,或者你通
过-f参数指定,或者让Bochs自己搜索。配置文件的作用是告诉Bochs到哪里寻找镜像
文件,模拟层如何工作等。Bochs搜索配置文件的顺序是:
.bochsrc
在当前目录中
bochsrc
在当前目录中
bochsrc.txt
在当前目录中
.bochsrc
在用户的主目录中
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的确是一款优秀的工具,我推荐给每一位做操作系统研究的朋友。
http://hi.baidu.com/gao6081295/blog/item/82dcb94585f80144510ffe9d.html http://blog.chinaunix.net/u1/51827/showart.php?id=2199862
原文地址
http://www.wangcong.org/articles/bochs.html
相关文章推荐
- (转)如何在Linux上使用Bochs
- 如何在Linux上使用Bochs(转载的)
- 如何在Linux上使用Bochs
- 如何解决Linux下Python3.5无法使用tkinter
- [转]如何在Linux使用Eclipse + CDT开发C/C++程序? (OS) (Linux) (C/C++) (gcc) (g++)
- Linux必备 -- 如何在Mac OS 使用VMware 安装Linux
- Linux 如何使用echo指令向文件写入内容
- windows下如何正确使用Jconsole远程连接linux主机上的JVM
- linux 下分区xvdb有200G,只使用了20G,如何扩展容量?
- 如何使用Putty远程(SSH)管理Linux VPS
- linux调用脚本后如何获得脚本上的输出,ping的使用
- 如何使用Windows登录Linux
- Linux系统中如何添加、使用硬盘
- linux ulimit的使用,如何产生core文件,调试段错误
- 如何让Linux下的Java程序使用中文
- 如何使用Linux套接字?
- 如何混合使用Linux和Windows(上)
- Linux下Python安装完成后如何使用pip命令
- (转载) 如何在Linux使用Eclipse + CDT开发C/C++程序? (OS) (Linux) (C/C++) (gcc) (g++)
- 如何在linux命令行无界面下,使用selenium进行自动化测试