summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2013-03-11 22:16:18 -0400
committerjim-p <jimp@pfsense.org>2013-03-11 22:16:18 -0400
commite92e83d4e2e3465bca9ca6d3cc4f746ef6566476 (patch)
treeb72aaf0e1c0b2130b62c28ff7c6ed84076569f64 /etc
parent94ca4e0d47cf61b8e8c812ca3dc18356fc166fb0 (diff)
downloadpfsense-e92e83d4e2e3465bca9ca6d3cc4f746ef6566476.zip
pfsense-e92e83d4e2e3465bca9ca6d3cc4f746ef6566476.tar.gz
Add the ability for full installs to optionally use RAM disks for /tmp and /var, and to allow selecting a size for /tmp and /var RAM disks on both Full installs and NanoBSD.
I think I caught most of the edge cases for transitioning into and out of RAM disk mode, and preserving data across reboots as is done on NanoBSD (RRD, DHCP leases, pkg/pbi info).
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/rrd.inc8
-rw-r--r--etc/inc/services.inc22
-rwxr-xr-xetc/rc35
-rwxr-xr-xetc/rc.embedded30
-rwxr-xr-xetc/rc.reboot8
-rwxr-xr-xetc/rc.shutdown8
6 files changed, 65 insertions, 46 deletions
diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc
index 6f44396..2566b8d 100644
--- a/etc/inc/rrd.inc
+++ b/etc/inc/rrd.inc
@@ -78,6 +78,10 @@ function restore_rrd() {
}
unlink($xml_file);
}
+ /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */
+ if (($g['platform'] == "pfSense") && !isset($config['system']['use_mfs_tmpvar'])) {
+ unlink_if_exists("{$g['cf_conf_path']}/rrd.tgz");
+ }
return true;
}
return false;
@@ -270,9 +274,7 @@ function enable_rrd_graphing() {
chown($rrddbpath, "nobody");
if ($g['booting']) {
- if ($g['platform'] != "pfSense") {
- restore_rrd();
- }
+ restore_rrd();
}
/* db update script */
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index 03325cd..81d2ee6 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -358,18 +358,20 @@ function services_dhcpdv4_configure() {
$is_olsr_enabled = true;
if ($g['booting']) {
- if ($g['platform'] != "pfSense") {
- /* restore the leases, if we have them */
- if (file_exists("{$g['cf_conf_path']}/dhcpleases.tgz")) {
- $dhcprestore = "";
- $dhcpreturn = "";
- exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcpleases.tgz 2>&1", $dhcprestore, $dhcpreturn);
- $dhcprestore = implode(" ", $dhcprestore);
- if($dhcpreturn <> 0) {
- log_error(sprintf(gettext('DHCP leases restore failed exited with %1$s, the error is: %2$s%3$s'), $dhcpreturn, $dhcprestore, "\n"));
- }
+ /* restore the leases, if we have them */
+ if (file_exists("{$g['cf_conf_path']}/dhcpleases.tgz")) {
+ $dhcprestore = "";
+ $dhcpreturn = "";
+ exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcpleases.tgz 2>&1", $dhcprestore, $dhcpreturn);
+ $dhcprestore = implode(" ", $dhcprestore);
+ if($dhcpreturn <> 0) {
+ log_error(sprintf(gettext('DHCP leases restore failed exited with %1$s, the error is: %2$s%3$s'), $dhcpreturn, $dhcprestore, "\n"));
}
}
+ /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */
+ if (($g['platform'] == "pfSense") && !isset($config['system']['use_mfs_tmpvar'])) {
+ unlink_if_exists("{$g['cf_conf_path']}/dhcpleases.tgz");
+ }
}
$syscfg = $config['system'];
diff --git a/etc/rc b/etc/rc
index 73674ea..9b049f1 100755
--- a/etc/rc
+++ b/etc/rc
@@ -73,27 +73,22 @@ if [ "$PLATFORM" = "pfSense" ]; then
fi
fi
-if [ "$PLATFORM" = "cdrom" ]; then
+if [ "${PLATFORM}" = "cdrom" ]; then
/etc/rc.cdrom
-fi
-
-if [ "$PLATFORM" = "embedded" ]; then
- export PKG_TMPDIR=/root/
- /etc/rc.embedded
-fi
-
-if [ "$PLATFORM" = "nanobsd" ]; then
- export PKG_TMPDIR=/root/
- /etc/rc.embedded
-fi
-
-# Mount /. If it fails run a fsck.
-if [ ! "$PLATFORM" = "cdrom" ] ; then
+else
+ # Mount /. If it fails run a fsck.
if [ "$PLATFORM" = "nanobsd" ]; then
+ export PKG_TMPDIR=/root/
/sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /)
else
/sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a)
fi
+
+ USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
+ if [ "${PLATFORM}" = "nanobsd" ] || [ "${PLATFORM}" = "embedded" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
+ /etc/rc.embedded
+ fi
+
# If /conf is a directory, convert it to a symlink to /cf/conf
if [ -d "/conf" ]; then
# If item is not a symlink then rm and recreate
@@ -165,7 +160,7 @@ if [ "$PLATFORM" = "cdrom" ] ; then
# do nothing for cdrom platform
elif [ "$PLATFORM" = "embedded" ] ; then
# do nothing for embedded platform
-elif [ "$PLATFORM" = "nanobsd" ] ; then
+elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
# Ensure that old-style PKG packages can be persistent across reboots
/bin/mkdir -p /root/var/db/pkg
/bin/rm -rf /var/db/pkg
@@ -180,6 +175,14 @@ else
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
/sbin/swapon -a 2>/dev/null >/dev/null
/etc/rc.savecore
+
+ if [ -d /root/var/db/pkg ]; then
+ # User must have just disabled RAM disks, move these back into place.
+ /bin/mkdir -p /var/db/pkg
+ /bin/mv /root/var/db/pkg /var/db/pkg
+ /bin/mkdir -p /var/db/pbi
+ /bin/mv /root/var/db/pkg /var/db/pbi
+ fi
fi
if [ "$PLATFORM" = "cdrom" ] ; then
diff --git a/etc/rc.embedded b/etc/rc.embedded
index ada4558..426495f 100755
--- a/etc/rc.embedded
+++ b/etc/rc.embedded
@@ -4,27 +4,27 @@
# For pfSense
# Size of /tmp
-tmpsize="40m"
+USE_MFS_TMP_SIZE=`/usr/bin/grep use_mfs_tmp_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'`
+if [ ${USE_MFS_TMP_SIZE} -gt 0 ]; then
+ tmpsize="${USE_MFS_TMP_SIZE}m"
+else
+ tmpsize="40m"
+fi
# Size of /var
-varsize="60m"
+USE_MFS_VAR_SIZE=`/usr/bin/grep use_mfs_var_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'`
+if [ ${USE_MFS_VAR_SIZE} -gt 0 ]; then
+ varsize="${USE_MFS_VAR_SIZE}m"
+else
+ varsize="60m"
+fi
# Run some initialization routines
[ -f /etc/rc.d/uzip ] && /etc/rc.d/uzip start
-echo -n "Setting up embedded specific environment..."
-# Initialize MFS for /tmp. Partly taken from /etc/rc.d/var
-if (/bin/mkdir -p /tmp/.diskless 2> /dev/null); then
- rmdir /tmp/.diskless
-else
- mdmfs -S -M -s ${tmpsize} md /tmp
-fi
-# Initialize MFS for /var. Partly taken from /etc/rc.d/var
-if (/bin/mkdir -p /var/.diskless 2> /dev/null); then
- rmdir /var/.diskless
-else
- mdmfs -S -M -s ${varsize} md /var
-fi
+echo -n "Setting up memory disks..."
+mdmfs -S -M -s ${tmpsize} md /tmp
+mdmfs -S -M -s ${varsize} md /var
# Create some needed directories
/bin/mkdir -p /var/db
diff --git a/etc/rc.reboot b/etc/rc.reboot
index 4bb28a1..afdc93c 100755
--- a/etc/rc.reboot
+++ b/etc/rc.reboot
@@ -14,7 +14,13 @@ sleep 1
PLATFORM=`cat /etc/platform`
if [ "$PLATFORM" = "pfSense" ]; then
rm -rf /tmp/*
-else
+fi
+
+USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
+DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'`
+DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2`
+# If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot...
+if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then
/etc/rc.backup_rrd.sh
/etc/rc.backup_dhcpleases.sh
fi
diff --git a/etc/rc.shutdown b/etc/rc.shutdown
index c7e8b25..c63e5e5 100755
--- a/etc/rc.shutdown
+++ b/etc/rc.shutdown
@@ -25,7 +25,13 @@ export PATH
PLATFORM=`cat /etc/platform`
if [ "$PLATFORM" = "pfSense" ]; then
find -x /tmp/* -type f -exec rm -f {} \;
-else
+fi
+
+USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
+DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'`
+DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2`
+# If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot...
+if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then
/etc/rc.backup_rrd.sh
/etc/rc.backup_dhcpleases.sh
fi
OpenPOWER on IntegriCloud