keepcalculator

06 Numbers and Powers

Create ISO Images from the Command Line

Card No. 06·68402 · Updated · Standard formula, shown below

You can create ISO images from the command line using built-in tools on Linux, macOS, and Windows. The exact command depends on your operating system, but the core idea is the same: you gather a folder of files or copy an optical disc into a single .iso file. This article explains the standard commands, how they work, and common pitfalls to avoid.

Why Use the Command Line for ISO Creation

Graphical tools like Brasero, K3b, or Windows’ built-in burner can create ISOs, but the command line offers several advantages. It is scriptable, so you can automate backups or build processes. It is lightweight, requiring no extra software on most systems. And it gives you precise control over filesystem type, volume labels, and bootability. For system administrators and developers, command-line ISO creation is a routine task.

Creating an ISO from a Folder on Linux

The standard tool on Linux is genisoimage (or its older name mkisofs). The basic syntax is:

genisoimage -o output.iso /path/to/folder

This creates an ISO 9660 filesystem with Rock Ridge extensions (which preserve Unix permissions and symbolic links). To include Joliet extensions (for Windows compatibility), add -J. To set a volume label, use -V "My Label". For example:

genisoimage -J -V "Backup_2024" -o backup.iso /home/user/documents

If you are on a modern distribution, you may also have xorriso or mkisofs installed. The commands are similar. Check what is available with which genisoimage mkisofs xorriso.

Creating an ISO from an Optical Disc

To copy a CD or DVD to an ISO (a “disc image”), you need to read the raw data. On Linux, use dd or readom. The simplest command is:

dd if=/dev/cdrom of=disc.iso bs=2048

Replace /dev/cdrom with the actual device name (check with lsblk). The block size of 2048 bytes matches the sector size of CDs/DVDs. For audio CDs, this method will not produce a playable ISO; you would need to extract audio tracks separately. On macOS, the device is usually /dev/disk2, and you can use dd as well, but be careful to unmount the disc first with diskutil unmountDisk /dev/disk2.

Creating an ISO on macOS

macOS includes the hdiutil tool, which can both create and convert disk images. To create an ISO from a folder, you first make a read-write image, then convert it to ISO format:

hdiutil makehybrid -o output.iso /path/to/folder

This directly creates an ISO 9660 image. For more control, you can create a UDIF image and then convert:

hdiutil makehybrid -o output.iso -iso -joliet /path/to/folder

To convert an existing .dmg to ISO, use:

hdiutil convert input.dmg -format UDTO -o output.iso

Note that the output will have a .cdr extension; you can rename it to .iso.

Creating an ISO on Windows

Windows does not have a built-in command-line tool for creating ISO images from folders. However, you can use PowerShell with the .NET classes, or install third-party tools like oscdimg (part of the Windows Assessment and Deployment Kit). A common PowerShell approach uses the IMAPI2FS COM object, but that is complex. A simpler method is to use the New-IsoFile function, which is not built-in but can be added via a script. For most users, the practical options are:

  • Install oscdimg from the Windows ADK and use: oscdimg -m -o -u2 -udfver102 source_folder output.iso
  • Use a free third-party command-line tool like mkisofs from the Cygwin or MSYS2 environments.

If you are only burning a disc to ISO, Windows 10 and 11 allow you to right-click the optical drive and select “Create ISO image” (in File Explorer), but that is not command-line.

Common Problems and How to Avoid Them

  • File name truncation: ISO 9660 has a limit of 8.3 characters for file names unless you use Rock Ridge or Joliet extensions. Always add -J (Joliet) or -R (Rock Ridge) when creating ISOs for general use.
  • Symbolic links and permissions: Without Rock Ridge, symbolic links and Unix permissions are lost. Use -R to preserve them.
  • Bootable ISOs: Creating a bootable ISO requires special handling. For Linux, use genisoimage -b boot.img or xorriso -as mkisofs -b isolinux/isolinux.bin. For Windows, use oscdimg with the -bootdata option.
  • Large files (>4GB): The UDF filesystem is required for files larger than 4GB. Use -udf with genisoimage or the appropriate option in oscdimg.
  • Corrupted images: If you use dd to read a disc and get errors, the ISO may be incomplete. Use readom with error correction or check the disc for scratches first.

Alternatives to Command-Line Tools

If the command line feels intimidating, there are graphical alternatives. On Linux, Brasero and K3b are popular. On Windows, ImgBurn and PowerISO (both free for basic use) offer GUI interfaces. On macOS, Disk Utility can create disk images, but not directly as ISO; you would need to convert. However, for scripting and automation, the command line is unmatched.

Frequently Asked Questions

Can I create an ISO from a folder on Windows without third-party tools?

Not directly. Windows does not have a built-in command-line tool to create ISO images from a folder. You can use PowerShell with the IMAPI2FS COM object, but it is not straightforward. Most users install oscdimg from the Windows ADK or use a portable tool like mkisofs.

What is the difference between ISO and IMG files?

ISO is a standard format for optical disc images, containing the filesystem (usually ISO 9660 or UDF). IMG is a generic term for a raw disk image, which may include partition tables and boot sectors. You can often rename an IMG to ISO if it contains an ISO 9660 filesystem, but not always.

How do I make a bootable ISO from the command line?

You need to include boot code. For Linux, use genisoimage -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table with the appropriate files in the source folder. For Windows, use oscdimg with the -bootdata switch. The exact parameters depend on the bootloader you are using.

Why does my ISO have short file names?

That is due to the ISO 9660 level 1 standard, which limits names to 8.3 characters. To preserve long names, add Joliet (-J) or Rock Ridge (-R) extensions. Most modern operating systems read these extensions automatically.

Can I create an ISO from a folder with symlinks?

Yes, but only if you use Rock Ridge extensions (-R). Without them, symlinks are not preserved and may be replaced with their targets or skipped. On macOS, hdiutil makehybrid handles symlinks if you use the -iso option with Rock Ridge.

Is it safe to use dd to create an ISO from a disc?

Yes, but be cautious. dd reads raw sectors, so if the disc has errors, you will get a corrupted image. It is also easy to accidentally write to the wrong device, so double-check the input and output paths. For scratched discs, use readom with error recovery options.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →