9
1
I need to create a disk image with two empty file systems. I have created it using
dd if=/dev/zero of=./disk.img bs=1MiB count=1024
Next, I have created 2 primary partitions using fdisk disk.img
; one is FAT32 and other is EXT3. Now, I have to format both partitions in order to create file-systems to be mounted as -o loop devices
. But I can't understand how to format them? I can't use mkfs.vfat
on disk.img
. So I am totally confused.
SOLUTION: Thanks to answer from @pjc50 I found very simple solution:
sudo aptitude install multipath-tools
sudo kpartx -a disk.img #it maps (mounts) found partitions to /dev/mapper/loop...
sudo mkfs.vfat -F 32 -n boot /dev/mapper/loop0p1
sudo mkfs.ext3 -L rootfs /dev/mapper/loop0p2
A drawback of this solution is requirement of superuser rights.
I doubt that all those programs will be able to use partitions inside a file. Can you create the two filesystems in separate files and then merge them in a big file with dd? – golimar – 2011-12-12T16:32:08.920
@golimar: but I will need MBR on such drive, I don't know how it's possible to merge different filesystems created separately as distinct files – psihodelia – 2011-12-12T16:33:54.493
You can use the MBR of the original file you said. dd allows offsets with the 'size' and 'skip' commands. You would need to find the exacts offsets and then overwrite part of the big file with the two smaller ones – golimar – 2011-12-12T16:51:58.333
Forgive me if I'm being naive here, but why not just use two separate files? – Garrett – 2011-12-12T16:54:29.250