Commit 612e039b authored by Franco Fichtner's avatar Franco Fichtner

rc: persistent firmware cache dirs on MFS; closes #924

This adds the following directories to avoid problems with
smaller embedded systems that do not have enough RAM:

	/var/cache/opnsense-update
	/var/cache/pkg

This is particularly bad for Nano systems with enough RAM
as it may grind the flash storage, but since this is a
"luxury" problem with Nano the scope is limited to that.
It's either being able to upgrade the firmware for all or
not at all.

FWIW, firmware upgrades will have to move to persistent
storage as soon as we hit FreeBSD 11 for the simple fact
that we'll have to do partial upgrade stages for the ABI
jumps of the kernel / base system anyway and cannot expect
to fetch more packages after reboot.

Proper garbage collection exists in both tools that shall
avoid overloading the persistant storage.
parent a40388b4
#!/bin/sh #!/bin/sh
# Copyright (c) 2014-2015 Franco Fichtner <franco@opnsense.org> # Copyright (c) 2014-2016 Franco Fichtner <franco@opnsense.org>
# Copyright (c) 2004-2010 Scott Ullrich <sullrich@gmail.com> # Copyright (c) 2004-2010 Scott Ullrich <sullrich@gmail.com>
# Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net> # Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>
# All rights reserved. # All rights reserved.
...@@ -91,51 +91,78 @@ fi ...@@ -91,51 +91,78 @@ fi
# Enable console output if its muted. # Enable console output if its muted.
/sbin/conscontrol mute off >/dev/null /sbin/conscontrol mute off >/dev/null
USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /conf/config.xml` setup_mfs_link()
if [ ${USE_MFS_TMPVAR} -ne 0 ]; then {
echo -n "Setting up memory disks..." ROOT=${1}
MFS=${2}
NAME=${3}
# Create dummy directory to for MFS-bound
# directories that require a persistant
# storage underneath to run.
if [ ! -d /root/var/db/pkg ]; then if [ ! -d "${ROOT}${MFS}/${NAME}" ]; then
mkdir -p /root/var/db mkdir -p "${ROOT}/${MFS}"
mv /var/db/pkg /root/var/db mv "${MFS}/${NAME}" "${ROOT}/${MFS}"
# create a symlink underneath as well # create a symlink underneath as well
# to fix early boot pkg(8) issues: ln -s "${ROOT}${MFS}/${NAME}" "${MFS}/${NAME}"
ln -s /root/var/db/pkg /var/db/pkg
fi fi
}
if [ ! -d /root/var/crash ]; then
mkdir -p /root/var install_mfs_link()
mv /var/crash /root/var {
ln -s /root/var/crash /var/crash ROOT=${1}
MFS=${2}
NAME=${3}
# Redirect persistent, but MFS-bound
# directory after tmpfs mount.
mkdir -p "${MFS}/${NAME}"
ln -s "${ROOT}${MFS}/${NAME}" "${MFS}"
}
delete_mfs_link()
{
ROOT=${1}
MFS=${2}
NAME=${3}
# Persistent copies of MFS-bound directories
# still there must be moved back into place.
if [ -d "${ROOT}${MFS}/${NAME}" ]; then
mkdir -p "${MFS}"
# reverse the recovery symlink before
# moving back the original database
rm -f "${MFS}/${NAME}"
mv "${ROOT}${MFS}/${NAME}" "${MFS}/"
fi fi
}
USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /conf/config.xml`
if [ ${USE_MFS_TMPVAR} -ne 0 ]; then
echo -n "Setting up memory disks..."
setup_mfs_link /root /var/cache opnsense-update
setup_mfs_link /root /var/cache pkg
setup_mfs_link /root /var/db pkg
setup_mfs_link /root /var crash
mount -t tmpfs -o mode=01777 tmpfs /tmp mount -t tmpfs -o mode=01777 tmpfs /tmp
mount -t tmpfs tmpfs /var mount -t tmpfs tmpfs /var
mkdir -p /var/db install_mfs_link /root /var/cache opnsense-update
ln -s /root/var/db/pkg /var/db/pkg install_mfs_link /root /var/cache pkg
install_mfs_link /root /var/db pkg
mkdir -p /var install_mfs_link /root /var crash
ln -s /root/var/crash /var/crash
echo "done." echo "done."
else else
# User must have just disabled RAM disks, remove_mfs_link /root /var/cache opnsense-update
# let's move these back into place. remove_mfs_link /root /var/cache pkg
remove_mfs_link /root /var/db pkg
if [ -d /root/var/db/pkg ]; then remove_mfs_link /root /var crash
mkdir -p /var/db
# reverse the recovery symlink before moving
# back the original database:
rm -f /var/db/pkg
mv /root/var/db/pkg /var/db/
fi
if [ -d /root/var/crash ]; then
mkdir -p /var
rm -f /var/crash
mv /root/var/crash /var/crash
fi
fi fi
# make some directories in /var # make some directories in /var
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment