How do I extract the list of installed packages on a broken FreeBSD upgrade without using any pkg related commands?

I had a laptop with no HDD and was running FreeBSD to a USB stick for a while.
Upon upgrading from 12.2 to 13.0, something happened and I think the install must have failed and reboot while I wasn't around.
Now basic commands like pkg and freebsd-update don't work anymore.

Is there a way for me to manually extract the list of installed packages via text files?
All of the pkg related commands don't work.
I think the USB stick is corrupted and possibly failing.

I was able to copy all files from /var/db/pkg from the broken upgrade.
And I bought a new SSD and did a fresh install of FreeBSD 13 on the same laptop.

So I am running the freshly installed FreeBSD 13 and mounting the USB with the broken FreeBSD upgrade.

I want the list of packages to be in such a manner that I can type the pkg command on the fresh install, copy/paste the list of packages and run it on the fresh install.
Thank you.
 
Is there a way for me to manually extract the list of installed packages via text files?
No, this information is stored in a database; /var/db/pkg/local.sqlite to be precise. You might have a working backup of it in /var/backup/ though.
 
I was able to copy all files from /var/db/pkg from the broken upgrade.
And I bought a new SSD and did a fresh install of FreeBSD 13 on the same laptop.

You could try:

sqlite3 local.sqlite 'select name from packages;'

this would give you whatever is in the name column in the table packages of the saved local.sqlite database from the broken installation.

Maybe this helps.
Good luck.
 
With /bin/sh you could install them all like that.

for i in $( sqlite3 local.sqlite 'select name from packages;' ); do pkg install -y $i; done

To backup your current database would be advisable. Good luck
 
I think the USB stick is corrupted and possibly failing.
If the file system is UFS you can try fsck(8) on the unmounted root partition.

I was able to copy all files from /var/db/pkg from the broken upgrade.
I want the list of packages to be in such a manner that I can type the pkg command on the fresh install, copy/paste the list of packages and run it on the fresh install.

If you can mount the root (/) partition of the USB stick system on the newly installed system you can try (assuming USB system root is mounted on /mnt):

pkg -c /mnt prime-list > prime-list .. # .pkg(8)... -c ..pkg will chroot in the ⟨chroot path⟩ environment.

pkg install `cat prime-list`
 
Back
Top