Just rename the file. Any .iso
file can be safely renamed to have a .img
extension.
TL;DR
ISO vs. IMG
A raw disk image is a binary file that contains a sector-by-sector binary copy of the binary data stored on a storage device. A raw disk image is a complete snapshot of the source medium, including the MBR, GUID OR Apple partition table.
An ISO image is a raw disk image that contains a sector-by-sector copy of the binary data stored on an optical disk. ISO images contains the binary data of an optical media formatted in the ISO-9660 filesystem.
ISO images form a subset of raw disk images. An ISO image (.iso
extension) can be renamed to a raw disk image file (.img
extension) but the opposite isn't automatically true unless the disk image contains ISO-9660-formatted data. A raw disk image that contains ext4-formatted data isn't an ISO image.
Quite often though, ISO images are used as bootable mediums if they contain a MBR boot sector or an ESP boot partition. The BIOS/UEFI firmware will be able to execute the bootloader code and boot the system.
I downloaded an Ubuntu 22.04 bootable ISO for a quick demo, probing for the filetype shows:
root@ubuntu:~# file ./ubuntu-22.04-desktop-amd64.iso
ubuntu-22.04-desktop-amd64.iso: DOS/MBR boot sector; GRand Unified Bootloader, stage1 version 0x79, boot drive 0xbb, stage2 address 0x8e70, 1st sector stage2 0xb8db31c3, stage2 segment 0x201
The ISO image uses a GPT (GUID partition table) layout that includes a protective MBR. The protective MBR contains the bootstrap code for the first-stage bootloader, which is just a tiny executable code used to load the second-stage bootloader (i.e. GRUB) responsible for loading the kernel in the legacy BIOS boot process.
The second-stage bootloader is stored in the ESP (EFI system partition) and newer computers that have a UEFI-compliant firmware can directly execute the second-stage bootloader by probing the disk to find the ESP.
The protective MBR also contains a partition table that defines a single stub partition with the size of the entire disk. This prevents software that don't understand the GPT layout to see the disk as empty.
Exploring the image's content
To explore the image's content, we can attach the ISO image to a loop device.
A loop device is a block device that maps its data blocks not to a physical storage device but to the blocks of a regular file in the filesystem or to another block device. This is useful to provide a block device for a raw image stored in the filesystem.
You can list the loop devices with ls -l /dev/loop*
. The special character device /dev/loop-control
is the kernel driver for loop devices. It's used to dynamically find a free loop device to use, and to add and remove loop devices from the system.
Attach the ISO image to an available loop device:
root@ubuntu:~# losetup -f --show -P ./ubuntu-22.04-desktop-amd64.iso
/dev/loop0
List the partitions:
root@ubuntu:~# fdisk -l /dev/loop0
Disk /dev/loop0: 3.41 GiB, 3654957056 bytes, 7138588 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
Disklabel type: gpt
Disk identifier: A09DB2B8-B5F6-43AE-AFB3-91E0A90189A1
Device Start End Sectors Size Type
/dev/loop0p1 64 7129427 7129364 3.4G Microsoft basic data
/dev/loop0p2 7129428 7137923 8496 4.2M EFI System
/dev/loop0p3 7137924 7138523 600 300K Microsoft basic data
Mount the ISO-9660 and EFI partitions:
root@ubuntu:~# mkdir -p /mnt/{iso,esp}
root@ubuntu:~# mount -o ro /dev/loop0p1 /mnt/iso
root@ubuntu:~# mount /dev/loop0p2 /mnt/esp
Note: ISO-9660 is a read-only filesystem so the partition must be mounted with the ro
option.
You can verify the mounted filesystems with the following:
root@ubuntu:~# df -T /dev/loop0p{1,2}
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/loop0p1 iso9660 3564682 3564682 0 100% /mnt/iso
/dev/loop0p2 vfat 4214 3222 992 77% /mnt/esp
To unmount the partitions and deallocate the loop device, run:
root@ubuntu:~# umount loop0p{1,2}
root@ubuntu:~# losetup -d /dev/loop0
hdiutils
) or simply suggest to rename the .iso to .img (which I doubt is the correct approach). – Marius Hofert Dec 08 '13 at 21:41