Difference between revisions of "Hard disk images"
m (HardDiskImages moved to Hard Disk Images: MediaWiki supports spaces in page names; please use them.)
Revision as of 21:13, 27 March 2008
Creating a hard disk image involves the following steps (under linux). If you already have loop devices setup at /dev/loop0 and /dev/loop1 change all references appropriately.
- Create the loop device of appropriate size
$ SIZE=100 $ dd if=/dev/zero of=my_hdd.img bs=1m count=$SIZE $ insmod loop.o $ losetup /dev/loop0 my_hdd.img
- Copy the master boot record which comes with syslinux
dd if=/path/to/syslinux/mbr.bin of=/dev/loop0
- Partition the hard disk,
- Create a single partition of type FAT32 (code c for fdisk)
- Mark the first partition as active (the MBR which comes with syslinux needs that)
- Calculate the offset of the first partition within the disk image. This can be done using fdisk's expert mode.
$ fdisk /dev/loop0 Command (m for help): x Expert command (m for help): p Disk /dev/loop0: 255 heads, 63 sectors, 1 cylinders Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID 1 80 1 1 0 254 63 0 63 16002 0b 2 00 0 0 0 0 0 0 0 0 00 3 00 0 0 0 0 0 0 0 0 00 4 00 0 0 0 0 0 0 0 0 00 Expert command (m for help): q
Notice that the first partition starts at sector 63. Knowing the sector size (standard is 512 bytes), we can easily calculate the offset in bytes to the first partition: 512 * 63 = 32256.
- Detach the loop device
fdisk /dev/loop0 losetup -d /dev/loop0
- Mount the first partition and create the filesystem
losetup -o $OFFSET /dev/loop1 my_hdd.img mkfs -t vfat /dev/loop1 mount -t vfat /dev/loop1 /path/to/mount_point
- Populate the file system with what ever you want by copying stuff into /path/to/mount_point
- Unmount the partition
- Create the boot sector for the partition, since the MBR will pass control to this partitions BOOT sector. The choice of boot sector depends on the OS to be installed in the HDD. Assuming we want to install DOS,
dd if=/path/to/syslinux/dos.bss of=/dev/loop1
- Detach the loop device and remove the loop module
losetup -d /dev/loop1 rmmod loop.o