I have a need to make my own .img file that can be mounted as a virtual diskette, but I do not know the command I need to use to do so. I've looked briefly at the man page for dd, but I can't tell if this can be used to do what I need, nor how to do it, even if it is the correct tool.

I just need to make a normal fat12 filesystem within a disk image, with custom files in it. How might I go about this?

Dani AI

Generated

As showed, the simplest approach is to create a blank file large enough to hold a FAT12 filesystem and then format it — that workflow answered ’s need. The notes below add practical alternatives, ways to populate the image, and common gotchas encountered when working with floppy-style or small FAT images.

Create the container quickly (sparse or allocated) rather than zero-filling every byte:

truncate -s 10M my.img
fallocate -l 10M my.img

For an authentic 1.44MB floppy use exactly 1474560 bytes when creating the file.

If the image is a raw filesystem (no partition table) it can be mounted directly and files copied in:

sudo mount -o loop my.img /mnt/tmp
sudo cp -r path/to/files/* /mnt/tmp/
sudo umount /mnt/tmp
sync

Mounting as a loop device is the easiest route for floppies. If the image contains a partition table, attach it with a loop/mapper tool and mount the partition node (or use kpartx) before copying.

Alternatives and cautions: mtools lets files be copied into a FAT image without root privileges (example: mcopy -i my.img localfile ::/), which is handy for automation. To make a bootable floppy install an appropriate boot sector with the emulator or syslinux tools. Always unmount/detach loop devices and run sync before removing the image to avoid corruption, and verify the result with tools like file or fsck when in doubt.

Recommended Answers

All 2 Replies

Hi,
Let us say you want to create a 10 Mb file system. Use dd to create a virtual disk image first.
Example - "dd if=/dev/zero of=/tmp/my.img bs=1k count=10000"
That will create a image file of size 10 Mb ~ approximately (1k * 10000)
Now to make it a FAT12 file system, use the command mkfs.vfat (or an equivalent tool in your distro like mkdosfs)
Basically, "mkfs.vfat -F 12 /tmp/my.img" (more parameters may be required) should format the virtual image as FAT12
Be careful that you do not destroy any critical data by mistake when using these commands.
Good luck !

That did it.. thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.