曲径通幽论坛

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

制作 bochs 启动软盘映像文件

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34387
跳转到指定楼层
楼主
发表于 2010-12-11 19:12:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
系统环境:Debian5

步骤:
1. 创建软盘映像文件
$ dd if=/dev/zero of=floppy.img bs=1024 count=1440
1440+0 records in
1440+0 records out
1474560 bytes (1.5 MB) copied,0.0234185 秒,63.0 MB/秒

上面, /dev/zero 文件经常用来初始化一块数据存储区,参考:http://www.groad.net/bbs/read.php?tid-2950.html

2. 将上面创建的映像文件设置为循环设备类型,并将其 挂到 /dev/loop1 上
# losetup /dev/loop1 floppy.img


3. 创建 EXT2 文件系统
# mkfs /dev/loop1
mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
184 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=1572864
1 block group
8192 blocks per group, 8192 fragments per group
184 inodes per group

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

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

mkfs 用来在一个设备上创建一个文件系统,这个设备通常是磁盘分区。因为它操作的是一个设备,所以我们在上面才会用 losetup 将映像文件与 /dev/loop1 这个设备挂接起来。这样,mkfs 看起来就像操作一个磁盘设备,但实际作用还是发生在映像文件上。

4. 将循环设备 mount 到一个目录上,这里选择 /mnt
# mount -o loop /dev/loop1 /mnt


5. 创建 grub 目录以及拷贝 stage1 和 stage2 文件到新建的 grub 目录中
# mkdir -p /mnt/boot/grub
# cp /boot/grub/stage[12] /mnt/boot/grub/

stage1 和 stage2 就采用我们系统上的。它们的作用就是实现 bootloader 。

6. 还编辑一个简单的 menu.lst 文件到 grub 中去,内容如下
title=Sample kernel
root (fd0)
kernel /boot/bzImage

上面,root 配置 GRUB 的根分区,这里即是 /boot 分区,fd0 表示第一个软盘,假如只有一个软盘,只写 fd 也是可以的。
kernel 指定要加载的内核文件,我们这里没有 bzImage 这个文件,为了格式完整,乱写一个。

7. unmount 掉设备
#umount /mnt


8. 将 grub 嵌入到映像文件中
# grub --device-map=/dev/null


9. 在步骤 8 后会显示出 grub 设置界面,执行下面的命令
grub> device (fd0) /dev/loop1

grub> root (fd0)
Unknown partition table signature
Filesystem type is ext2fs, using whole disk

grub> setup (fd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... no
Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.l
st "... succeeded
Done.

grub> quit


10. 分离循环设备
# losetup -d /dev/loop1


11. 使用 bochs 验证 grub 的引导

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-5-19 17:50 , Processed in 0.078807 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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