近期不小心把系统弄崩了,重装了系统,使用了ubuntu 14.04,顺便准备研究Grub 2.0引导linux的方式,发现制作bochs引导镜像着实不容易,倒也不是操作困难,而是grub命令变更比较大,一时半会还不熟,折腾了好久才算是弄好。特此留下笔记以备后忘。


Ubuntu 14.04
Grub 2.02

root@Jean-vm:/home/jeanleo/bochs# dd if=/dev/zero of=disk.img count=$((63*16*100))
100800+0 records in
100800+0 records out
51609600 bytes (52 MB) copied, 0.699557 s, 73.8 MB/s
root@Jean-vm:/home/jeanleo/bochs# fdisk disk.img
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x379f62f8.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
a   toggle a bootable flag
b   edit bsd disklabel
c   toggle the dos compatibility flag
d   delete a partition
l   list known partition types
m   print this menu
n   add a new partition
o   create a new empty DOS partition table
p   print the partition table
q   quit without saving changes
s   create a new empty Sun disklabel
t   change a partition’s system id
u   change display/entry units
v   verify the partition table
w   write table to disk and exit
x   extra functionality (experts only)

Command (m for help): x
Expert command (m for help): c
Number of cylinders (1-1048576, default 6): 100
Expert command (m for help): h
Number of heads (1-256, default 255): 16
Expert command (m for help): s
Number of sectors (1-63, default 63): 63
Expert command (m for help): r
Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 2): 1
First sector (2048-100799, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-100799, default 100799):
Using default value 100799

Command (m for help): a
Partition number (1-4): 1
Command (m for help): w
The partition table has been altered!

Syncing disks.
root@Jean-vm:/home/jeanleo/bochs# fdisk -lu disk.img

Disk disk.img: 51 MB, 51609600 bytes
16 heads, 63 sectors/track, 100 cylinders, total 100800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x379f62f8

Device Boot      Start         End      Blocks   Id  System
disk.img1   *        2048      100799       49376   83  Linux
root@Jean-vm:/home/jeanleo/bochs# sudo apt-get install kpartx
Reading package lists… Done
Building dependency tree
Reading state information… Done
kpartx is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 53 not upgraded.
root@Jean-vm:/home/jeanleo/bochs# kpartx -av disk.img
add map loop1p1 (252:0): 0 98752 linear /dev/loop1 2048
root@Jean-vm:/home/jeanleo/bochs# ls -l /dev/mapper/
total 0
crw——- 1 root root  10, 236  7月 17 06:23 control
brw-r–r– 1 root root 252,   0  7月 19 13:26 loop1p1
root@Jean-vm:/home/jeanleo/bochs# mkfs /dev/mapper/loop1p1
mke2fs 1.42.9 (4-Feb-2014)
Discarding device blocks: done
warning: 223 blocks unused.

Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
12384 inodes, 49153 blocks
2456 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=50593792
6 block groups
8192 blocks per group, 8192 fragments per group
2064 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
root@Jean-vm:/home/jeanleo/bochs# mount /dev/mapper/loop1p1 /mnt/img/
root@Jean-vm:/home/jeanleo/bochs# grub-install –no-floppy –boot-directory=/mnt/img /dev/loop1
Installing for i386-pc platform.
Installation finished. No error reported.
root@Jean-vm:/home/jeanleo/bochs# cp /boot/vmlinuz-3.14.12 /mnt/img/vmlinuz
root@Jean-vm:/home/jeanleo/bochs# vim /mnt/img/grub/grub.cfg

# Timeout for menu
set timeout=10
# Set default boot entry as Entry0
set default=0
# Entry0- Load Linux kernel
menuentry “Linux” {
set root=(hd0,1)
linux /vmlinuz root=/dev/hda1

root@Jean-vm:/home/jeanleo/bochs# umount /mnt/img/
root@Jean-vm:/home/jeanleo/bochs# kpartx -d disk.img
loop deleted : /dev/loop1

root@Jean-vm:/home/jeanleo/bochs# kpartx -av disk.img
add map loop1p1 (252:0): 0 98752 linear /dev/loop1 2048
root@Jean-vm:/home/jeanleo/bochs# mount /dev/mapper/loop1p1 /mnt/img/

megs: 2000
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
ata0-master: type=disk, path=”disk.img”, cylinders=100, heads=16, spt=63
boot: c
log: bochsout.txt
mouse: enabled=0
cpu: ips=15000000
clock: sync=both


电子邮件地址不会被公开。 必填项已用*标注