Measure an ISO Image Safely with isosize

isosize answers a small but annoying question, how big is this ISO-9660 filesystem really, without mounting the image or touching a single byte of it. You will finish with the byte length, sector count, or block count of an image. The examples use isosize from util-linux 2.41.3, installed on this machine. Allow about ten minutes. You need a readable ISO file and a shell; reading a physical optical device may also need elevated privileges, but the ordinary file examples do not.

1. Check the installed command

Start with the local binary and its help output. This is an ordinary read-only check and does not need sudo:

$ command -v isosize
/usr/bin/isosize
$ isosize --version
isosize from util-linux 2.41.3
$ isosize --help
Usage:
 isosize [options] <iso9660_image_file> ...

The input can be a normal image file or a block device such as an optical drive. The command measures the ISO-9660 filesystem inside that input, it is not a general-purpose file-size command, so do not run it on an arbitrary archive or disk image and expect the byte count from stat.

Checkpoint: confirm that isosize --version reports the version you are documenting. Options and diagnostic wording can differ between util-linux releases.

2. Read the image length in bytes

Pass one ISO file as the final argument. With no options, isosize prints the ISO-9660 filesystem length in bytes:

$ isosize /path/to/image.iso
376832

The number is deliberately printed without a unit label, treat it as bytes. The sample above is from a small test image; your image will produce a different value.

Use a separate command to confirm the file you selected:

$ file /path/to/image.iso
/path/to/image.iso: ISO 9660 CD-ROM filesystem data

file is only a quick identification check. The useful isosize result is still the filesystem length, which can differ slightly from the size of the containing file: ISO writers can append run-out sectors, and the manual specifically allows for that.

3. Show sectors and sector size together

Use --sectors, or its short form -x, when the count and block size matter more than a byte total:

$ isosize --sectors /path/to/image.iso
sector count: 184, sector size: 2048

"Sectors" is the command's display term for ISO blocks. In the installed version, both values appear on one line. Do not parse the punctuation as a stable API for a long-lived script; test the exact util-linux versions your script needs to support.

The sector count multiplied by the displayed sector size gives the measured ISO length. For the example above, 184 times 2048 is 376832 bytes, a useful check when comparing an image with a tool that reports 2048-byte sectors.

4. Use a divisor when a plain number is easier

--divisor NUMBER, or -d NUMBER, divides the byte result by the number you give. It is ignored when --sectors is present. Use 2048 to display the block count in the usual ISO block size:

$ isosize --divisor 2048 /path/to/image.iso
184

A different divisor answers a different question. 512, for example, reports how many 512-byte units fit in the measured ISO length:

$ isosize -d 512 /path/to/image.iso
736

This option does not rescan, resize, pad or rewrite the image, it only changes the displayed number. Keep the divisor explicit in scripts, because a bare output value gives no clue about its unit.

Tip: do not combine -d with -x expecting both to take effect. The manual says the divisor is ignored once sectors mode is selected.

5. Create a disposable test image if you need a known result

Learning the command with no ISO to hand? Create a temporary one with an ISO authoring tool. This only touches a temporary directory and needs no root:

$ test_dir="$(mktemp -d /tmp/isosize-test.XXXXXX)"
$ mkdir "$test_dir/tree"
$ printf '%s\n' 'isosize test' > "$test_dir/tree/README.txt"
$ xorriso -as mkisofs -quiet -o "$test_dir/test.iso" "$test_dir/tree"
$ isosize "$test_dir/test.iso"
376832
$ isosize --sectors "$test_dir/test.iso"
sector count: 184, sector size: 2048

The exact length depends on the authoring tool and its metadata, the point of this fixture is a valid ISO-9660 input, not a guaranteed size on every host. Keep the temporary directory while checking the output, and when finished remove only the directory your command created, for example with rm -rf -- "$test_dir". That deletion is irreversible, so verify the variable before running it and do not substitute a broad path.

6. Read an optical device carefully

A block device can be supplied in place of a file:

$ isosize /dev/sr0
376832

Use the device name that actually exists on your system. Access may fail with a permission error; if the device is intentionally readable only by a privileged group, run the same read-only command with the required privileges:

$ sudo isosize /dev/sr0

This command does not mount the disc, eject it, write to it or alter its contents. It does still touch live hardware, so avoid running it against a device that another operation is replacing or diagnosing. Check ls -l /dev/sr0 first, and do not guess a device path.

7. Diagnose a failed measurement

For a normal file, check existence and readability before reaching for permission changes or sudo:

$ test -r /path/to/image.iso && echo readable
readable
$ isosize /path/to/image.iso
376832

If the input is not an ISO-9660 filesystem, isosize reports an error and a failure status. A plain text file is a safe way to see that boundary:

$ isosize /path/to/notes.txt
isosize: /path/to/notes.txt: might not be an ISO filesystem
$ printf 'exit status: %s\n' "$?"
exit status: 32

With multiple inputs, treat a non-zero status as a reason to inspect every reported path rather than trusting the successful-looking numbers. Do not repair a failed check by renaming a file, mounting it, or modifying its contents. First establish whether you selected the wrong path, an incomplete download, a non-ISO image, or a device that is not currently readable. Compare a trusted checksum when image integrity matters.

Done means