diff options
author | jim-p <jim@pingle.org> | 2010-04-23 12:19:36 -0400 |
---|---|---|
committer | jim-p <jim@pingle.org> | 2010-04-23 12:19:36 -0400 |
commit | 2b5f276f8766b7085d8b6ec54b21b6db7554a355 (patch) | |
tree | acd730b4e78ed1f1f01fe082e601449f38675de3 /etc/inc | |
parent | 08fd5444a92c40b9c248493b8da517ffce0e5445 (diff) | |
download | pfsense-2b5f276f8766b7085d8b6ec54b21b6db7554a355.zip pfsense-2b5f276f8766b7085d8b6ec54b21b6db7554a355.tar.gz |
Improve NanoBSD slice updating/changing a bit, add some error checking. Resolves #534.
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/pfsense-utils.inc | 58 |
1 files changed, 40 insertions, 18 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; |