11

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.

9

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.

  • Thank you for your reply; so I grok that the iso file no longer exists. Is there any kind of checker that will check that the files on the bootable disk have integrity? How does one know if something got corrupted? Or if some viri or other stuff is in there in the OS? That was a big problem on the WinXP OS system I was converting from. – Niall Nov 8 '14 at 23:30
  • You can check for defects in the bootable USB by actually booting from it and then choosing check cd for defects in the boot menu. – astrob0t Nov 8 '14 at 23:45
  • Super. Great help on this. That works. And it reported "No errors found." when I ran it. </br></br> It does bring up the question, if the USB image were to be corrupted by a viri, wouldn't it be possible for the malware to potentially fool the "check disc for defects" code, and report that all is well, even if it were to be infected with something? – Niall Nov 9 '14 at 0:21
  • 1
    the check cd for defects is nothing but a md5 compare of the individual files with the list of md5 values present in the md5sum.txt file present in the cd. for better peace of mind, we can manually navigate to the usb folder and run md5sum -c md5sum.txt – astrob0t Nov 9 '14 at 0:29
  • I've installed the Lubuntu from the USB now. I will try running that command as soon as I figure out how to find the command prompt. (I'm new to Linux.) – Niall Nov 9 '14 at 21:35
7

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.

  • here is my jupyter notebook gist to check iso and usb integrity – Levon May 2 '17 at 12:29
2

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
  • I found that useful to make sure the image on USB is valid before trying it. – code2be Jan 21 '18 at 11:48
0

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

  • I'm still having issues appear from the integrity check on a brand new stick - it says some files were not found, which is a bit weird, looks like it's misreporting. With the integrity check on the other stick, it said some files didn't match, which sounded more serious. I didn't install from the old stick, but I did from the new stick (with the 69 apparently missing files) and the install went fine despite that. – Adam Oct 13 '16 at 10:59
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!!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.