曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 6750|回复: 0
打印 上一主题 下一主题

创建 bochs 磁盘镜像文件

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34387
跳转到指定楼层
楼主
发表于 2010-12-28 11:24:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
首先用 bximage 来创建:
========================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
        $Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts 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] 500

I will create a 'flat' hard disk image with
  cyl=1015
  heads=16
  sectors per track=63
  total sectors=1023120
  total size=499.57 megabytes

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

Writing: [] Done.

I wrote 523837440 bytes to hda.

The following line should appear in your bochsrc:
  ata0-master: type=disk, path="hda", mode=flat, cylinders=1015, heads=16, spt=63
上面按照提示创建了一个名为 hda 的磁盘映像文件,大小共 500M,磁盘参数为 cylinders=1015, heads=16, spt=63 。

使用 fdisk 工具进行分区:
$ sudo fdisk hda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9cd896d6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

You must set cylinders.
You can do this from the extra functions menu.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): x            # x 参数表示专家模式

Expert command (m for help): h         # headers
Number of heads (1-256, default 255): 16

Expert command (m for help): s         # spt
Number of sectors (1-63, default 63): 63
Warning: setting sector offset for DOS compatiblity

Expert command (m for help): c       # cylinders
Number of cylinders (1-1048576): 1015

Expert command (m for help): r          # 返回普通模式

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p                # 主分区
Partition number (1-4): 1
First cylinder (1-1015, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1015, default 1015):
Using default value 1015

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 25: 对设备不适当的 ioctl 操作.  # 这里的警告提示不要紧
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
查看结果:
$ sudo fdisk -l -u hda
You must set cylinders.
You can do this from the extra functions menu.

Disk hda: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x9cd896d6

Device Boot      Start         End      Blocks   Id  System
  hda1              63     1023119      511528+  83  Linux

创建 ext2 文件系统:
$ sudo losetup -o 32256 /dev/loop0 hda            
$ sudo mkfs /dev/loop0
mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
128016 inodes, 511528 blocks
25576 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
上面的 losetup 的中 -o 32256 (512*63=32256)是设置数据偏移,由于历史原因,第一个扇区 512 字节为 MBR,其后 62 个扇区为保留扇区,用以其他引导程序使用。windows 的 NT 系统和 linux 一般都从第 63 扇区后开始。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-28 12:03 , Processed in 0.067579 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表