How to check that cloning of an Ubuntu ISO file was successful

Scenario

When users have problems running Ubuntu or an Ubuntu flavour live or installing it, we often ask them to check with sha256sum that the download was successful. But there can be problems also in the next step, which can be cloning or extracting from the ISO file to a USB drive.

My experience is that cloning is a very reliable method to make a USB boot drive to run Ubuntu live or install Ubuntu into a computer. However, sometimes it fails (caused by various problems, which will not be discussed here).

Method to check that cloning was successful

When booting into a USB drive with Ubuntu Desktop or an Ubuntu flavour (Kubuntu, Lubuntu … Xubuntu), a writable partition is created, if there is some free drive space ‘behind’ the image of the ISO file. This makes straightforward checking of the cloning process fail, unless you remember to check before booting into it.

The tool diff-image-drive is a bash shellscript that can help you solve this problem (both with and without a writable partition). It can check the content of the image (of the ISO file) in the USB drive except where the partition table and writable partition and backup partition table are located.

$ diff-image-drive
usage:    sudo diff-image-drive <image-file> <device>
examples: sudo diff-image-drive ubuntu.iso /dev/sdc
          sudo diff-image-drive myfile.img /dev/sdc
version:  1.3

The usage of diff-image-drive is illustrated below,

You can download the diff-image-drive file at GitHub - sudodus/files at master · GitHub

6 Likes

Nice, that fills a gap that the usual `sha256sum` advice does not cover. For a quick manual check before the first boot I also like the simple form `sudo cmp -n $(stat -c%s ubuntu.iso) ubuntu.iso /dev/sdX` (with the real USB device, not a partition). Your script is the safer documented route after a writable partition has been created, because it avoids comparing the changed tail of the device.

Thanks for this little helper tool. I’ve found a fly in the ointment, though; it only compares the calculated sha256sum output and could erroneously suggest to the uninitiated user that everything is alright, even with a corrupted or maliciously altered ISO.

How about using the -c switch of sha256sum in the first ISO checksum stage? The user needs to provide a companion file with the checksum(s) and gets warned when it’s missing, so at least they’ll have a hint that there is still no authoritative proof.

Or just output an unconditional warning that users need to compare the displayed checksums against the one provided on the download site? That has the benefit of not needing any extra code.

It is there already in the README.md file on the download site:

Start by checking with sha256sum, that the iso file or image file was downloaded correctly. Then clone to a [USB] drive, and if problems to boot, check with diff-image-drive that cloning was successful.

2 Likes