Работа с Firefox из tmpfs/Running a persistent Firefox profile from tmpfs
Как известно, Firefox любит насиловать винт во время работы, особенно это касается файлов sessionstore.js, webappsstore.sqlite, places.sqlite и cookies.sqlite.
Я долго на это смотрел, скрипел зубами, не выдержал и написал скрипт, который выкидывает профиль в /tmpfs во время запуска, а потом синкает его обратно.
It's well known that Firefox likes thrashing your HDD when it works. This problem seriously affects these files: sessionstore.js, webappsstore.sqlite, places.sqlite and cookies.sqlite.
To solve this problem I've created a bash script which copies a Firefox profile to a temporary RAM based directory and then, when Firefox finishes, this script copies changed files back to a persistent directory.
Mode of action:
1) Edit: ~/.mozilla/firefox and add
[Profile1]
Name=firefox-tmpfs
IsRelative=1
Path=firefox-tmpfs
(if you already have more than one profile, Profile1 should become Profile2,3,4 etc.)
2) Create a directory ~/.mozilla/firefox/firefox-persistent
Within it:
mkdir ad
mkdir bk
mkdir ex
ln -s adblockplus $HOME/.mozilla/firefox/firefox-persistent/ad
ln -s extensions $HOME/.mozilla/firefox/firefox-persistent/ex
ln -s bookmarks $HOME/.mozilla/firefox/firefox-persistent/bk
3) Create a symbolic link from /tmp/firefox-tmpfs to ~/.mozilla/firefox/firefox-tmpfs
Create these two files:
$ cat > fxtmpfs.files
addons.sqlite
blocklist.xml
bookmarks.html
cert8.db
chromeappsstore.sqlite
compatibility.ini
content-prefs.sqlite
cookies.sqlite
downloads.sqlite
extensions.ini
extensions.sqlite
formhistory.sqlite
key3.db
lazarus-backup.sqlite
lazarus.sqlite
localstore.rdf
mimeTypes.rdf
permissions.sqlite
places.sqlite
pluginreg.dat
prefs.js
search.json
secmod.db
sessionstore.js
signons.sqlite
$ cat > fxtmpfs
#! /bin/bash
# v1.1
trap '' HUP
fxprofile=firefox-tmpfs
fxpersist=$HOME/.mozilla/firefox/firefox-persistent
dvolatile=/tmp/$fxprofile
die()
{
xmessage -center "FATAL ERROR:
$@" &>/dev/null
exit 1
}
copyback()
{
# $1 - old
# $2 - new
fsize=`stat -c '%s' "$1"` || die "stat of $1 failed"
md5old="X"
if [ -f "$1" ]; then
md5old=`md5sum "$1"` || die "md5sum of $1 failed"
fi
md5new="Y"
if [ -f "$2" ]; then
md5new=`md5sum "$2"` || die "md5sum of $2 failed"
fi
test -f "$2-journal" && die "WHAT THE FUCK IS GOING ON? YOU ARE STILL RUNNING FIREFOX!"
if [ "$fsize" -gt 0 ]; then
if [ "$md5new" != "$md5old" ]; then
/bin/cp -a "$1" "$2" || die "cp from $1 to $2 failed!"
fi
fi
}
files="`dirname $0`/`basename $0`.files"
test -f $files || die "I cannot find $files"
if [ -d "$dvolatile" ]; then
xmessage -center -timeout 5 "Temporary Firefox profile already exists." &>/dev/null &
else
mkdir -p "$dvolatile" || die "mkdir of $dvolatile failed"
# © Artem S. Tashkinov
cp -a "$fxpersist"/* "$dvolatile" || die "cp of $fxpersist to $dvolatile failed"
fi
firefox -no-remote -P $fxprofile
xmessage -center -timeout 3 "Syncing Firefox profile in 3 seconds ..." &>/dev/null &
sync
sleep 3
for i in `cat "$files"`; do
copyback "$dvolatile/$i" "$fxpersist/$i"
done
xmessage -center -timeout 5 "All done." &>/dev/null
chmod +x fxtmpfs
Run fxtmpfs.