pkg upgrade ... disk image is malformed

I build packages locally on one machine with poudriere, another one picks them up. This has worked flawlessly for months, except today. No disk crashes or anything untoward. 10.1-STABLE

Q: How to fix the database image or work around this issue. I don't want to run the update in case the corrupted database gets worse.

I suppose I could list all the non-auto packages, destroy pkg's database, then install all the packages listed....any suggestions most welcome.

root@Trimon:~ # pkg upgrade
Code:
Updating NyingmaCentral repository catalogue...
NyingmaCentral repository is up-to-date.
All repositories are up-to-date.
Checking for upgrades (41 candidates):  2%
pkg: sqlite error while executing SELECT p.name, p.origin, p.version, 0 FROM main.packages AS p INNER JOIN main.deps AS d ON p.id = d.package_id WHERE d.name = SPLIT_UID('name', ?1) AND d.origin = SPLIT_UID('origin', ?1); in file pkgdb_iterator.c:277: database disk image is malformed
pkg: sqlite error while executingû in file pkgdb_iterator.c:228: database disk image is malformed
pkg: sqlite error while executing SELECT p.name, p.origin, p.version, 0 FROM main.packages AS p INNER JOIN main.deps AS d ON p.id = d.package_id WHERE d.name = SPLIT_UID('name', ?1) AND d.origin = SPLIT_UID('origin', ?1); in file pkgdb_iterator.c:277: database disk image is malformed
pkg: sqlite error while executing SELECT p.name, p.origin, p.version, 0 FROM main.packages AS p INNER JOIN main.deps AS d ON p.id = d.package_id WHERE d.name = SPLIT_UID('name', ?1) AND d.origin = SPLIT_UID('origin', ?1); in file pkgdb_iterator.c:277: database disk image is malformed
Checking for upgrades (41 candidates): 100%
The following 4 packages will be affected (of 0 checked):
 
Try:
Code:
cd /var/backups
xz -d pkg.sql.xz
#(or pkg.sql.xz.1,  pkg.sql.xz.2.....)
pkg backup -r pkg.sql

Code:
root@Trimon:/tmp # ls -lrt /var/backups/pkg.sql.xz*
-rw-r--r--  1 root  wheel  6511296 Jun 24 03:05 /var/backups/pkg.sql.xz.2
-rw-r--r--  1 root  wheel  6511296 Jun 25 03:03 /var/backups/pkg.sql.xz

root@Trimon:/tmp # diff /var/backups/pkg.sql.xz /var/backups/pkg.sql.xz.2
Files /var/backups/pkg.sql.xz and /var/backups/pkg.sql.xz.2 differ

root@Trimon:/tmp # cp /var/backups/pkg.sql.xz .
root@Trimon:/tmp # xz -d pkg.sql.xz
root@Trimon:/tmp # pkg backup -r pkg.sql
Restoring database:
Restoring: 100%
pkg: sqlite error while executing backup step in file backup.c:101: not an error
pkg: sqlite error -- (null)

root@Trimon:/tmp # cp /var/backups/pkg.sql.xz.2 .
root@Trimon:/tmp # xz -d pkg.sql.xz.2
xz: pkg.sql.xz.2: Filename has an unknown suffix, skipping
root@Trimon:/tmp # mv pkg.sql.xz.2 pkg.sql.xz
root@Trimon:/tmp # xz -d pkg.sql.xz
xz: pkg.sql.xz: Compressed data is corrupt

I just realized this. I thought pkg kept itself up-to-date?

Code:
root@Trimon:/tmp # pkg --version
1.3.8
root@Trimon:/tmp # pkg rquery -e '%n=pkg' %v
1.5.4
 
It does keep itself up to date assuming you're not updating too many versions ahead like it seems to be the case here. I would re-install pkg(8) with this to bring it up to date:

/usr/sbin/pkg bootstrap -f
pkg update -f
 
It does keep itself up to date assuming you're not updating too many versions ahead like it seems to be the case here. I would re-install pkg(8) with this to bring it up to date:

/usr/sbin/pkg bootstrap -f
pkg update -f
Unfortunately

Code:
root@Trimon:/tmp # /usr/sbin/pkg bootstrap -f
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from ftp://ftp@10.1.1.6/pub/pkg/101amd64/RL_WS, please wait...
pkg-static: sqlite error while executing DROP INDEX deps_unique;CREATE UNIQUE INDEX deps_unique ON deps(name, version, package_id); in file pkgdb.c:2333: database disk image is malformed

I think at this stage I need a clean sql database. None of the other systems have seen this problem, pkg is the correct version on them, so it was just my workstation that failed to keep up for some reason.
 
