# HOWTO: FreeBSD Binary Upgrade (base system + packages)



## vermaden (Sep 13, 2010)

There are many ways to upgrade FreeBSD along with installed packages to the newest version(s), most of them include compilation (buildworld/portmaster), this HOWTO will provide simple and fast way to upgrade FreeBSD system without needless compilation.

Upgrade if the _base system_ is relatively easy, its about to type 4 commands, read and UNDERSTAND on screen comunicates, if it goes to packages, we will use the fact, that all packages are build to newest version along with newest *-RELEASE version.

*0. CONFIGURATION BACKUP* (rather not needed, but ...)
[font="Courier New"]*root # tar -czf /root/ETC.tar.gz /etc /usr/local/etc*[/font]

*1. BASE SYSTEM UPGRADE* (I assume that 8.1-RELEASE is the current latest version)
[font="Courier New"]*root # freebsd-update upgrade -r 8.1-RELEASE*[/font]
[font="Courier New"]*root # freebsd-update install*[/font]
[font="Courier New"]*root # shutdown -r now*[/font]
[font="Courier New"]*root # freebsd-update install*[/font]

While doing the _base system_ procedure we will be asked for installed 'datasets' and about modifications in config files, we only need to read and UNDERSTAND the on screen comunicats.


*2. PACKAGES UPGRADE*
[font="Courier New"]*root # pkg_info -qoa | sort > /root/packagelist*[/font]
[font="Courier New"]*root # pkg_delete -a -f*[/font]
[font="Courier New"]*root # rm -r -f /boot/modules /usr/local /var/db/pkg*[/font]
[font="Courier New"]*root # while read PKG; do pkg_add -r $( basename ${PKG} ); done < /root/packagelist*[/font]

At this point all old packages have been removed, and latest pacakges have been installed on their place, it works automatically, unless port nam has changed, like with *VirtualBox*, when its port name changed from *emulators/virtualbox* into *emulators/virtualbox-ose*, so the only 'risk' here, is that some packages will not be added automatically.


*2.1. SEARCHING FOR MISSED PACKAGES*
[font="Courier New"]*root # pkg_info -qoa | sort > /root/packagelist.NEW*[/font]
[font="Courier New"]*root # diff -u /root/packagelist**[/font]

This way is probably the fastest and easiest to find missed packages.


*3. CLEANUP*
[font="Courier New"]*root # rm -r -f /root/packagelist**[/font]
[font="Courier New"]*root # rm -r -f /root/ETC.tar.gz*[/font]

If we had made some bigger changes in the configuration, we may keep the old configuration (*/root/ETC.tar.gz*).


----------



## psycho (Sep 13, 2010)

great how-to, like usual...


----------



## graudeejs (Sep 13, 2010)

fix: s/*probable*/probably/ at the end of post

Nice howto


----------



## surgeon (Sep 15, 2010)

FBSD 7.3 is not supported?


```
# freebsd-update upgrade -r 8.1-RELEASE
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from update4.FreeBSD.org... failed.
Fetching public key from update5.FreeBSD.org... failed.
Fetching public key from update2.FreeBSD.org... failed.
Fetching public key from update3.FreeBSD.org... failed.
No mirrors remaining, giving up.
```


----------



## vermaden (Sep 16, 2010)

surgeon said:
			
		

> FBSD 7.3 is not supported?



Even 7.2-RELEASE have info about upgrade using *freebsd-update*, so its definitely supported, the question is why You could not found any mirrors, any network issues?

http://freebsd.org/releases/7.2R/announce.html


----------



## surgeon (Sep 16, 2010)

vermaden said:
			
		

> the question is why You could not found any mirrors, any network issues?


Nope.

I can easily browse http://update5.freebsd.org/ and http://update4.freebsd.org/.
But not http://update.freebsd.org/.


----------



## Sora_ (Sep 19, 2010)

surgeon said:
			
		

> Nope.
> 
> I can easily browse http://update5.freebsd.org/ and http://update4.freebsd.org/.
> But not http://update.freebsd.org/.



You just have to wait... I had the same problem and after 10 minutes i tried it again and it worked.


----------



## MrHien (Sep 21, 2010)

Nice tut! It working for me..


----------



## surgeon (Sep 23, 2010)

Maybe this is the problem?


```
# freebsd-update upgrade -v debug -r 8.1-RELEASE
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from update4.FreeBSD.org... fetch: http://update4.FreeBSD.org/7.3-STABLE/amd64/pub.ssl: Not Found
failed.                         
Fetching public key from update5.FreeBSD.org... fetch: http://update5.FreeBSD.org/7.3-STABLE/amd64/pub.ssl: Not Found
failed.                         
Fetching public key from update2.FreeBSD.org... fetch: http://update2.FreeBSD.org/7.3-STABLE/amd64/pub.ssl: Not Found
failed.                         
Fetching public key from update3.FreeBSD.org... fetch: http://update3.FreeBSD.org/7.3-STABLE/amd64/pub.ssl: Not Found
failed.                         
No mirrors remaining, giving up.
```

There is no 7.3-*STABLE* dir. Only 7.3-*RELEASE*. So, where to repair that?


----------



## oliverh (Sep 23, 2010)

