"Pemberian dari makhluk adalah kerugian, dan penolakan dari Tuhan adalah kebaikan."

Making a Bochs disk image

by danang.wijanarko@gmail.com

 

First, use a real machine to setup a partition to your liking. If you need to tar up the disk, use something like.

tar czlp --same-owner -f c.img.tgz --exclude /tmp /

I exclude certain directories to save space

Then create image disk using bximage.

# bximage

========================================================================
bximage
Disk Image Creation Tool for Bochs
$Id: bximage.c,v 1.24 2004/08/29 19:31:09 vruppert Exp $
========================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd]

What kind of image should I create?
Please type flat, sparse or growing. [flat]

Enter the hard disk size in megabytes, between 1 and 32255
[10] 50

I will create a 'flat' hard disk image with
cyl=101
heads=16
sectors per track=63
total sectors=101808
total size=49.71 megabytes

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

Writing: [] Done.

I wrote 52125696 bytes to c.img.

The following line should appear in your bochsrc:
ata0-master: type=disk, path="c.img", mode=flat, cylinders=101, heads=16, spt=63

Now we have c.img. Then use fdisk to create partition on c.img with this spec cylinders=101, heads=16, spt=63.

# fdisk c.img

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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

Expert command (m for help): h 16
Number of heads (1-256, default 255): s 63
Number of heads (1-256, default 255): c 101
Number of heads (1-256, default 255):
root@nirmaladewi:~# fdisk c.img
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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

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
Warning: setting sector offset for DOS compatiblity

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

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-101, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-101, default 101):
Using default value 101

Command (m for help): a
Partition number (1-4): 1

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: Inappropriate ioctl for device.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Next examine the offset of our disk for correct offset and loopback mounting. To determine the correct offset for mounting your disk image, do.

# fdisk -l -u c.img
You must set cylinders.
You can do this from the extra functions menu.

Disk c.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
c.img1 * 63 101807 50872+ 83 Linux

And we take 63 * 512 = 32256.
Next setup the loopback device -- note that you need to use an offset corresponding to the location of the first partition. In our case is 32256.

# losetup -o 32256 /dev/loop0 c.img

Then format the image.

# mkreiserfs /dev/loop0
mkreiserfs 3.6.19 (2003 www.namesys.com)

A pair of credits:
Elena Gryaznova performed testing and benchmarking.

Alexander Lyamin keeps our hardware running, and was very generous to our
project in many little ways.

Guessing about desired format.. Kernel 2.6.8-1-386 is running.
Format 3.6 with standard journal
Count of blocks on the device: 12704
Number of blocks consumed by mkreiserfs formatting process: 8212
Blocksize: 4096
Hash function used to sort names: "r5"
Journal Size 8193 blocks (first block 18)
Journal Max transaction length 1024
inode generation number: 0
UUID: 93106843-9ab0-4eec-a277-d638b7dc4bdb
ATTENTION: YOU SHOULD REBOOT AFTER FDISK!
ALL DATA WILL BE LOST ON '/dev/loop0'!
Continue (y/n):y
Initializing journal - 0%....20%....40%....60%....80%....100%
Syncing..ok

Tell your friends to use a kernel based on 2.4.18 or later, and especially not a
kernel based on 2.4.9, when you use reiserFS. Have fun.

ReiserFS is successfully created on /dev/loop0.

Next step is mounting the disk to put files on it. Don't forget to put /boot/grub/* there too.

# mount /dev/loop0 /mnt
# cd /mnt

Next is using debootstrap to create base file system on it.  Then the GRUB bootloader on c.img.

# grub --no-floppy
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.95 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub> device (hd0) c.img

grub> geometry (hd0) 101 16 63
drive 0x80: C/H/S = 101/16/63, The number of sectors = 101808, c.img
Partition num: 0, Filesystem type is reiserfs, partition type 0x83

grub> root (hd0,0)
Filesystem type is reiserfs, partition type 0x83

grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 22 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+22 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"..
. succeeded
Done.

grub> quit

Next set the /boot/grub/menu/lst in the c.img.

 

- d

"Bekatul Port" Personal Enterprise Number (PEN) registered @ IANA OID

ASN.1 Notation: {iso(1) identified-organization(3) dod(6) internet(1) private(4) enterprise(1) 30347}

Dot Notation: 1.3.6.1.4.1.1.30347

IRI Notation: oid:/ISO/Identified-Organization/6/1/4/1/30347


View Stat Counter