First, don't ask me anything about my confidence in anything portmaster or pkg. :mad:
Then again, I have reams of notes about legacy version trash that portmaster and pkg have left behind . . .that I can share. I don't think that one system (the left hand) knows what the other (the right hand) is doing.

Regardless, what does this mean?

===> Registering installation for sqlite3-3.9.2
Installing sqlite3-3.9.2...
pkg-static: sqlite error while executing INSERT INTO files (path, sha256, package_id) VALUES (?1, ?2, ?3) in file pkgdb.c:1754: database disk image is malformed
*** Error code 70

Stop.
make[1]: stopped in /usr/ports/databases/sqlite3
*** Error code 1

I started out trying to reinstall (with no success regarding) PHP, then (working back up the complaint list) autoconfig, then Perl . . .now this re. sqlite. I just don't understand why the developers can't write the make files such that the [I]makes[/I] can resolve this sort of thing. I'm a 66 year old career programmer. Seems to me like a few more if-then-else interrogatories could figure this out . . .just do it -- overlay it.

BTW, apparently autoconfig and sqlite are dependencies of the scripting languages. If the "makes" need them, then just reinstall corrected version. Be done with it!
 
So to follow up on this, I tried to repair the database, I tried, well, lots of things and nothing worked.

In the end, I created a script which installs all the packages I want on the workstation, stored on a server.

