This guy uses fdisk and "dd".
"There are multiple ways to do this, but one of the easiest methods is to use either “dd” or “bximage”. The latter one is a tool from the Bochs Emulator that can create disks."
"Another way is to use the “dd” utility that comes on most unix/linux systems:
dd if=/dev/zero of=hdd.img bs=1024 count=10240"
"Partition the image through fdisk
Now that we have a completely blank file (or virtual disk), we need to partition it just like any other disk. The “fdisk” utility it the way to go here, and there is nothing different between creating partitions on a virtual disk than it is on a physical one.
I’ve added a bunch of partitions (again: I’m testing my OS here, so it needs to be able to handle stuff like extended partitions etc). Just make sure you set the correct settings for your cylinders, heads and sectors-per-track in the fdisk menu. They are located in the “Expert menu” through “x”. I’ve added a big 5MB partition for Linux, a small 2MB partition for dos/fat16, another 1.5MB for linux, and a-little-bit-less-than-1MB partition for Linux, but I’ve put the last one inside an extended partition:
# fdisk -l -u hdd.img -C 20 -H 16 -S 63
Disk hdd1.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 20 cylinders, total 0 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: 0x839d4362
Device Boot Start End Blocks Id System
hdd.img1 63 10079 5008+ 83 Linux
hdd.img2 10080 15119 2520 6 FAT16
hdd.img3 15120 18143 1512 83 Linux
hdd.img4 18144 20159 1008 5 Extended
hdd.img5 18207 20159 976+ 83 Linux"
"Format the partitions
At this point you are able to format the partitions. Again, just like any physical partition.
# mkfs.ext2 /dev/loop1
# mkdosfs /dev/loop2
# mkfs.ext2 /dev/loop3
# mkfs.ext2 /dev/loop5"
He's making loop-back devices but you can adapt it too your needs.