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).
This commit is contained in:
jim-p 2013-03-11 22:16:18 -04:00
parent 94ca4e0d47
commit e92e83d4e2
8 changed files with 170 additions and 88 deletions

View File

@ -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 */

View File

@ -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'];

35
etc/rc
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -99,15 +99,6 @@ EOF;
nanobsd_detect_slice_info();
}
if (isset($_POST['rrdbackup'])) {
$config['system']['rrdbackup'] = $_POST['rrdbackup'];
install_cron_job("/etc/rc.backup_rrd.sh", ($config['system']['rrdbackup'] > 0), $minute="0", "*/{$config['system']['rrdbackup']}");
}
if (isset($_POST['dhcpbackup'])) {
$config['system']['dhcpbackup'] = $_POST['dhcpbackup'];
install_cron_job("/etc/rc.backup_dhcpleases.sh", ($config['system']['dhcpbackup'] > 0), $minute="0", "*/{$config['system']['dhcpbackup']}");
}
if ($_POST['changero']) {
if (is_writable("/")) {
conf_mount_ro();
@ -240,42 +231,11 @@ if ($savemsg)
<td colspan="2" valign="top" class="listtopic"><?=gettext("Periodic Data Backup");?></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("RRD Backup");?></td>
<td width="22%" valign="top" class="vncell"><?=gettext("RRD/DHCP Backup");?></td>
<td width="78%" class="vtable">
<form action="diag_nanobsd.php" method="post" name="iform">
<?=gettext("Frequency:");?>
<select name='rrdbackup'>
<option value='0' <?php if (!isset($config['system']['rrdbackup']) || ($config['system']['rrdbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
<?php for ($x=1; $x<=24; $x++) { ?>
<option value='<?= $x ?>' <?php if ($config['system']['rrdbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
<?php } ?>
</select>
<br/>
<?=gettext("This will periodically backup the RRD data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
<br/>
<br/>
<?=gettext("These options have been relocated to");?> <a href="system_advanced_misc.php"><?=gettext("System > Advanced, Miscellaneous tab")?></a>.
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("DHCP Leases Backup");?></td>
<td width="78%" class="vtable">
<form action="diag_nanobsd.php" method="post" name="iform">
<?=gettext("Frequency:");?>
<select name='dhcpbackup'>
<option value='0' <?php if (!isset($config['system']['dhcpbackup']) || ($config['system']['dhcpbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
<?php for ($x=1; $x<=24; $x++) { ?>
<option value='<?= $x ?>' <?php if ($config['system']['dhcpbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
<?php } ?>
</select>
<br/>
<?=gettext("This will periodically backup the DHCP leases data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
<br/>
<br/>
</td>
</tr>
<tr>
<td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='<?=gettext("Save"); ?>'></form></td>
</tr>
<?php if(file_exists("/conf/upgrade_log.txt")): ?>
<tr>
<td colspan="2" valign="top" class="">&nbsp;</td>

View File

@ -68,6 +68,9 @@ $pconfig['crypto_hardware'] = $config['system']['crypto_hardware'];
$pconfig['thermal_hardware'] = $config['system']['thermal_hardware'];
$pconfig['schedule_states'] = isset($config['system']['schedule_states']);
$pconfig['kill_states'] = isset($config['system']['kill_states']);
$pconfig['use_mfs_tmpvar'] = isset($config['system']['use_mfs_tmpvar']);
$pconfig['use_mfs_tmp_size'] = $config['system']['use_mfs_tmp_size'];
$pconfig['use_mfs_var_size'] = $config['system']['use_mfs_var_size'];
$pconfig['powerd_ac_mode'] = "hadp";
if (!empty($config['system']['powerd_ac_mode']))
@ -97,6 +100,12 @@ if ($_POST) {
if (!empty($_POST['thermal_hardware']) && !array_key_exists($_POST['thermal_hardware'], $thermal_hardware_modules))
$input_errors[] = gettext("Please select a valid Thermal Hardware Sensor.");
if (!empty($_POST['use_mfs_tmp_size']) && !is_numeric($_POST['use_mfs_tmp_size']) && ($_POST['use_mfs_tmp_size'] <= 40))
$input_errors[] = gettext("/tmp Size should not be less than 40MB.");
if (!empty($_POST['use_mfs_var_size']) && !is_numeric($_POST['use_mfs_var_size']) && ($_POST['use_mfs_var_size'] <= 60))
$input_errors[] = gettext("/var Size should not be less than 60MB.");
if (!$input_errors) {
if($_POST['harddiskstandby'] <> "") {
@ -198,6 +207,23 @@ if ($_POST) {
else
unset($config['system']['kill_states']);
if($_POST['use_mfs_tmpvar'] == "yes")
$config['system']['use_mfs_tmpvar'] = true;
else
unset($config['system']['use_mfs_tmpvar']);
$config['system']['use_mfs_tmp_size'] = $_POST['use_mfs_tmp_size'];
$config['system']['use_mfs_var_size'] = $_POST['use_mfs_var_size'];
if (isset($_POST['rrdbackup'])) {
$config['system']['rrdbackup'] = $_POST['rrdbackup'];
install_cron_job("/etc/rc.backup_rrd.sh", ($config['system']['rrdbackup'] > 0), $minute="0", "*/{$config['system']['rrdbackup']}");
}
if (isset($_POST['dhcpbackup'])) {
$config['system']['dhcpbackup'] = $_POST['dhcpbackup'];
install_cron_job("/etc/rc.backup_dhcpleases.sh", ($config['system']['dhcpbackup'] > 0), $minute="0", "*/{$config['system']['dhcpbackup']}");
}
write_config();
$retval = 0;
@ -246,6 +272,19 @@ function maxmss_checked(obj) {
else
jQuery('#maxmss').attr('disabled','true');
}
function tmpvar_checked(obj) {
if (obj.checked) {
jQuery('#use_mfs_tmp_size').attr('disabled',false);
jQuery('#use_mfs_var_size').attr('disabled',false);
jQuery('#rrdbackup').attr('disabled',false);
jQuery('#dhcpbackup').attr('disabled',false);
} else {
jQuery('#use_mfs_tmp_size').attr('disabled','true');
jQuery('#use_mfs_var_size').attr('disabled','true');
jQuery('#rrdbackup').attr('disabled','true');
jQuery('#dhcpbackup').attr('disabled','true');
}
}
//]]>
</script>
<form action="system_advanced_misc.php" method="post" name="iform" id="iform">
@ -509,6 +548,70 @@ function maxmss_checked(obj) {
"This option overrides that behavior by not clearing states for existing connections."); ?>
</td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("RAM Disks"); ?></td>
</tr>
<?php if ($g['platform'] == "pfSense"): ?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Use RAM Disks"); ?></td>
<td width="78%" class="vtable">
<input name="use_mfs_tmpvar" type="checkbox" id="use_mfs_tmpvar" value="yes" <?php if ($pconfig['use_mfs_tmpvar']) echo "checked=\"checked\""; ?> onclick="tmpvar_checked(this)" />
<strong><?=gettext("Use memory file system for /tmp and /var"); ?></strong><br/>
<?=gettext("Set this if you wish to use /tmp and /var as RAM disks (memory file system disks) on a full install " .
"rather than use the hard disk. Setting this will cause the data in /tmp and /var to be lost at reboot, including log data. RRD and DHCP Leases will be retained."); ?>
</td>
</tr>
<?php endif; ?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("/tmp RAM Disk Size"); ?></td>
<td width="78%" class="vtable">
<input name="use_mfs_tmp_size" id="use_mfs_tmp_size" value="<?php if ($pconfig['use_mfs_tmp_size'] <> "") echo $pconfig['use_mfs_tmp_size']; ?>" class="formfld unknown" <?php if (($g['platform'] == "pfSense") && ($pconfig['use_mfs_tmpvar'] == false)) echo "disabled=\"disabled\""; ?> /> MB
<br />
<?=gettext("Set the size, in MB, for the /tmp RAM disk. " .
"Leave blank for 40MB. Do not set lower than 40."); ?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("/var RAM Disk Size"); ?></td>
<td width="78%" class="vtable">
<input name="use_mfs_var_size" id="use_mfs_var_size" value="<?php if ($pconfig['use_mfs_var_size'] <> "") echo $pconfig['use_mfs_var_size']; ?>" class="formfld unknown" <?php if (($g['platform'] == "pfSense") && ($pconfig['use_mfs_tmpvar'] == false)) echo "disabled=\"disabled\""; ?> /> MB
<br />
<?=gettext("Set the size, in MB, for the /var RAM disk. " .
"Leave blank for 60MB. Do not set lower than 60."); ?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Periodic RRD Backup");?></td>
<td width="78%" class="vtable">
<?=gettext("Frequency:");?>
<select name="rrdbackup" id="rrdbackup" <?php if (($g['platform'] == "pfSense") && ($pconfig['use_mfs_tmpvar'] == false)) echo "disabled=\"disabled\""; ?> >
<option value='0' <?php if (!isset($config['system']['rrdbackup']) || ($config['system']['rrdbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
<?php for ($x=1; $x<=24; $x++) { ?>
<option value='<?= $x ?>' <?php if ($config['system']['rrdbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
<?php } ?>
</select>
<br/>
<?=gettext("This will periodically backup the RRD data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
<br/>
<br/>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Periodic DHCP Leases Backup");?></td>
<td width="78%" class="vtable">
<?=gettext("Frequency:");?>
<select name="dhcpbackup" id="dhcpbackup" <?php if (($g['platform'] == "pfSense") && ($pconfig['use_mfs_tmpvar'] == false)) echo "disabled=\"disabled\""; ?> >
<option value='0' <?php if (!isset($config['system']['dhcpbackup']) || ($config['system']['dhcpbackup'] == 0)) echo "selected"; ?>><?=gettext("Disable"); ?></option>
<?php for ($x=1; $x<=24; $x++) { ?>
<option value='<?= $x ?>' <?php if ($config['system']['dhcpbackup'] == $x) echo "selected"; ?>><?= $x ?> <?=gettext("hour"); ?><?php if ($x>1) echo "s"; ?></option>
<?php } ?>
</select>
<br/>
<?=gettext("This will periodically backup the DHCP leases data so it can be restored automatically on the next boot. Keep in mind that the more frequent the backup, the more writes will happen to your media.");?>
<br/>
<br/>
</td>
</tr>
<tr>
<td colspan="2" class="list" height="12">&nbsp;</td>
</tr>