# freebsd-update fails with 'Incorrect hash'



## balanga (Dec 9, 2021)

I've been trying to update (using `freebsd-update`) an old FreeBSD 12.0 system for almost a week without success. It starts off OK every time and downloads 000's of files but always stops with some file has 'incorrect hash'. I don't know if all these downloaded files are stored in cache, and each subsequent attempt to update just carries on where the last one failed, but after a week of attempts I guess all the required files would have been downloaded....

If I constantly have this problem, would the same occur if I attempted to set up my own update server as described here:-









						Build Your Own FreeBSD Update Server
					

Building your own freebsd-update server allows a system administrator to perform fast updates for a number of machines from a local mirror




					docs.freebsd.org
				




The above guide is ten years old and I wondered if it was still applicable or needed updating in some way...


----------



## SirDice (Dec 9, 2021)

balanga said:


> I don't know if all these downloaded files are stored in cache, and each subsequent attempt to update just carries on where the last one failed, but after a week of attempts I guess all the required files would have been downloaded....


Try cleaning out /var/db/freebsd-update/ (don't remove the directory itself).


----------



## balanga (Dec 9, 2021)

After a clear out I ran `freebsd-update -r 13.0-RELEASE upgrade`. This is on a system running 12.0-RELEASE. It only has a 60GB disk but over 40GB is available.

The first run fetched 9110 files and successfully applied patches and then showed:-



> Fetching 9593 files... failed



No 'incorrect hash' or anything else. Would some sort of error msg have been recorded anywhere?

I'm now trying again...

(Some time later)



> ...fetched 8540 files.
> Applying patches... done
> Fetching 9480 files...


----------



## richardtoohey2 (Dec 10, 2021)

freebsd-update is a shell script, so (if that's an option for you) then you could try adding more debug code to it to see where it's going wrong on your system?

/usr/sbin/freebsd-update

Obviously back it up first.


----------



## balanga (Dec 10, 2021)

I just noticed that there is a '--debug' option. I'll see what that gives me. The previous attempt failed, but did not report 'incorrect hash'.


----------



## SirDice (Dec 10, 2021)

As this is an old system, are you sure the disk itself is still good? It might be having bad sectors that cause some of the downloaded files to get corrupted when written to disk.


----------



## balanga (Dec 10, 2021)

It's definitely an old disk, a 1.8" PATA disk in an IBM ThinkPad X41. Never seen any disks like this before.

I just use the machine for occasional testing, but not really had any problems with it.

What's the best way of checking for bad sectors?


----------



## SirDice (Dec 10, 2021)

balanga said:


> a 1.8" PATA disk in an IBM ThinkPad X41. Never seen any disks like this before.


I do remember those, those tiny disks were fairly short-lived though. Never seen them much. 



balanga said:


> What's the best way of checking for bad sectors?


PATA (IDE) disks should also support SMART. So have a look with smartctl(8).


----------



## balanga (Dec 10, 2021)

I rebooted and did a PXEBOOT where I have lots of utiities and ran an old DOS progam - VIVARD which did a surface scan and no bad blocks was reported, so I think it's safe to assume that the problem lies elsewhere. 

I noticed that in /var/db/freebsd-update there are some file called serverlist* where either or both of two servers are listed. What purpose do they serve?


----------



## SirDice (Dec 10, 2021)

balanga said:


> I noticed that in /var/db/freebsd-update there are some file called serverlist* where either or both of two servers are listed. What purpose do they serve?


update.freebsd.org is actually load-balanced. It's how freebsd-update(8) keeps track of the mirrors.


```
# Pick a mirror.  Returns 1 if we have run out of mirrors to try.
fetch_pick_server () {
# Generate a list of not-yet-tried mirrors
        sort serverlist_tried |
            comm -23 serverlist_full - > serverlist
```

/usr/sbin/freebsd-update is a shell script, so you can easily read what it does. It's a large and complex script though.


----------



## balanga (Dec 10, 2021)

SirDice said:


> /usr/sbin/freebsd-update is a shell script, so you can easily read what it does. It's a large and complex script though.



Easily and 'large and complex' sounds like an oxymoron to me


----------



## grahamperrin@ (Dec 19, 2021)

balanga said:


> … Would some sort of error msg have been recorded anywhere? …



I suspect not.

FreeBSD bug 256143 – freebsd-update does not log its activities



> … if all these downloaded files are stored in cache …



I suspect not.

FreeBSD bug 257247 – freebsd-update / pkg: add automation, no questions, continue from interrupted state



> … The first run fetched 9110 files and successfully applied patches and then showed:-
> 
> 
> No 'incorrect hash' or anything else. …



FreeBSD bugs:

197308 – Improve feedback of freebsd-update at failure of release upgrade
260399 – freebsd-update: Downloading patches often fails repeatedly
You might like to edit the title of this topic; broaden its scope (no longer specific to hash mismatches).


----------



## grahamperrin@ (Dec 19, 2021)

ViVARD



balanga said:


> …  did a surface scan …



Scanned in what ways, technically? 

<https://www.hiren.info/downloads/freeware-tools/page/46> and the 2013 review at <https://www.softpedia.com/get/System/Hard-Disk-Utils/ViVARD.shtml> lack relevant detail. 

Can a scan by VIVARD perform writes to the disk in its entirety?

HDAT2

From a user manual, for the _most powerful_ test: 



> Read defined block of sectors into memory 1, write this block of sectors onto device, read the same defined block of sectors into memory 2 and compare memory 1 and 2.




ViVARD, HDAT2 and more are included in Ultimate Boot CD. 

(The included version of HDAT2 is outdated, but should be good enough for your purposes.)


----------

