Jul 15, 2013

Updating FreeBSD 9 with freebsd-update and beadm

In my previous post I described how Install FreeBSD 9 with root on ZFS with support for beadm, now my purpose is to show the advantages of this configuration to deal with tasks so committed like operating system updates. 

As a starting point we have a system under FreeBSD 9 which has generated a snapshot with beadm nothing but complete the installation.

The initial version we have is:

root@morsa:/root # uname -a
FreeBSD morsa 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec  4 09:23:10 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

In FreeBSD there are two routes to upgrade the OS, with svn or CTM can update sources /usr/src and then compile the kernel and the userland, or use the command freebsd-update which updates the binaries and is the method I'll show you.

The command freebsd-update enables updates of major or minor version, only with the GENERIC kernel, not the customs kernels. It also allow apply patches to FreeBSD.


In order to update the system, we must first download the update:
root@morsa:/root # freebsd-update fetch
Looking up update.FreeBSD.org mirrors... 1 mirrors found.
Fetching metadata signature for 9.1-RELEASE from update2.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Preparing to download files...
00....110....120
................................................
The following files will be updated as part of updating to 9.1-RELEASE-p4:
/boot/kernel/kernel
/boot/kernel/kernel.symbols
/boot/kernel/linker.hints
/boot/kernel/nfsd.ko
/boot/kernel/nfsd.ko.symbols
/lib/libc.so.7
/lib/libcrypto.so.6
/rescue/
/rescue/atacontrol
/rescue/atmconfig

After the download, we update the system:
root@morsa:/root # freebsd-update install
Installing updates... done
reboot the server:
root@morsa:/root # shutdown -r now
Now, we have FreeBSD 9 updated:
root@morsa:/root # uname -a
FreeBSD morsa 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0: Mon Jun 17 11:42:37 UTC 2013     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
At this point, we performed a snapshot to get a consistent return point.
root@morsa:/root # beadm create 91_30062013@update_RELEASE-p4
Created successfully
Finally, we list the snapshots we have done. 
root@morsa:/root # beadm list -s
BE/Dataset/Snapshot                                                 Active Mountpoint            Space Created

91_30062013
  fbsdzpool1/ROOT/91_30062013                                       NR     /                    466.7M 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr                                   -      /usr                 435.6M 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr/home                              -      /usr/home            144.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr/ports                             -      /usr/ports             1.4G 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr/ports/distfiles                   -      /usr/ports/distfiles   1.7M 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr/ports/packages                    -      /usr/ports/packages  144.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/usr/src                               -      /usr/src             511.9M 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var                                   -      /var                 692.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/crash                             -      /var/crash           148.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/db                                -      /var/db              278.2M 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/db/pkg                            -      /var/db/pkg          280.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/empty                             -      /var/empty           144.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/log                               -      /var/log             416.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/mail                              -      /var/mail            152.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/run                               -      /var/run             448.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013/var/tmp                               -      /var/tmp             356.0K 2013-06-30 14:39
  fbsdzpool1/ROOT/91_30062013@intall_r243825                        -      -                     71.7M 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr@intall_r243825                    -      -                     78.6M 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr/home@intall_r243825               -      -                      0.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr/ports@intall_r243825              -      -                      8.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr/ports/distfiles@intall_r243825    -      -                      8.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr/ports/packages@intall_r243825     -      -                      0.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/usr/src@intall_r243825                -      -                      1.9M 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var@intall_r243825                    -      -                    124.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/crash@intall_r243825              -      -                      0.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/db@intall_r243825                 -      -                    212.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/db/pkg@intall_r243825             -      -                      8.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/empty@intall_r243825              -      -                      0.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/log@intall_r243825                -      -                    108.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/mail@intall_r243825               -      -                      8.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/run@intall_r243825                -      -                    184.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013/var/tmp@intall_r243825                -      -                    100.0K 2013-06-30 16:00
  fbsdzpool1/ROOT/91_30062013@update_RELEASE-p4                     -      -                     84.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr@update_RELEASE-p4                 -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr/home@update_RELEASE-p4            -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr/ports@update_RELEASE-p4           -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr/ports/distfiles@update_RELEASE-p4 -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr/ports/packages@update_RELEASE-p4  -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/usr/src@update_RELEASE-p4             -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var@update_RELEASE-p4                 -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/crash@update_RELEASE-p4           -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/db@update_RELEASE-p4              -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/db/pkg@update_RELEASE-p4          -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/empty@update_RELEASE-p4           -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/log@update_RELEASE-p4             -      -                     84.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/mail@update_RELEASE-p4            -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/run@update_RELEASE-p4             -      -                      0.0K 2013-07-03 08:49
  fbsdzpool1/ROOT/91_30062013/var/tmp@update_RELEASE-p4             -      -                    100.0K 2013-07-03 08:49

From this point, if necessary undo the changes and go back to an previous consistent point, we have two routes:

freebsd-update rollback: This command has the option to undo the changes made, leaving the system in the state before applying the update. In this case, when you run this command, the system would be restored to version  FreeBSD 9.1-RELEASE # 0 r243825.

beadm create / activate: With beadm you can restore the entire boot environment to a previous point arbitrarily defined. To reverse the FreeBSD version 9.1-RELEASE # 0 r243825 you would execute:
# beadm create -e 91_30062013@intall_r243825 91_04072013
# beadm activate 91_04072013
# shutdown -r now

The difference between both methods lies in the specificity of the first method, which reverses the OS, and only the OS, to its previous state.

By contrast, in the case of the second method, the restore point is arbitrarily defined at the time of the creation of the snapshot and not only reversed FreeBSD binaries, but the entire file system where the OS is installed.
 
The second method is more direct, avoids problems with configuration files, which may have been modified with mergemaster, and possible changes in the status of packages and ports we may have made.

No comments:

Post a Comment

Comments are welcome, I encourage you to contribute by proposing topics of your interest to develop in this blog.