bochs - bximage

前言

想将U盘镜像用winhex复制成文件后,供bochs使用。
在指定.bxrc时,填写的cylinders, heads, spt是用DiskGenius看到的参数,bochs却提示磁盘容量和参数不匹配。

看了pediy上一同学的文章,发现最简单的解决方法是,建立一个比实际U盘稍大的bochs镜像。将winhex复制出来的U盘镜像替换到bochs镜像的0字节位置。等在bochs中调试妥当后,再复制和U盘镜像同样的2进制内容到U盘,实现在U盘上正常运行。

实验

oldlinux的linux0.12实验自带Bochs-2.3.6.exe,就装这个版本。
实验用的U盘是刚买的32MB小U盘。

建立bochs空镜像

为了防止运行U盘镜像时,bochs报磁盘容量和参数不匹配的错误,需要将bochs镜像做的比U盘镜像稍大,bochs镜像应为33MB. bximage指定的影响容量单位是MB, 指定位32不行(比32MB的U盘实际容量小)。

cd /d "D:\ls\study\linux_prj\old_linux\src\3.1.2"
"C:\Program Files (x86)\Bochs-2.3.6\bximage.exe"
========================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
        $Id: bximage.c,v 1.32 2006/06/16 07:29:33 vruppert Exp $
========================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] 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 129023
[10] 33

I will create a 'flat' hard disk image with
  cyl=67
  heads=16
  sectors per track=63
  total sectors=67536
  total size=32.98 megabytes

What should I name the image?
[c.img] udisk_33mb.img

Writing: [] Done.

I wrote 34578432 bytes to udisk_33mb.img.

The following line should appear in your bochsrc:
  ata0-master: type=disk, path="udisk_33mb.img", mode=flat, cylinders=67, heads=16, spt=63
(The line is stored in your windows clipboard, use CTRL-V to paste)

Press any key to continue

编辑bochs配置文件

将C:\Program Files (x86)\Bochs-2.3.6\bochs\下的BIOS-bochs和VGABIOS拷贝到实验目录D:\ls\study\linux_prj\old_linux\src\3.1.2\,文件列表如下:
BIOS-bochs-latest
BIOS-bochs-legacy
VGABIOS-lgpl-latest
VGABIOS-lgpl-latest-cirrus
VGABIOS-lgpl-latest-cirrus-debug
VGABIOS-lgpl-latest-debug

编译D:\ls\study\linux_prj\old_linux\src\3.1.2\my_bochsrc.bxrc, 填入由bximage说的udisk_33mb.img的cylinders, heads, spt. 将BIOS-bochs和VGABIOS指向实验目录下的文件(从bochs目录下拷贝过来的)

###############################################################
# @file my_bochsrc.bxrc
# @brief bochsrc.txt file for linux 0.12 disk image.
###############################################################

# how much memory the emulated machine will have
megs: 32

# filename of ROM images
romimage: file=./BIOS-bochs-latest
vgaromimage: file=./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="udisk_33mb.img", cylinders=67, heads=16, spt=63

# 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

修改bochs镜像内容

现在可用的winhex全功能版本是19.6, 可以将大容量磁盘镜像保存到文件。
先用winhex将32MB的U盘内容保存到udisk_32mb_by_winhex.dat。

用winhex打开udisk_32mb_by_winhex.dat, 定义块头(文件头0)和块尾(文件尾01E17FFF ),选择编辑=>拷贝块=>复制成Hex数据。

用winhex打开udisk_33mb.img(0 ~ 020F9FFF), 鼠标点击第一个字节。
选择编辑 => 剪贴板 => wirte, 用剪贴板内容换掉文件内容。现在从0~01E17FFF的内容为U盘镜像内容(内容和容量都相同)。

启动bochs的脚本

在实验目录下编辑一个run.bat,双击运行。
这步可以验证自己写的my_bochsrc.bxrc和udisk_33mb.img对不对。
写的启动脚本run.bat中, bochs 如果不带-q选项,会先弹出bochs开始菜单的对话框,这不是.bxrc写错了.

echo off
rem @file D:\ls\study\linux_prj\old_linux\src\3.1.2\run.bat
cd "D:\ls\study\linux_prj\old_linux\src\3.1.2"
"C:\Program Files (x86)\Bochs-2.3.6\bochs" -q -f .\my_bochsrc.bxrc

在这里插入图片描述
在运行之后,bochs能直接跑起来, 没有错误提示。说明镜像和配置文件整的都对。
到这,实验环境就搭完了。
只要在udisk_33mb.img基础上,替换0扇区的启动代码,就可以做后续实验了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值