• We did not send an email asking for donations - please read this post.

Create IMG Files


Jarret W. Buse

Create IMG Files

I have had many questions about creating IMG files for VirtualBox. Many situations arise where the only easy access to an external data is through floppy disks.

One prime example is a Virtual DOS machine. Once DOS is installed, CD-ROM drivers are needed to access a virtual CD. It is not too easy to access shared directories. The answer: IMG files loaded as a Virtual Floppy disk.

In this article, I will explain how to create the IMG files, make the disk bootable, if needed, and mount them in a VirtualBox machine.

To create the IMG file, we have a few options. We can use a standard floppy disk size of 1.44MB or 2.88MB. If it is bigger than 2.88MB, VirtualBox will not recognize it and generate an error when adding the image to the Floppy Drive.

The creation of the floppy IMG file is done with the command “dd if=/dev/zero of=floppy.img bs=1k count=1440”. The command creates a 1.44MB image called “floppy.img” in the current folder. You can specify a different location by adding a path to filename. It is possible to also change into the folder in which you want the file created. If you are in the proper folder, then you do not need to specify the folder name. The file is set to read and write a one kilobyte block at a time (bs=1k).

At this point, the image file is created, but it is not formatted. If you try to load the file into a VirtualBox session, an error will occur. The “Virtual Floppy” needs to be formatted and can be done so. The image must be mounted as if it were an actual drive. To mount the image file, the following command is used: “sudo losetup /dev/loop0 floppy.img”. Once mounted, the “Virtual Floppy” can be formatted with the command “sudo mkfs -t vfat /dev/loop0”. Before anything can be done with it, the image must be unmounted first by the command “sudo losetup -d /dev/loop0”.

Do not be under the assumption that the image is formatted for use by a Virtual System. If I used the image as Drive A: in an MS-DOS Virtual Machine, the floppy would not be accessible. An error would be displayed as if there were an unformatted floppy disk in the drive. In an MS-DOS Virtual Machine, I could simply perform the command “format a:” to format the floppy image. If I wanted the floppy image to be bootable, I could run the command “format a: /s”. At this point, files could be copied to it from the Virtual Machine.

But what if you want to place files on the floppy image from your Linux system to put into the MS-DOS Virtual Machine?

A mount point needs to be created to mount the IMG file by running the command “sudo mkdir /media/floppy”. Any valid folder name in the /media/ folder would work, but the following mount names should reflect your change.

The image file should then be mounted at the new mount point created in the /media/ folder. The command to mount the IMG file is “sudo mount floppy.img /media/floppy”.

Now that the file is mounted, files can be copied to it with the command “sudo cp * /media/floppy”. Here, all files in the local directory are copied to the “floppy.img” file. If the files are in a different location, the path must be specified. Also, be aware of the image file size you created. If needed, multiple images must be created.

Finally, the image can be unmounted by “sudo umount /media/floppy”. Again, be aware of the mount point name if you used a different one. The folder you created as a mount point can then be deleted or left as you may need.

The image file can now be mounted as a Floppy Drive in a Virtual Machine.

The necessary commands to perform this task are as follows:

1. dd if=/dev/zero of=floppy.img bs=1k count=1440

2. sudo losetup /dev/loop0 floppy.img
3. sudo mkfs -t vfat /dev/loop0

4. sudo losetup -d /dev/loop0

5. sudo mkdir /media/floppy

6. sudo mount floppy.img /media/floppy

7. sudo cp * /media/floppy

8. sudo umount /media/floppy

9. sudo rmdir /media/floppy

NOTE: Step 5 is only needed once if the mount point is left intact. Step 9 is not needed if the mount point will remain for other copies.

I created an MS-DOS Virtual Machine and found that I had no mouse driver. I could not access a shared folder or even a CD-ROM without the CD-ROM drivers. I created an IMG file with the mouse driver in it and another with the appropriate CD drivers. With a CD-ROM, I could now mount ISO files to be accessed by the MS-DOS Virtual Machine.

If you have a zip, or some type of archived file, the file can be opened after the IMG file is mounted. With Root privileges, the archive contents can be extracted to the /media/floppy mount point. The files will then be placed into the IMG file. Simply unmount the mount point and you have a floppy image of the archive content.


  • slide.jpg
    7.1 KB · Views: 118,913
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online