Recently when developing my kernel module I experienced multiple crashes, mostly as a result of giving bad pointer to some kernel function which resulted in random writes to crucial kernel memory. That manifested as kernel crashing at some point of time in the future, locking up the system completely. Well, reboot and no big deal, right? Except when file system data gets corrupted.
At some point I noticed Firefox acting weirdly. It didn’t remember new visited links and other small issues like that. Moreover when trying to show history it showed up as empty (which does pose a problem as I was trying to find a site I visited), and trying to clear history did nothing either. At this point I was pretty sure something weird was going on as some parts of Firefox clearly remembered history, so I decided to do a check on the SQLite database places.sqlite
that Firefox uses to record history, download, bookmarks and etc. Nowadays Firefox locks the database so when trying to open it Firefox should be closed first (or it also could be copied).
> cd ~/.mozilla/firefox/profile/
> sqlite3 places.sqlite
sqlite> PRAGMA integrity_check;
*** in database main ***
Page 1040: btreeInitPage() returns error code 11
Page 1041: btreeInitPage() returns error code 11
Runtime error: database disk image is malformed (11)
Oops, no wonder it didn’t work properly. Though apparently Firefox didn’t care much as it said nothing. So I tried to recover and rebuild the database by running:
> mv places.sqlite places.sqlite.old
> sqlite3 places.sqlite.old '.recover' > places.sql
> sqlite3 -init places.sql places.sqlite
I did take a look at the generated SQL and everything seemed to be in order. However, when launching Firefox this time around it moved the new places.sqlite
to places.sqlite.corrupt
and generated a new database. So there was still something missing in the places.sql
that made Firefox reject it, but I couldn’t see anything wrong in the SQL statements.
After doing some searching on the net I came across this superuser post that immediately showed where the issue was: Firefox is using PRAGMA user_version
to store a schema version and as it didn’t see a proper version it decided that the database was corrupted.
I’m running Firefox 105 so I get:
> sqlite3 places.sqlite.old 'PRAGMA user_version;'
69
So I prepended
PRAGMA user_version = 69;
PRAGMA journal_mode = truncate;
PRAGMA page_size = 32768;
VACUUM;
PRAGMA journal_mode = wal;
to places.sql
and generated a new SQLite database.
And hurray, this time everything worked (except the missing history earlier from the day that has now disappeared from existence.)