bochs 中文文档 下载 App

bximage 工具概览——创建转换调整磁盘镜像的一站式命令行

bximage 是什么

bximage 是 Bochs 安装包里自带的一个独立工具,专门用来管理磁盘镜像。它能:

  1. 创建各种格式的磁盘镜像(flat、sparse、VMDK、VHDX、VNC)
  2. 转换不同格式之间(如 flat → VMDK、VMDK → flat)
  3. 调整已有磁盘的大小(resize)
  4. 合并 sparse 格式的红日志(undoable 模式)到基映像

两种使用模式

交互式(最易用)

直接运行:

bximage

会显示菜单:

========================================================================
bximage
Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
========================================================================

1. Create new floppy or hard disk image
2. Convert disk image to different format
3. Resize a hard disk image
4. Create undoable image with redolog base image
5. Commit a redolog file into its base image
6. Quit

按提示一步步操作——比如选 1 创建新磁盘后,会问你:磁盘类型(软盘/硬盘)、大小、格式(flat 还是 sparse)、文件路径。

命令行模式(脚本友好)

所有参数一次性在命令行传完:

# 创建 flat 格式 60MB 硬盘
bximage -q -create -mode flat -size 60M -filename hd60M.img

# 创建 sparse 格式
bximage -q -create -mode sparse -size 1G -filename system.img

# 格式转换
bximage -q -convert flat-to-sparse -filename source.img -target target.img

# 调整大小
bximage -q -resize -filename hd60M.img -size 120M

# 合并 undoable 日志
bximage -q -commit -filename base.img -redolog redolog.bin

-q 表示静默模式——不输出进度信息,适合批处理脚本。

创建新磁盘时的关键选择

磁盘类型

bximage -q -create -fd ...     # 软盘
bximage -q -create -hd ...     # 硬盘

格式选择

OS 开发和经典系统场景最常用 flat 格式:

bximage -q -create -mode flat -size 60M -filename hd60M.img

为什么选 flat?

sparse 格式适合需要"撤销修改"的场景——可以给一个基映像套一层可写日志,重开时丢日志就能回到原始状态。经典系统跑临时实验有用,OS 开发通常不需要。

命令行参数速查

创建(-create)

参数说明
-q静默模式
-create创建新映像
-fd / -hd软盘 / 硬盘
-mode flat / sparse / vmware3 / vmware4 / vhdx格式
-size N大小:60M(60MB)、1G(1GB)、1024K(1024KB)
-filename path输出文件路径

转换(-convert)

参数说明
-convert src-mode-to-dst-mode格式转换(flat-to-vmdk、vmdk-to-flat 等)
-filename path源文件
-target path输出文件

调整大小(-resize)

参数说明
-resize调整大小
-filename path目标文件
-size N新大小

注意:resize 不会改变磁盘上的分区表——如果你扩大了磁盘,需要在系统里用 fdisk/GParted 重建分区表才能用新增的空间。缩小磁盘会破坏数据,谨慎使用。

bximage 创建的 flat 磁盘的几何参数

运行 bximage 创建 flat 磁盘后,它会输出几行关键信息——其中 C/H/S 三参数必须抄到 bochsrc 里:

$ bximage -q -create -mode flat -size 60M -filename hd60M.img
========================================================================
bximage
========================================================================

hd60M.img:
  CHS=121/16/63  (cylinders/heads/sectors)
  total sectors = 122208
  sectors per track = 63
  heads = 16
  cylinders = 121
  sectors = 63

I will create 122208 sectors

然后 bochsrc 里:

ata0-master: type=disk, path="hd60M.img", mode=flat, cylinders=121, heads=16, spt=63

这三参数必须和 bximage 输出完全一致——写错了 BIOS 报告的磁盘容量会和真实大小不符,某些老系统会因此分区错误。

软盘镜像创建

OS 开发实验常用 1.44MB 软盘:

bximage -q -create -fd -size 1_44M -filename boot.img

软盘不需要 C/H/S 参数——bochsrc 里直接写:

floppyA: type=1_44, path="boot.img", status=inserted

type 已经隐含了软盘大小和几何参数。

bximage 报错处理

"Size is too small"

磁盘太小——flat 格式最小约 50KB(sparse 可以更小)。加大 -size 参数。

"Filename already exists"

文件已经存在。删除旧文件或换个文件名。

"Cannot open file for writing"

路径不对或权限不够(Linux/macOS)。检查目录是否存在、是否有写权限。

找不到 bximage

Windows 安装包在 Bochs 安装目录里(bximage.exe)。Linux distro 包管理器通常一起装,或者编译 Bochs 时会一起生成。