I then completely erased the machine and reinstalled the OS (it's automated, so no pain there), finally ran the script. Now I don't care if pkg's database gets messed up, I can nuke it and run the script.

I'm guessing the issue arose from me killing ports-mgmt/pkg while it was operating on the database and somehow databases/sqlite3 dropped the ball.

ports-mgmt/pkg has been flawless for me otherwise, coupled with ports-mgmt/poudriere.
 
Well, like another Arkansan of dubious celebrity, "Ah I feel your pain"; however, I think there is a common thread here, and it is revealed in your comment,
I'm guessing the issue arose from me killing ports-mgmt/pkg while it was operating on the database and somehow databases/sqlite3 dropped the ball.
and I think it is sqlite3, et al.

Somewhere in the make-file logic, there should be code that reads something like:

Code:
(pseudocode)
If there is a problem with sqlite,
then do{fix sqlite};

If sqlite is still broken,
then {do the fix again until it's fixed}
else
{do whatever's next}
endif;

exit(0);

function(fix sqlite){
do whatever's necessary
};
I've screwed with this since last Friday afternoon, and that is way too much wasted time. I'd much rather be trout fishing on the upper White River in Arkansas or snow skiing at Arapahoe Basin, CO.

BTW, it would be interesting to see your reinstall script.
 
BTW, it would be interesting to see your reinstall script.

So it's actually a bit more than just a reinstall script, but making no apologies for the lack of comments, lack of decent checking, etc., here you go :D

This lives in /etc (I roll my own kernel+world and insert a few items that are part of my base).

So this part is the common script that lives on all machines. It mounts a directory over NFS based on the short hostname, which contains all the per-host specific files (see below). One of those is the update.local.sh script, which in this particular case is my workstation.

Code:
$ cat /etc/update.sh
#!/bin/sh

logger () {
 ${LOGGER} -t AI $1
}
RCConf_set () {
 $AWK ${RCP} operation=set key=$1 value=$2 < /etc/rc.conf > /tmp/stage/etc/rc.conf && \
cp /tmp/stage/etc/rc.conf /etc && logger "rc.conf/$1"
}

INetConf_set () {
 ${AWK} -f ${aLIB} -f ${SCRIPT}/e_inetd_conf.awk -f ${aEXEC} operation=set key=$1 value="$2" \
< /etc/inetd.conf > /tmp/stage/etc/inetd.conf && cp /tmp/stage/etc/inetd.conf /etc && logger "inetd.conf $1"
}

Pkg_AddIfMissing () {
 ${PKG} query -e '%a=0' %o | ${AWK} -f ${aLIB} -f ${SCRIPT}/e_Pkg.awk -f ${aEXEC} operation=addifmissing pkg=$1
 if [ $? == 0 ]; then
   PKG_INSTALLED=${PKG_INSTALLED},$2
 fi
}
Pkg_RemoveIfInstalled () {
 ${PKG} query -e '%a=0' %o | ${AWK} -f ${aLIB} -f ${SCRIPT}/e_Pkg.awk -f ${aEXEC} operation=delifpresent pkg=$1
 if [ $? == 0 ]; then
   PKG_INSTALLED=${PKG_INSTALLED},$2
 fi
}
Pkg_Upgrade () {
 env ASSUME_ALWAYS_YES=YES ${PKG} upgrade
}
if [ `id -u` != 0 ]; then
 echo "ONLY ROOT CAN EXECUTE THIS SCRIPT";
 exit 1
fi
if [ $# == 1 ]; then
 MODE=$2
else
 MODE=UPDATE
fi
echo "****************"
echo "* Mode: ${MODE}"
echo "****************"
H=`/bin/hostname -s`
CP=/bin/cp
CPIO=/usr/bin/cpio
FIND=/usr/bin/find
RM=/bin/rm
TM=/tmp/mnt
TS=/tmp/stage
AWK=/usr/bin/awk
PKG=/usr/sbin/pkg
KILL=/bin/kill
LOGGER=/usr/bin/logger
REBOOT=/sbin/reboot
SERVICE=/usr/sbin/service
SCRIPT=/tmp/mnt/common/scripts
aEXEC=${SCRIPT}/exec.awk
aLIB=${SCRIPT}/lib.awk

/bin/mkdir ${TM} ${TS}
/sbin/mount -t nfs,ro 10.1.1.1:/var/lib/tftpboot/FreeBSD/SystemConfig/Hostname ${TM}
${CP} -a ${TM}/common/root/* ${TS}
${CP} -a ${TM}/$H/root/* ${TS}
MyScriptDateBefore=`ls -lD%s /etc/update.sh | awk '{print $6}'`
${CP} -a ${TS}/etc/update.sh /etc
MyScriptDateAfter=`ls -lD%s /etc/update.sh | awk '{print $6}'`

#${CP} -av ${TS}/* /
PWD=`pwd`
cd ${TS}
${FIND} etc | ${CPIO} -p -dmv /etc
#cd ${PWD}
#${RM} -rf ${TS}

if [ "${MyScriptDateBefore}" == "${MyScriptDateAfter}" ]; then
 if [ -f ${TM}/common/scripts/standard.sh ]; then
  . ${TM}/common/scripts/standard.sh ${MODE}
 fi

 if [ -f /etc/update.local.sh ]; then
  . /etc/update.local.sh ${MODE}
 fi
 #--------
 #PWD=`pwd`
 #cd ${TS}
 ${FIND} . | ${CPIO} -p -dmv /
 cd ${PWD}
 ${RM} -rf ${TS}

 /sbin/umount ${TM}
 ${RM} -rf ${TM}
else
 echo "***"
 echo "*** Update script changed, finishing early..."
 echo "***"
 /sbin/umount ${TM}
 ${RM} -rf ${TM}
 exit 10
fi

if [ "${SYS_REBOOT}" == "TRUE" ]; then
 logger Rebooting...
 echo "SYSTEM ABOUT TO REBOOT."
 sleep 1
 echo "SYSTEM ABOUT TO REBOOT.."
 sleep 2
 echo "SYSTEM ABOUT TO REBOOT..."
 sleep 3
 echo "SYSTEM ABOUT TO REBOOT...."
 sleep 4
 ${REBOOT}
else
 if [ "${SERVICE_CUPSD_RESTART}" == "TRUE" ]; then
  $SERVICE cupsd stop
  $SERVICE cupsd start
 fi
 if [ "${SERVICE_SAMBA_RESTART}" == "TRUE" ]; then
  $SERVICE samba_server stop
  $SERVICE samba_server start
 fi
 if [ "${INIT_REBOOT}" == "TRUE" ]; then
  ${KILL} -HUP 1
 fi
fi
$

So the directory layout looks like this:

Code:
[root@RLServices /]# cd /var/lib/tftpboot/FreeBSD/SystemConfig/Hostname/ws-leeb
[root@RLServices ws-leeb]# find .
.
./Disk2
./root
./root/etc
./root/etc/update.local.sh
./root/etc/ssl
./root/etc/ssl/certs
./root/etc/ssl/certs/Server-AD-ldap-proxy.crt
./root/etc/ssl/certs/4e6ecc8f.0
./root/etc/ssl/certs/TNMC-RootCA.crt
./root/etc/ssl/certs/Server-AD-dc-root.crt
./root/etc/ssl/certs/db302771.0
./root/etc/ssl/certs/01e214fd.0
./root/etc/ssl/certs/CANI-RootCSA.crt
./root/etc/ssl/certs/b74c0feb.0
./root/etc/ssl/certs/TNMC-RootCSA.crt
./root/etc/ssl/certs/8f8016b4.0
./root/etc/ssl/certs/Server-LDAP1.crt
./root/etc/ssl/certs/a78a50b2.0
./root/etc/ssl/certs/Server-AD-dc-lodge.crt
./root/etc/ssl/certs/3bc4d629.0
./root/etc/nsswitch.conf
./root/etc/ssh
./root/etc/ssh/ssh_host_ecdsa_key
./root/etc/ssh/id_dsa
./root/etc/ssh/ssh_host_dsa_key.pub
./root/etc/ssh/ssh_host_dsa_key
./root/etc/ssh/ssh_host_rsa_key
./root/etc/ssh/id_dsa.pub
./root/etc/ssh/ssh_host_ecdsa_key.pub
./root/etc/ssh/ssh_host_rsa_key.pub
./root/etc/pam.d
./root/etc/pam.d/system
./root/etc/pam.d/sshd
./root/etc/rc.conf.local
./root/usr
./root/usr/local
./root/usr/local/etc
./root/usr/local/etc/nss_ldap.conf
./root/usr/local/etc/pkg
./root/usr/local/etc/pkg/repos
./root/usr/local/etc/pkg/repos/NyingmaCentral.conf
./root/usr/local/etc/ldap.conf
./root/usr/local/etc/squid
./root/usr/local/etc/squid/squid.conf
./root/usr/local/etc/openldap
./root/usr/local/etc/openldap/ldap.conf
./root/usr/local/etc/security
./root/usr/local/etc/security/pam_mount.conf.xml
./root/usr/local/etc/smb4.conf
./root/usr/local/etc/X11
./root/usr/local/etc/X11/xorg.conf.d
./root/usr/local/etc/X11/xorg.conf.d/xorg.conf

The important parts being /root/etc/update.local.sh and /root/usr/local/etc/pkg/ports/NyingmaCentral.conf

Then finally it's going to run the update.local.sh containing

Code:
$ cat /etc/update.local.sh 
${AWK} </boot/loader.conf -f ${aLIB} -f ${SCRIPT}/e_loader_conf.awk -f ${aEXEC} key=nvidia_load value=\"YES\" > /tmp/stage/boot/loader.conf && SYS_REBOOT=TRUE && \
${CP} /boot/loader.conf /boot/loader.conf.local.bak && \
${CP} /tmp/stage/boot/loader.conf /boot && \
logger "Local processed /boot/loader.conf"

Pkg_AddIfMissing net/samba42
Pkg_AddIfMissing net/nss_ldap
#Pkg_AddIfMissing security/pam_ldap
Pkg_AddIfMissing security/pam_mkhomedir
Pkg_AddIfMissing sysutils/pam_mount
Pkg_AddIfMissing editors/nano EDITORS
Pkg_AddIfMissing x11-servers/xorg-server
Pkg_AddIfMissing x11-drivers/xf86-input-keyboard
Pkg_AddIfMissing x11-drivers/xf86-input-mouse
Pkg_AddIfMissing x11/xinit
Pkg_AddIfMissing x11/nvidia-driver-304
Pkg_AddIfMissing x11-wm/xfce4
#Pkg_AddIfMissing www/chromium
Pkg_AddIfMissing x11/nvidia-settings
Pkg_AddIfMissing www/squid
Pkg_AddIfMissing net/rdesktop
#Pkg_AddIfMissing editors/libreoffice
#Pkg_AddIfMissing ftp/filezilla
Pkg_AddIfMissing graphics/evince
Pkg_AddIfMissing graphics/gimp
Pkg_AddIfMissing graphics/inkscape
#Pkg_AddIfMissing multimedia/vlc
Pkg_AddIfMissing net/sqtop
Pkg_AddIfMissing net/wireshark
Pkg_AddIfMissing net/x11vnc
#Pkg_AddIfMissing print/cups-client
Pkg_AddIfMissing sysutils/kdirstat
Pkg_AddIfMissing sysutils/smartmontools
Pkg_AddIfMissing sysutils/xfce4-cpugraph-plugin
Pkg_AddIfMissing sysutils/xfce4-fsguard-plugin
Pkg_AddIfMissing sysutils/xfce4-genmon-plugin
Pkg_AddIfMissing sysutils/xfce4-mount-plugin
Pkg_AddIfMissing sysutils/xfce4-netload-plugin
Pkg_AddIfMissing textproc/antiword
Pkg_AddIfMissing textproc/meld
#Pkg_AddIfMissing www/opera

Pkg_Upgrade

${AWK} </etc/sysctl.conf -f ${aLIB} -f ${SCRIPT}/e_sysctl_conf.awk -f ${aEXEC} key=kern.ipc.shm_allow_removed value=1 > /tmp/stage/etc/sysctl.conf && \
${CP} /etc/sysctl.conf /etc/sysctl.conf.local.bak && \
${CP} /tmp/stage/etc/ttys /etc && \
logger "/etc/sysctl.conf modified"

For added fun, if you are still with me,that Disk2 file contains

Code:
SCRUB ada0
SCRUB ada1
SCRUB ada2

part ada0
 destroy -F
 create -s GPT
 bootcode -b /boot/pmbr
 add -t freebsd-boot -a 4K -s 128K -l boot0
 bootcode -p /boot/gptboot -i 1
 add -t freebsd-swap -a 4K -s 4G -l swap0
 add -t freebsd-ufs -a 4K -s 10G -l root0
 add -t freebsd-ufs -a 4K -s 10G -l var0
 add -t freebsd-ufs -a 4K -s 20G -l squid0
 add -t freebsd-ufs -a 4K -s 100G -l usr0

part ada1
 destroy -F
 create -s GPT
 bootcode -b /boot/pmbr
 add -t freebsd-boot -a 4K -s 128K -l boot1
 bootcode -p /boot/gptboot -i 1
 add -t freebsd-swap -a 4K -s 4G -l swap1
 add -t freebsd-ufs -a 4K -s 10G -l root1
 add -t freebsd-ufs -a 4K -s 10G -l var1
 add -t freebsd-ufs -a 4K -s 20G -l squid1
 add -t freebsd-ufs -a 4K -s 100G -l usr1

part ada2
 destroy -F
 create -s GPT
 bootcode -b /boot/pmbr
 add -t freebsd-boot -a 4K -s 128K -l boot2
 bootcode -p /boot/gptboot -i 1
 add -t freebsd-swap -a 4K -s 4G -l swap2
 add -t freebsd-ufs -a 4K -s 10G -l root2
 add -t freebsd-ufs -a 4K -s 20G -l var2
 add -t freebsd-ufs -a 4K -s 20G -l squid2
 add -t freebsd-ufs -a 4K -s 200G -l usr2

stripe
 label Svar /dev/gpt/var0 /dev/gpt/var1
 label Ssquid /dev/gpt/squid0 /dev/gpt/squid1 /dev/gpt/squid2
 label Susr /dev/gpt/usr0 /dev/gpt/usr1

mirror
 label Mboot /dev/gpt/boot0 /dev/gpt/boot1 /dev/gpt/boot2
 label Mroot /dev/gpt/root0 /dev/gpt/root1 /dev/gpt/root2
 label Mvar /dev/stripe/Svar /dev/gpt/var2
 label Musr /dev/stripe/Susr /dev/gpt/usr2

newfs
 /dev/mirror/Mroot
 /dev/mirror/Mvar
 /dev/mirror/Musr
 /dev/stripe/Ssquid

fstab
 /dev/mirror/Mroot / ufs rw 0 1
 /dev/gpt/swap0 none swap sw 0 0
 /dev/gpt/swap1 none swap sw 0 0
 /dev/gpt/swap2 none swap sw 0 0
 /dev/mirror/Musr /usr ufs rw 0 2
 /dev/mirror/Mvar /var ufs rw 0 2
 /dev/stripe/Ssquid /SquidCache ufs rw,async,noatime 0 2

bootloader.conf
 geom_stripe_load="YES"
 geom_mirror_load="YES"
 tmpfs_load="YES"
 vm.pmap.pcid_enabled="0"

os
 Workstation

distribute
 kernel
 base

end
which is used by my install script.

So for a bare-metal rebuild, I PXE boot the machine into my install version of FreeBSD (basically just a GENERIC amd64 kernel with /etc/INSTALL.SH in there and run the install script. That uses the MAC address, which is linked to the hostname 00:1e:c9:44:dc:b4 -> ../Hostname/ws-leeb/, parses the above, which formats the disks, sets up the GEOM structures, fstab, grabs the OS kernel.txz base.txz files, extracts them and runs the same update script mentioned above. Finally it reboots into a usable system.

This can take around 20 minutes to run on my workstation, but it's all hands off after I hit enter. A server typically is far less, as the packages are much smaller.

I wrote this because the nice new bsdinstall(8) didn't agree with me (it was very new and I was very impatient).

<soapbox on>
I'm trying to move migrating my severs from CentOS to FreeBSD and wanted a reproducible way to bring up a system, easy to move to different hardware and (eventually) self healing/auditing. By that I mean if a file is modified on the system directly, rather than just overwriting them by running the update script periodically, I'd like to diff what's on the machine vs. the staging server, mail me the offending file, then overwrite it with the staging version. While Linux has some nice newer stuff (I've been deep into IP and QoS mostly), it's too much of a wild bronco for this aging admin. I don't want to have to re-learn what I already know, what already works very well (besides which using both GNU and BSD utilities gets darned confusing).

FreeBSD is, IMHO, a very well engineered OS and I'd rather the slower pace.
<soapbox off>
 
First, to leebrown66, thanks again for sharing your custom installation method . . .very interesting.

Second, apologies for what continues to be a rather lengthy post.:eek:

Yet, I still want to understand the pkg and portmaster system.

1). I still would like to know what caused the following failure:
pkg-static: sqlite error while executing INSERT INTO files (path, sha256, package_id) VALUES (?1, ?2, ?3) in file pkgdb.c:1754: database disk image is malformed
*** Error code 70
What is implied by database disk image is malformed?

If I sniff around for pkgdb.c, the following is revealed:
# find / -name pkgdb.c -print
find: /usr/local/lib/perl5/5.22/unicore/lib/Ext: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/GCB: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Gc: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/GrBase: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Hex: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Hst: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Hyphen: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/IDC: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/IDS: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Ideo: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/In: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Jg: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Jt: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/LOE: Bad file descriptor
find: /usr/local/lib/perl5/5.22/unicore/lib/Lb: Bad file descriptor

Execution of the command, /usr/local/lib/perl5/5.22/unicore/lib # ls reveals the following:
Age BidiM CI CWL Ccc Dep Ext Hex IDS Jt Math NFKCQC PatSyn SB
Alpha Blk CWCF CWT CompEx Dia GCB Hst Ideo LOE NChar NFKDQC PatWS SD
Bc Bpt CWCM CWU DI Dt Gc Hyphen In Lb NFCQC Nt Perl STerm
BidiC CE CWKCF Cased Dash Ea GrBase IDC Jg Lower NFDQC Nv QMark Sc
. . .however, ls -ls does not list the objects tagged as assoc/w a "bad file descriptor". They just don't appear in the output list.

Should I manually delete /usr/local/lib/perl5 and try to reinstall perl5.22?

2). What database . . .perhaps a sqlite3 table, or otherwise what does pkg info use to generate it's list?

3). Regardless, I am willing to reinstall ALL user ports. To accomplish that, I have tried following the guidelines in PORTMASTER(8), i.e.,

Using portmaster to do a complete reinstallation of all your ports:
1. portmaster --list-origins > ~/installed-port-list
2. Update your ports tree
3. portmaster -ty --clean-distfiles
4. portmaster --check-port-dbdir
5. portmaster -Faf
6. pkg_delete -a
7. rm -rf /usr/local/lib/compat/pkg
8. Back up any files in /usr/local you wish to save,
such as configuration files in /usr/local/etc
9. Manually check /usr/local and /var/db/pkg
to make sure that they are really empty
10. Re-install portmaster
11. portmaster `cat ~/installed-port-list`

portmaster -ty --clean-distfiles seems to attempt to make various objects. For example,
make: Fatal errors encountered -- cannot continuemake: "/usr/ports/databases/postgresql-plpython/Makefile" line 45: Cannot open /usr/ports/databases/postgresql-plpython/../postgresql84-server/Makefile
make: Fatal errors encountered -- cannot continuemake: "/usr/ports/databases/postgresql-tcltk/Makefile" line 71: Cannot open /usr/ports/databases/postgresql-tcltk/../../databases/postgresql84-server/Makefile
. . .etc. . . .etc.
make: "/usr/ports/x11-themes/qt-bluecurve-theme/Makefile" line 45: Cannot open /usr/ports/x11-themes/qt-bluecurve-theme/../bluecurve-themes/Makefile
make: Fatal errors encountered -- cannot continuemake: "/usr/ports/x11/avant-window-navigator-xfce4/Makefile" line 13: Cannot open /usr/ports/x11/avant-window-navigator-xfce4/../avant-window-navigator/Makefile
make: Fatal errors encountered -- cannot continue===>>> Checking for stale distfiles

Deleting apache24/httpd-2.4.17.tar.bz2

Deleting freebsd-doc-47806.tar.gz

Deleting freetype-2.6.tar.bz2

Deleting joomla-joomla-cms-3.4.5_GH0.tar.gz

Deleting perl/perl-5.22.0.tar.xz

===>>> Exiting
Why? What I'm wanting to do is get rid of old ports and packages.

Then this follows: portmaster -Faf but precedes pkg_delete -a. What is the logic here . . .seems to me that the objective is to remove all ports and packages before reinstalling? Why have portmaster attempt to update all before deleting all?

Why is pkg_delete -a suggested? That is a command from the old deprecated pkg_* system and is not installed on my current system (v10.2 RELEASE); however, pkg delete -a seems to attempt (it eventually fails with a complaint from sqlite3 similar to previously mentioned above) to delete all. Is that what the "-a" flag indicates? I can't find any explanation of the "-a" flag in the documentation.

pkg info reveals the following, et al.
perl5-5.22.0_4 Practical Extraction and Report Language
perl5.18-5.18.4_17 Practical Extraction and Report Language

If I execute pkg delete perl5-5.22.0_4, the procedure crashes the OS and initiates a reboot! What's with that? !!!

I really don't want to reinstall the OS . . .it seems to be OK, but I'm willing to start fresh with a new install of the user ports, but I just can't get the old legacy stuff out of the way.

All suggestions will be greatly appreciated!
 
RE:
Before continuing, please boot into single user mode and run fsck on all the filesystems with fsck -tufs -y.
. . .on my way out to CAP HQ (where the server is) to rerun fsck -y yet again from single user mode, plus the -t usf argument.

pkgdb was used by ports-mgmt/portupgrade, it is not part of pkg.
. . .OK, I'm not sure how this became an issue with Perl5.22. Portupgrade (to my knowledge) has never been installed??? I've mainly focused on pkg and/or portmaster.

The updated procedure to rebuild all ports is here: Thread rebuilding-all-ports-with-portmaster.51210.
Thanks, I'll take a look. Actually, I've been following your write-up, http://www.wonkity.com/~wblock/docs/html/portupgrade.html#_reinstalling_all_ports .
 
You're right. The portupgrade version was written in Ruby.

In any case, the database is corrupted and needs to be recreated.
 
I have yet to see a way to rebuild the database based on what is currently installed. In the best case, I expect the notion of auto (ie dependent vs requested) is going to be lost.

That's why I have a script to install the packages, so if the database breaks, the database can be recreated. As I create my own packages, reinstalling 500+ packages isn't a big deal, but I imagine for folks relying on an internet connection, that could be a long time to 'fix'.

Perhaps if pkg(8) kept a separate text file of requested packages itself this could be achieved in a more autonomous way that also didn't involve re-installing everything.
 
Last edited by a moderator:
Good afternoon gentlemen:

My apologies for perhaps seeming to be unresponsive or otherwise out of the loop. I continue to struggle with the problems; however, while working towards a solution both Saturday afternoon and Sunday, I was able to remove and reinstall pkg(8) and portmaster(8). This eliminated the complaints about malformed database disk images associated with the sqlite3 DBMS.

In any case, the database is corrupted and needs to be recreated.
I will post the steps to the solution when I finish writing my Epistle of Ports. ;)

I have yet to see a way to rebuild the database based on what is currently installed.

Perhaps if pkg(8) kept a separate text file of requested packages itself this could be achieved in a more autonomous way that also didn't involve re-installing everything.
I think this is what the following from PORTMASTER(8) is intended to accomplish in steps 1 and 11:
Using portmaster to do a complete reinstallation of all your ports:
1. portmaster --list-origins > ~/installed-port-list
2. Update your ports tree
3. portmaster -ty --clean-distfiles
4. portmaster --check-port-dbdir
5. portmaster -Faf
6. pkg_delete -a (Command from old pkg system? !!!)
Pkg delete -afy seems to attempt to delete all – is that what the "-a" flag indicates?
7. rm -rf /usr/local/lib/compat/pkg
8. Back up any files in /usr/local you wish to save,
such as configuration files in /usr/local/etc
9. Manually check /usr/local and /var/db/pkg
to make sure that they are really empty
10. Re-install portmaster
11. portmaster `cat ~/installed-port-list`

After all, the user can designate the name and/or location of the "installed port list". It's just an ASCII text file.

Continuing, additionally I successfully completed a make of lang/php56.

A problem of a crashing OS still persists. I tried to make lang/perl5.22 but that crashes the OS . . .repeated several times. On a whim, I decided to try a make of lang/perl5.20 and it completed successfully.

Toward the end of the day (Sunday evening) I tried to make www/apache24 but it, too, crashes the OS.
/usr/ports/www/apache24 # make
===> apache24-2.4.18 depends on executable: autoconf-2.69 - found
===> apache24-2.4.18 depends on executable: autoheader-2.69 - found
===> apache24-2.4.18 depends on executable: autoreconf-2.69 - found
===> apache24-2.4.18 depends on executable: aclocal-1.15 - found
===> apache24-2.4.18 depends on executable: automake-1.15 - found
===> apache24-2.4.18 depends on executable: libtoolize - found
===> apache24-2.4.18 depends on package: libiconv>=1.14_9 - found
===> apache24-2.4.18 depends on shared library: libexpat.so - found (/usr/local/lib/libexpat.so)
===> apache24-2.4.18 depends on shared library: libapr-1.so - not found
===> apr-1.5.2.1.5.4 depends on package: libiconv>=1.14_9 - found
===> apr-1.5.2.1.5.4 depends on shared library: libexpat.so - found (/usr/local/lib/libexpat.so)
===> apr-1.5.2.1.5.4 depends on shared library: libgdbm.so - found (/usr/local/lib/libgdbm.so)
===> apr-1.5.2.1.5.4 depends on shared library: libmysqlclient.so.18 - found (/usr/local/lib/mysql/libmysqlclient.so.18)
===> apr-1.5.2.1.5.4 depends on shared library: libdb-5.3.so - not found
===> db5-5.3.28_2 depends on file: /usr/local/openjdk8/bin/java - not found
===> License GPLv2 accepted by the user
===> Found saved configuration for openjdk8-8.66.17
===> openjdk8-8.66.17 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by openjdk8-8.66.17 for building
===> Extracting for openjdk8-8.66.17
=> SHA256 Checksum OK for openjdk-8-src-b132-03_mar_2014.zip.
=> SHA256 Checksum OK for patch-8u05-b13.xz.
=> SHA256 Checksum OK for patch-8u11-b13.xz.
=> SHA256 Checksum OK for patch-8u20-b26.xz.
=> SHA256 Checksum OK for patch-8u25-b17.xz.
=> SHA256 Checksum OK for patch-8u31-b13.xz.
=> SHA256 Checksum OK for patch-8u40-b25.xz.
=> SHA256 Checksum OK for patch-8u45-b14.xz.
=> SHA256 Checksum OK for patch-8u51-b16.xz.
=> SHA256 Checksum OK for patch-8u60-b23.xz.
=> SHA256 Checksum OK for patch-8u66-b17.xz.
At the point of the panic crash, here is a photo of the console output prior to reboot.

OS_crash.JPG


This just continues to be so frustrating. I'm at a loss to understand what is happening, other than I think the same scenario was playing out when the Perl5.22 make crashed, too. Perhaps something to do with
Code:
=> SHA256 Checksum OK for patch-8u66-b17.xz.
. . .or what follows?


Well, I've found this: https://lists.freebsd.org/pipermail/freebsd-current/2013-August/043722.html
and this: https://lists.freebsd.org/pipermail/freebsd-current/2013-August/043677.html
 
I think this is what the following from PORTMASTER(8) is intended to accomplish in steps 1 and 11:
Not quite what I meant. That will produce a list of all ports as I understand it (root and leaf ports as the manpage describes it), including dependencies.
To put this in pkg(8) parlance, I would want only:

pkg query -e '%a=0' %o

which is a list of the 29 ports I asked to be installed on this system and not

pkg query -e '%a=1' %o

which are the 416 dependents.

Not that any of this helps with your situation I'm afraid :(
 
rtwingfield, the crashing OS is very likely a hardware problem, overheating, bad RAM, voltages fluctuating, disk going bad (which would explain why it crashes at the same place if it does). What you're seeing in form of crashes while trying to use and fix the pkg database are symptoms of the problem, not the cause.
 
Thanks for the thoughts. The six scsi disks are configured as three RAID-1 pairs, each of which are assigned to three different file systems. I do know that the SQLite3 DBMS schema was corrupted. As I've mentioned, I've reinstalled and essentially started from scratch and pkg and portmaster seem to be working (no malformed disk image complaints). I'll have to do additional diagnostics tomorrow from the HQ where the hardware is located. I can't access from remote (here) while in single user mode. Additionally, I don't think fsck was performing as advertised because while in single user mode, fsck -y seemed to be ignoring the assume all prompts to be answered as "y". All prompts for fix or repair were apparently auto-responded to as "no". Regardless, all latter instances of the procedures eventually returned clean file system messages.

Also in spite of issuing a mount -u -w / , the system still returned a comment . . .something like file system is read only. So if the target file system was truly read-only, then how could it be repaired?

Tomorrow morning, I'm going to try some variant syntax such as mount -u -a -o rw / and perhaps with an -f , too. Once I'm convinced that fsck ran successfully, and then if the problem persists, then I will start pulling, testing and swapping RAM.
 
Also in spite of issuing a mount -u -w / , the system still returned a comment . . .something like file system is read only. So if the target file system was truly read-only, then how could it be repaired?
fsck(8) works directly on the filesystem and can really only fix things if the filesystem is unmounted. As an alternative it will allow a filesystem to be mounted read-only but will present a warning. It cannot fix the filesystem if it's mounted read/write (which is probably why you got "no" even when you added -y).

The reason why you need to run fsck(8) when booted to single user mode is because only the root filesystem is mounted (read-only). If you subsequently run mount -u / you will re-mount the root filesystem read/write, which prevents fsck(8) from fixing things.
 
Following boot into single user mode, simply executing fsck -y repaired the file system. Old dog learned new trick. :)

Many thanks again!
 
Try:
Code:
cd /var/backups
xz -d pkg.sql.xz
#(or pkg.sql.xz.1,  pkg.sql.xz.2.....)
pkg backup -r pkg.sql
This happened again to me and while the above failed in the same way it did before, this procedure worked for me:
As root:
Code:
cd /var/backups
xz -d pkg.sql.xz
rm /var/db/pkg/local.sqlite
sqlite3 /var/db/pkg/local.sqlite
sqlite> .read /var/backups/pkg.sql
sqlite> .quit
Use at your own risk...
 
Back
Top