@surgeon

Stable is development, there are no binary updates for it.


----------



## vermaden (Sep 23, 2010)

surgeon said:
			
		

> There is no 7.3-*STABLE* dir. Only 7.3-*RELEASE*. So, where to repair that?



As You built *-STABLE by hand, You must now rebuilt it by hand into *-RELEASE.

You may of course stay 'STABLE' and update packages only, as step 2. and later will work as advertised (if I recall correctly packages for *-STABLE are rebuild wvery week).


----------



## hansivers (Sep 26, 2010)

vermaden said:
			
		

> *2. PACKAGES UPGRADE*
> [font="Courier New"]*root # pkg_info -qoa > /root/packagelist*[/font]
> [font="Courier New"]*root # pkg_delete -a -f*[/font]
> [font="Courier New"]*root # rm -r -f /boot/modules /usr/local /var/db/pkg*[/font]
> [font="Courier New"]*root # while read PKG; do pkg_add -r $( basename ${PKG} ); done < /root/packagelist*[/font]



@Vermaden :

Many thanks again for your very informative post.

If my understanding of your script is correct, the removal of /usr/local directory (3rd line) will destroy all modifications to packages config files in /usr/local/etc. So, the admin will have to retype again all these modifications AFTER installation of newest packages. Would have been more efficient just to keep /usr/local/etc directory untouched, to provide the newest packages with the personalized version of config files?


----------



## vermaden (Sep 26, 2010)

hansivers said:
			
		

> @Vermaden :
> 
> Many thanks again for your very informative post.
> 
> If my understanding of your script is correct, the removal of /usr/local directory (3rd line) will destroy all modifications to packages config files in /usr/local/etc.



... but the *0.* step BACKUPS the /usr/local/etc directory.


----------



## hansivers (Sep 27, 2010)

vermaden said:
			
		

> ... but the *0.* step BACKUPS the /usr/local/etc directory.



Yes, I have noticed. My question was more about what to do after installation of newer packages. If I follow your script step by step, the older config files are not lost (because of the initial backup) but they are no longer installed in the /usr/local/etc directory.  

So I understand that the admin have two possible courses of action:

a) untar the older config files in /usr/local/etc (but it will replace the newer config files, a risky operation)

b) manually merge older and newer config files (with diff or something like that?)

That why I asked previously whether it would have been more simple to just keep /usr/local/etc untouched (to avoid the manual merging). 

Many thanks again for your feedback. It is much appreciated!


----------



## vermaden (Sep 27, 2010)

hansivers said:
			
		

> That why I asked previously whether it would have been more simple to just keep /usr/local/etc untouched (to avoid the manual merging).



I have done that in 8.0 --> 8.1 step, everything worked, that that was not a critical/important machine so I would fix it without any pressure.

As for NOT deleting /usr/local/etc, something like that my be usefull:

```
# cd /usr/local
# ls | grep -v etc | while read I; do rm -r -f "${I}"; done
```


----------



## hbokh (Nov 7, 2010)

*Be very careful!* WHY do a "rm -rf" on the complete /usr/local but backup ONLY etc in that directory?
A lot of users have a whole lot of stuff in /usr/local (web-root / installers / certificates / etc.).


----------



## vermaden (Nov 8, 2010)

@hbokh

HOWTO creator assumes that You KNOW what You are doing ...


----------



## freeck (Jan 4, 2011)

I get a "variable not defined" error at this step:


```
root # while read PKG; do pkg_add -r $( basename ${PKG} ); done < /root/packagelist
```


----------



## vermaden (Jan 5, 2011)

@freeck

You need to use POSIX sh(1) compatible for these commands.


----------



## sinbad (Jul 28, 2012)

oppps.
I'm getting "Illegal variable name" when tryiing step 4

```
#while read PKG ; do pkg_add -r $( basename ${PKG} ) ; done < /root/packagelist
Illegal variable name.
```

At first I thought its because I had csh as my shell. so I changed it back to *chsh -s /bin/tcsh*

but the same Illegal variable name is shown.

can someone please help me? my server is down now.


----------



## vermaden (Jul 28, 2012)

Both *csh*/*tcsh *are C-shells, use *sh*/*zsh*/*fish*/*ksh*/*bash *which are Bourne Shells.


----------



## sinbad (Jul 28, 2012)

Thanks so much for the reply. I was able to change to sh and run the command.
problem now is that I'm getting

```
unable to fetch 'ftp://ftp.package' protocol error
```
for all the packages.

my google turn that I need to add the http:// to the url but not sure how to apply to the command

```
while read PKG ; do pkg_add -r $( basename ${PKG} ) ; done < /root/packagelist
```

Any ideas what I can try?
thanks again.


----------



## sinbad (Jul 28, 2012)

Forget the upgrade. I was stupid enough to delete my www dir which was inside /usr/local.  Damn me so stupid.
Please add to your initial post a warning so other stupid user like myself, who don't fall in the 'know what they doing' won't *beep**beep**beep**beep* up their sites so easily.
Feels like jumping from the roof now.


----------



## wblock@ (Jul 29, 2012)

Look at it this way:

A) It shows how valuable backups are.
B) When you recreate it, it will be better than before because of your experience.


----------

