RAW disk image and .Img format, Difference?

15,771

Unfortunately, you can't entirely tell for sure from just the file extension.

First of all, filename extensions can be renamed. For instance, there have been many cases where a JPG file gets renamed as a PNG file (or vice versa), maybe because a person is in a graphics editor and thinks they are saving in one format when they are actually saving in another format. In some cases, it really doesn't matter. For instance, if a web browser uses "graphics processing" instructions to try to handle a PNG file, and the "graphics processing" library looks at the graphic and figures out it is a JPG file, the end result might be that everything ends up working out okay.

Back in the days of MS-DOS, I found that the .IMG filename extension was most commonly used for "raw" disk images. However, there were occasionally some pieces of software which had other formats that they called an "image". .IMG was most commonly a "raw disk image" but that truth was not an absolute. Exceptions were rather uncommon, but they did occasionally exist. Typically, I think the exceptions were most commonly with images of floppy disks, or entirely unrelated file formats (e.g., maybe some sort of "raw" data for a graphic). For larger files, such as those containing tens of megabytes (or more), my inclination would be to think that is probably the image of a partition or an entire "hard drive" (or other "long term storage"; e.g. an SSD).

To alleviate the confusion, I personally prefer to use the filename extension of ".raw". Over the years, I have virtually never seen ".raw" as referring to anything other than a raw disk image, while ".img" (or ".ima") are occasionally extensions that have been used by some other custom-made formats.

As a more modern example, Usenet post has some instructions which will output data in the QCOW2 format and using filename "virtual.img". I have a hunch that such documentation may even have been included in the Qemu package documentation for some operating system. Things have gotten better with newer versions of Qemu, where documentation now tends to specify .qcow2 more commonly, but I remember working with older versions of Qemu and thinking that the documentation didn't really specify a default filename extension for the QCOW2 format. (As a person who likes using ".htm" and ".jpg" and ".mid", liking to keep extensions short, I typically used ".qc2" myself.)

When I come across a ".img" file, I think of it as "probably a disk image, and most likely a raw image, but a bit less certain than if it had used the .raw extension". When I know what format the data is in, I tend to try to avoid assigning the ".img" extension, so that things are not ambiguous.

If the file is indeed a raw image file, then renaming it can be done successfully. Unfortunately, there's no real easy way for software to test for the .raw format. By definition, the .raw format doesn't have any additional bytes serving as "metadata" that describes the rest of the file. File formats have rules, and basically the one "rule" of the "raw disk image" format is that there are no bytes except what would be actually on a disk if the image were written to a physical disk. Any variation from that rule would mean that the file is not truly just a "raw" disk image. I suppose some software could analyze an MBR and see if the data there makes sense, but I wouldn't feel very confident in such a process as it would still feel like there'd still be too much possibility for mis-detection. I would actually feel more confidence in reading documentation that specifies what format a file is using.

As for your final question: "If its different, how can I convert a vmdk to img?"

Using qemu-img ought to work. Make sure to specify " -O raw ". I'm not including an example command line, because different versions of qemu-img have expected the "-O specifiedFormat" command line option in different locations of the command line. If you placed the " -O raw " in the wrong spot, the result would be an error message (instead of a file that gets created), so you'd know right away. You can check the documentation that came with your copy of qemu-img for instructions that are relevant to the version of the software that is installed on the machine you're using.

Share:
15,771
JuliandotNut
Author by

JuliandotNut

Updated on September 18, 2022

Comments

  • JuliandotNut
    JuliandotNut almost 2 years

    So I need .img file to use with xen hypervisor. Currently I have a vmdk disk image of my current installation. It seems qemu can convert from vmdk to raw disk image, and as far as I read, .img file is also a raw disk image format. My question is if the output of qemu conversion (which has .raw extension btw) is same as .img file and I can plainly rename it? or is there a difference?

    If its different, how can I convert a vmdk to img?