summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jim@pingle.org>2010-04-23 12:19:36 -0400
committerjim-p <jim@pingle.org>2010-04-23 12:19:36 -0400
commit2b5f276f8766b7085d8b6ec54b21b6db7554a355 (patch)
treeacd730b4e78ed1f1f01fe082e601449f38675de3
parent08fd5444a92c40b9c248493b8da517ffce0e5445 (diff)
downloadpfsense-2b5f276f8766b7085d8b6ec54b21b6db7554a355.zip
pfsense-2b5f276f8766b7085d8b6ec54b21b6db7554a355.tar.gz
Improve NanoBSD slice updating/changing a bit, add some error checking. Resolves #534.
-rw-r--r--etc/inc/pfsense-utils.inc58
-rw-r--r--etc/rc.nanobsd_switch_boot_slice27
-rwxr-xr-xusr/local/www/diag_nanobsd.php19
3 files changed, 72 insertions, 32 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 6364d37..c6b897c 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1933,12 +1933,18 @@ function nanobsd_get_active_slice() {
function nanobsd_get_size() {
return strtoupper(file_get_contents("/etc/nanosize.txt"));
}
-function nanobsd_set_boot_slice($slice) {
+function nanobsd_switch_boot_slice() {
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
nanobsd_detect_slice_info();
+ if ($BOOTFLASH == $ACTIVE_SLICE) {
+ $slice = $TOFLASH;
+ } else {
+ $slice = $BOOTFLASH;
+ }
+
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
if(strstr($slice, "s2")) {
@@ -1961,20 +1967,15 @@ function nanobsd_set_boot_slice($slice) {
exec("sysctl kern.geom.debugflags=16");
exec("gpart set -a active -i {$ASLICE} {$BOOT_DRIVE}");
exec("/usr/sbin/boot0cfg -s {$ASLICE} -v /dev/{$BOOT_DRIVE}");
- exec("/sbin/tunefs -L ${AGLABEL_SLICE} /dev/$ACOMPLETE_PATH");
- exec("/bin/mkdir /tmp/{$AGLABEL_SLICE}");
- exec("/sbin/fsck_ufs -y /dev/{$ACOMPLETE_PATH}");
- exec("/sbin/mount /dev/ufs/{$AGLABEL_SLICE} /tmp/{$AGLABEL_SLICE}");
- $fstab = <<<EOF
-/dev/ufs/{$AGLABEL_SLICE} / ufs ro 1 1
-/dev/ufs/cf /cf ufs ro 1 1
-EOF;
- file_put_contents("/tmp/{$AGLABEL_SLICE}/etc/fstab", $fstab);
- exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
+ // We can't update these if they are mounted now.
+ if ($BOOTFLASH != $slice) {
+ exec("/sbin/tunefs -L ${AGLABEL_SLICE} /dev/$ACOMPLETE_PATH");
+ nanobsd_update_fstab($AGLABEL_SLICE, $ACOMPLETE_PATH, $AOLD_UFS_ID, $AUFS_ID);
+ }
exec("/sbin/sysctl kern.geom.debugflags=0");
conf_mount_ro();
}
-function nanobsd_clone_slice($dstslice) {
+function nanobsd_clone_slice() {
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
@@ -1986,12 +1987,7 @@ function nanobsd_clone_slice($dstslice) {
exec("/bin/dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
- exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
- exec("/sbin/fsck_ufs -y /dev/{$COMPLETE_PATH}");
- exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
- exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
- $status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
- exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
+ $status = nanobsd_update_fstab($GLABEL_SLICE, $COMPLETE_PATH, $OLD_UFS_ID, $UFS_ID);
exec("/sbin/sysctl kern.geom.debugflags=0");
if($status) {
return false;
@@ -1999,6 +1995,32 @@ function nanobsd_clone_slice($dstslice) {
return true;
}
}
+function nanobsd_update_fstab($gslice, $complete_path, $oldufs, $newufs) {
+ $tmppath = "/tmp/{$gslice}";
+ $fstabpath = "/tmp/{$gslice}/etc/fstab";
+
+ exec("/bin/mkdir {$tmppath}");
+ exec("/sbin/fsck_ufs -y /dev/{$complete_path}");
+ exec("/sbin/mount /dev/ufs/{$gslice} {$tmppath}");
+ exec("/bin/cp /etc/fstab {$fstabpath}");
+
+ if (!file_exists($fstabpath)) {
+ $fstab = <<<EOF
+/dev/ufs/{$gslice} / ufs ro 1 1
+/dev/ufs/cf /cf ufs ro 1 1
+EOF;
+ if (file_put_contents($fstabpath, $fstab))
+ $status = true;
+ else
+ $status = false;
+ } else {
+ $status = exec("sed -i \"\" \"s/pfsense{$oldufs}/pfsense{$newufs}/g\" {$fstabpath}");
+ }
+ exec("/sbin/umount {$tmppath}");
+ exec("/bin/rmdir {$tmppath}");
+
+ return $status;
+}
function nanobsd_detect_slice_info() {
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
diff --git a/etc/rc.nanobsd_switch_boot_slice b/etc/rc.nanobsd_switch_boot_slice
new file mode 100644
index 0000000..ccbed9c
--- /dev/null
+++ b/etc/rc.nanobsd_switch_boot_slice
@@ -0,0 +1,27 @@
+#!/usr/local/bin/php -q
+<?php
+require_once("globals.inc");
+require_once("config.inc");
+require_once("pfsense-utils.inc");
+
+global $g;
+global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
+global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
+global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
+nanobsd_detect_slice_info();
+
+if ($g['platform'] != "nanobsd") {
+ echo "This script can only be used on NanoBSD (embedded) images.\n";
+ exit(1);
+}
+
+echo "Boot slice : {$BOOTFLASH} ({$BOOT_DEVICE})\n";
+echo "Active slice: {$ACTIVE_SLICE}\n\n";
+
+echo "Switching active slice...";
+nanobsd_switch_boot_slice();
+echo "Done.\n\n";
+nanobsd_detect_slice_info();
+echo "Boot slice : {$BOOTFLASH} ({$BOOT_DEVICE})\n";
+echo "Active slice: {$ACTIVE_SLICE}\n\n";
+?> \ No newline at end of file
diff --git a/usr/local/www/diag_nanobsd.php b/usr/local/www/diag_nanobsd.php
index fee325e..3e9bed1 100755
--- a/usr/local/www/diag_nanobsd.php
+++ b/usr/local/www/diag_nanobsd.php
@@ -74,7 +74,7 @@ if($_POST['bootslice']) {
<p/>&nbsp;
</div>
EOF;
- nanobsd_set_boot_slice($_POST['bootslice']);
+ nanobsd_switch_boot_slice();
$savemsg = "The boot slice has been set to " . nanobsd_get_active_slice();
// Survey slice info
nanobsd_detect_slice_info();
@@ -133,23 +133,14 @@ if ($savemsg)
<td width="22%" valign="top" class="vncell">Bootup</td>
<td width="78%" class="vtable">
<form action="diag_nanobsd.php" method="post" name="iform">
- Bootup slice:
- <select name='bootslice'>
- <option value='<?php echo $BOOTFLASH; ?>'<?php if ($BOOTFLASH == $ACTIVE_SLICE) {?> selected<?php } ?>>
- <?php echo $BOOTFLASH; ?>
- </option>
- <option value='<?php echo $TOFLASH; ?>'<?php if ($TOFLASH == $ACTIVE_SLICE) {?> selected<?php } ?>>
- <?php echo $TOFLASH; ?>
- </option>
- </select>
+ Bootup slice is currently: <?php echo $ACTIVE_SLICE; ?>
+ <br/><br/>This will switch the bootup slice to the alternate slice.
<br/>
- This will set the bootup slice.
+ <input type='hidden' name='bootslice' value='switch'>
+ <input type='submit' value='Switch Slice'></form>
</td>
</tr>
<tr>
- <td valign="top" class="">&nbsp;</td><td><br/><input type='submit' value='Set bootup'></form></td>
- </tr>
- <tr>
<td colspan="2" valign="top" class="">&nbsp;</td>
</tr>
<tr>
OpenPOWER on IntegriCloud