Power loss while updating ports

The power went out while I was updating the ports on a VM:
Code:
# uname -a
FreeBSD iantomarus 15.0-RELEASE-p9 FreeBSD 15.0-RELEASE-p9 GENERIC amd64
# zfs list
NAME                                           USED  AVAIL  REFER  MOUNTPOINT
zroot                                         57.4G   101G    96K  /zroot
zroot/ROOT                                    41.0G   101G    96K  none
zroot/ROOT/15.0-RELEASE-p1_2026-02-01_183205     8K   101G  18.7G  /
zroot/ROOT/15.0-RELEASE-p2_2026-03-01_105108     8K   101G  18.4G  /
zroot/ROOT/15.0-RELEASE-p4_2026-04-01_080659     8K   101G  21.3G  /
zroot/ROOT/15.0-RELEASE-p5_2026-05-01_142206     8K   101G  19.7G  /
zroot/ROOT/15.0-RELEASE-p7_2026-05-01_193749     8K   101G  19.9G  /
zroot/ROOT/15.0-RELEASE-p8_2026-06-01_190344     8K   101G  21.1G  /
zroot/ROOT/default                            41.0G   101G  21.2G  /
zroot/home                                    1.94G   101G    96K  /home
zroot/home/paolo                              1.94G   101G  1.94G  /home/paolo
zroot/tmp                                      128K   101G   128K  /tmp
zroot/usr                                     14.3G   101G    96K  /usr
zroot/usr/ports                               13.4G   101G  13.4G  /usr/ports
zroot/usr/src                                  977M   101G   977M  /usr/src
zroot/var                                     70.8M   101G    96K  /var
zroot/var/audit                                 96K   101G    96K  /var/audit
zroot/var/crash                               68.5M   101G  68.5M  /var/crash
zroot/var/log                                 1.79M   101G  1.79M  /var/log
zroot/var/mail                                 160K   101G   160K  /var/mail
zroot/var/tmp                                  104K   101G   104K  /var/tmp
Now running pkg info:
Code:
# pkg info
7-zip-26.01                    Console version of the 7-Zip file archiver
Andika-6.200                   Sans-serif font designed for literacy use
AppStream-1.1.2                Machine-readable software metadata for desktop environments
GraphicsMagick-1.3.47,1        Fast image processing tools based on ImageMagick
ImageMagick7-7.1.2.24          Image processing tools
Imath-3.2.2_4                  C++/Python lib of 2D/3D vector, matrix, math ops for computer graphics
aalib-1.4.r5_14                ASCII art library
abseil-20250127.1_1            Abseil Common Libraries (C++)
accountsservice-26.13.3_1      D-Bus interface for user account query and manipulation
adwaita-icon-theme-47.0        GNOME Symbolic Icons
adwaita-icon-theme-legacy-46.2 Full color icon theme for legacy applications
alef-1.0_4                     Free multi-lingual font designed for screens
alegreya-sans-2.008_1,1        Humanist sans serif font with a calligraphic feeling
alsa-lib-1.2.15.3              ALSA compatibility library
anonymous-pro-1.002_3          Fixed width sans designed especially for coders
aom-3.14.0                     AV1 reference encoder/decoder
appres-1.0.7                   Program to list application's resources
appstream-glib-0.8.3_1         Library to help with AppStream metadata
asciidoc-10.2.1                Text document format for writing short documents and man pages
at-spi2-core-2.60.4            Assistive Technology Service Provider Interface
atkmm-2.28.4                   C++ wrapper for ATK API library
autoconf-2.73                  Generate configure scripts and related files
autoconf-switch-20220527       Wrapper script to switch between autoconf versions
automake-1.18.1                GNU Standards-compliant Makefile generator
avahi-app-0.8_6                Service discovery on a local network
b612-1.008                     Highly legible font family for aircraft cockpit screens
babl-0.1.124                   Dynamic pixel format conversion library
bash-5.3.9                     GNU Project's Bourne Again SHell
Bus error (core dumped)
I think I can get the old pkg backup database in /var/backups but I do not know how to use it. The files in /var/backups are:
Code:
  > ls /var/backups/
total 25 MB
-rw-r--r--  1 root wheel uarch  1.5K 2026.01.06 11:07 aliases.bak
-rw-r--r--  1 root wheel uarch  512K 2026.05.02 03:01 boot.ada0p2.bak
-rw-r--r--  1 root wheel uarch  512K 2026.01.07 03:01 boot.ada0p2.bak2
-rw-r--r--  1 root wheel uarch  189B 2026.01.07 03:01 gpart.ada0.bak
-rw-r--r--  1 root wheel uarch  706B 2025.12.12 17:59 group.bak
-rw-r--r--  1 root wheel uarch  571B 2026.05.02 03:01 kern.geom.conftxt.bak
-rw-r--r--  1 root wheel uarch  571B 2026.01.07 03:01 kern.geom.conftxt.bak2
-rw-------  1 root wheel uarch  2.8K 2025.12.13 15:19 master.passwd.bak
-rw-r--r--  1 root wheel uarch   11M 2026.01.07 04:01 pkg.sql.xz
-rw-r--r--  1 root wheel uarch   13M 2026.05.02 03:13 pkg.sql.zst

How can I restore the pkg sql database? And. The error is a pkg sql database error? Many thanks
 
Well, I guess it is gone. It no more starts. No way to restart it with old kernel and with saved BE, in single user mode, no way.

VirtualBox_FreeBSD_02_06_2026_17_09_33.jpg


It freeze with this screen, no access with SSH
 
Wait, I turned off the machine and turned off my brain too (swearing enough) to go to dinner. I rebooted the machine (Windows) started the VM (VirtualBox) and FreeBSD boot normally, maybe the problem was in the host too. It was a very short brownout (a storm lightning strike), the server, TV and other electronic devices didn't even shut down, only my desktop, probably because it was under heavy load, I not turned off the machine after power loss.
In any case, pkg gives the same error. When I update the ports, I disable LightDM and the desktop environment (plus dbus, avahi, samba, and a few other services) to keep the system lighter. Then, when everything was fine, I re-enabled all the services, LightDM started normally, I logged into XFCE (X11), and everything is fine except for the XFCE whisker menu. It was most likely the update that was running when the power went out.Now the only problem I have is pkg (I hope). I searched the forums for threads about problems with the pkg database, but I couldn't find a solution. I don't know how to use the files in /var/backups to restore the database. Any pkg command gives me the error
Code:
Bus error (core dumped)
 
Since it is a VM, first I would run "zpool scrub" to ensure the zpool/zfs structures are consistent and not damaged due to powerfail. Assuming the FS is not damaged (or fixed up), you can try something like the following as root:

Code:
mv /var/db/pkg/local.sqlite /var/db/pkg/local.sqlite.damaged
zstdcat /var/backup/pkg.sql.zstd | pkg shell
pkg check
You will likely find some issues that you can fix by reinstalling affected packages but the db should be consistent. But Note: follow the above at your own risk.
 
Back
Top