18

Is there a way to perform an integrity check on a ready-to-use USB boot disk?

I just made a Lubuntu 14.04.01 boot USB, and have not been able to figure out how to run an integrity check on it. I can't find any .iso file to run an MD5sum hash against.

Zanna
  • 72,312
Niall
  • 185
  • 1
  • 1
  • 6

6 Answers6

17

You can find the md5sum of an Ubuntu iso here.

The above md5 value is the checksum of the entire disk, not of the individual files.

When you prepare a bootable USB, the files from the iso file are copied over to the USB and the bootloder of the USB is overwritten, thus making it bootable. You see here, a single file(for ex, lubuntu 14.04.1 x64 iso) with a md5 sum(a5f97cd6a9f171c70cf816de8728f13b) is now destroyed and multiple files are present in the USB instead. So you don't have an iso anymore to compare the original lubuntu iso's md5 sum to.

If you want to check the integrity of each of the individuals files, then you need to boot from the USB and then select check cd for defects from the boot menu. There's a file ms5sum.txt in each ubuntu iso which contains the md5sum of each individual file in the iso. The check cd for defects option verifies the md5sum of each file with the md5 list present in the iso.

From LiveWireBT's answer, just navigating into the usb drive and running md5sum -c md5sum.txt should perform a consistency check of the individual files.

astrob0t
  • 1,766
13

Hashes of individual files contained in the ISO image are stored in the root folder as md5sum.txt.

Running md5sum -c md5sum.txt in the same folder should perform a consistency check.

LiveWireBT
  • 29,597
4

My answer is based on Lucas's answer in Unix and Linux StackExchange. To check the integrity of a usb boot disk, first find the size of the iso image with

 stat -c '%s' imagename.iso 

This will output an image size which you can enter in place of <imagesize> in the command below. The next command sends (through a pipe) all bytes corresponding to the size of the image to the md5sum command :

sudo head -c <imagesize> /dev/sdb1 | md5sum

You can compare this with the md5sum of your .iso file.

md5sum imagename.iso

If md5sums are different then there was an issue while copying the data. If md5sums are the same, you have successfully checked data integrity on your usb disk!

Note on locating your usb device under /dev/

For the command above, you need to know the name of your usb device such as /dev/sdbX, not the mount point (such as /media/usbX). You can find out by looking at the column Filesystem, in the output of df. For example my usb device appears as /dev/sdb1 in the output of

df
0

head -c $(stat -c imagename.iso) /dev/sdX | sha256sum

Similar to paul-rougieux's answer, but it gets the size of the ISO and performs the hash check in a single command

0

In the code below, change X into the path to the (iso-)image, you can check this by: ls -AFl Documents/tails.ISO # X would be Documents/tails.ISO

And change Y into the right device identifier for the USB drive. You can check with lsblk while it is not plugged in versus when it is plugged in to make sure you have the right device name (usually something like /dev/sdZ).

The code to check whether what has been written to the USB drive corresponds to the image file used (in the bash shell!):

img='X' usb='Y'
[[ $(head -c $(stat -c '%s' "$img") "$usb" |sha256sum) = $(sha256sum <"$img") ]] &&
  echo OK ||
  echo ERROR

If you use a tool like GNU ddrescue (the package is often called gddrescue), you could write: ddrescue --force 'X' 'Y' and it would automatically verify whether it was correctly written!

Note that by plugging the USB stick in and out, some partitions in the written image could get automatically mounted and thereby modified (the 'dirty bit') causing it to produce a completely different checksum!!

pepa65
  • 121
-1

Don't know whether the Linux Mint ISO uses the same grub menu as the vanilla Ubuntu ISO, but I'm just installing now and the grub menu that comes up has:

check the integrity of the medium

which took 10 mins to run and found 69 errors. I checked that iso image I downloaded was good, so I'm trying a different USB stick now.

It's GNU GRUB version 2.02^beta2-36ubuntu3

Adam
  • 1,149