Commit c77aa994 authored by Franco Fichtner's avatar Franco Fichtner

system: add optional swap file for SSD; closes #1554

(cherry picked from commit 77401d6a)
parent a9e4d414
......@@ -131,6 +131,7 @@
/usr/local/etc/rc.rfc2136
/usr/local/etc/rc.shutdown
/usr/local/etc/rc.sshd
/usr/local/etc/rc.swapon
/usr/local/etc/rc.syshook
/usr/local/etc/rc.syshook.d/05-beep.stop
/usr/local/etc/rc.syshook.d/05-update.early
......
......@@ -203,7 +203,7 @@ rm -f /var/run/nologin
# set up and recover a crash dump before activating swap
/usr/local/etc/rc.crashdump
swapon -a
/usr/local/etc/rc.swapon
# write /var/run/dmesg.boot
/etc/rc.d/dmesg onestart
......
#!/bin/sh
# Copyright (c) 2017 Franco Fichtner <franco@opnsense.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
SWAPUSE=$(grep -c use_swap_file /conf/config.xml)
SWAPFILE=/usr/swap0
SWAPSIZE=2048
SWAPDEV=md98
# auto-configured fstab entries:
swapon -a
# swap file option for SSDs:
if [ "${SWAPUSE}" != "0" ]; then
if [ ! -f ${SWAPFILE} ]; then
dd if=/dev/zero of=${SWAPFILE} bs=1m count=${SWAPSIZE}
chmod 0600 ${SWAPFILE}
fi
if mdconfig -a -t vnode -f ${SWAPFILE} -u ${SWAPDEV}; then
swapon /dev/${SWAPDEV}
fi
else
rm -f ${SWAPFILE}
fi
......@@ -82,6 +82,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
/* if the old use_mfs_tmpvar is found, set these flags, too */
$pconfig['use_mfs_var'] = isset($config['system']['use_mfs_tmpvar']) || isset($config['system']['use_mfs_var']);
$pconfig['use_mfs_tmp'] = isset($config['system']['use_mfs_tmpvar']) || isset($config['system']['use_mfs_tmp']);
$pconfig['use_swap_file'] = isset($config['system']['use_swap_file']);
$pconfig['rrdbackup'] = !empty($config['system']['rrdbackup']) ? $config['system']['rrdbackup'] : null;
$pconfig['dhcpbackup'] = !empty($config['system']['dhcpbackup']) ? $config['system']['dhcpbackup'] : null;
$pconfig['netflowbackup'] = !empty($config['system']['netflowbackup']) ? $config['system']['netflowbackup'] : null;
......@@ -157,6 +158,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($config['system']['use_mfs_tmp']);
}
if (!empty($pconfig['use_swap_file'])) {
/* set explicit value here in case we want to make it flexible */
$config['system']['use_swap_file'] = 2048;
} elseif (isset($config['system']['use_swap_file'])) {
unset($config['system']['use_swap_file']);
}
if (!empty($pconfig['rrdbackup'])) {
$config['system']['rrdbackup'] = $pconfig['rrdbackup'];
} elseif (isset($config['system']['rrdbackup'])) {
......@@ -390,7 +398,7 @@ include("head.inc");
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('On AC Power Mode') ?></td>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('On AC Power Mode') ?></td>
<td>
<select name="powerd_ac_mode" class="selectpicker" data-style="btn-default" data-width="auto">
<option value="hadp" <?=$pconfig['powerd_ac_mode']=="hadp" ? "selected=\"selected\"" : "";?>>
......@@ -408,7 +416,7 @@ include("head.inc");
</select>
</td>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('On Battery Power Mode') ?></td>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('On Battery Power Mode') ?></td>
<td>
<select name="powerd_battery_mode" class="selectpicker" data-style="btn-default" data-width="auto">
<option value="hadp"<?=$pconfig['powerd_battery_mode']=="hadp" ? "selected=\"selected\"" : "";?>>
......@@ -427,7 +435,7 @@ include("head.inc");
</td>
</tr>
<tr>
<td><a id="help_for_powerd_normal_mode" href="#" class="showhelp"><i class="fa fa-info-circle text-circle"></i></a> <?=gettext('On Normal Power Mode'); ?></td>
<td><a id="help_for_powerd_normal_mode" href="#" class="showhelp"><i class="fa fa-info-circle text-circle"></i></a> <?=gettext('On Normal Power Mode'); ?></td>
<td>
<select name="powerd_normal_mode" class="selectpicker" data-style="btn-default" data-width="auto">
<option value="hadp"<?=$pconfig['powerd_normal_mode']=="hadp" ? "selected=\"selected\"" : "";?>>
......@@ -449,7 +457,14 @@ include("head.inc");
</td>
</tr>
<tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("RAM Disk Settings (Reboot to Apply Changes)"); ?></th>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Disk / Memory Settings (reboot to apply changes)"); ?></th>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Swap file'); ?></td>
<td>
<input name="use_swap_file" type="checkbox" id="use_swap_file" value="yes" <?=!empty($pconfig['use_swap_file']) ? 'checked="checked"' : '';?>/>
<strong><?= gettext('Add a 2 GB swap file to the system') ?></strong>
</td>
</tr>
<tr>
<td><a id="help_for_use_mfs_var" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('/var RAM disk'); ?></td>
......
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