Project

General

Profile

« Previous | Next » 

Revision 08fd5444

Added by Jim Pingle over 15 years ago

Relocate some NanoBSD functions to a central place. Change NanoBSD diagnostics and system info widget to use the new code. Ticket #533 and some prerequisite parts of Ticket #534.

View differences:

usr/local/www/diag_nanobsd.php
49 49
$pgtitle = array("Diagnostics","NanoBSD");
50 50
include("head.inc");
51 51

  
52
function detect_slice_info() {
53
	global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
54
	global $GLABEL_SLIZE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
55
	global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE;
56

  
57
	$BOOT_DEVICE=trim(`/sbin/mount | /usr/bin/grep pfsense | /usr/bin/cut -d'/' -f4 | /usr/bin/cut -d' ' -f1`);
58
	$REAL_BOOT_DEVICE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/{$BOOT_DEVICE} | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' '`);
59
	$BOOT_DRIVE=trim(`/sbin/glabel list | /usr/bin/grep -B2 ufs/pfsense | /usr/bin/head -n 1 | /usr/bin/cut -f3 -d' ' | /usr/bin/cut -d's' -f1`);
60

  
61
	// Detect which slice is active and set information.
62
	if(strstr($REAL_BOOT_DEVICE, "s1")) {
63
		$SLICE="2";
64
		$OLDSLICE="1";
65
		$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
66
		$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
67
		$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";	
68
		$GLABEL_SLICE="pfsense1";
69
		$UFS_ID="1";
70
		$OLD_UFS_ID="0";
71
		$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
72

  
73
	} else {
74
		$SLICE="1";
75
		$OLDSLICE="2";
76
		$TOFLASH="{$BOOT_DRIVE}s{$SLICE}";
77
		$COMPLETE_PATH="{$BOOT_DRIVE}s{$SLICE}a";
78
		$COMPLETE_BOOT_PATH="{$BOOT_DRIVE}s{$OLDSLICE}";
79
		$GLABEL_SLICE="pfsense0";
80
		$UFS_ID="0";
81
		$OLD_UFS_ID="1";
82
		$BOOTFLASH="{$BOOT_DRIVE}s{$OLDSLICE}";
83
	}
84
}
85

  
86 52
// Survey slice info
87
detect_slice_info();
53
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
54
global $GLABEL_SLICE, $UFS_ID, $OLD_UFS_ID, $BOOTFLASH;
55
global $BOOT_DEVICE, $REAL_BOOT_DEVICE, $BOOT_DRIVE, $ACTIVE_SLICE;
56
nanobsd_detect_slice_info();
88 57

  
89 58
?>
90 59

  
......
95 64

  
96 65
<?php
97 66

  
98
$NANOBSD_SIZE = strtoupper(file_get_contents("/etc/nanosize.txt"));
67
$NANOBSD_SIZE = nanobsd_get_size();
99 68

  
100 69
if($_POST['bootslice']) {
101 70
	echo <<<EOF
......
105 74
			<p/>&nbsp;
106 75
		</div>
107 76
EOF;
108
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
109
	ob_implicit_flush(1);
110
	if(strstr($_POST['bootslice'], "s2")) {
111
		$ASLICE="2";
112
		$AOLDSLICE="1";
113
		$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
114
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
115
		$AGLABEL_SLICE="pfsense1";
116
		$AUFS_ID="1";
117
		$AOLD_UFS_ID="0";
118
		$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
119
	} else {
120
		$ASLICE="1";
121
		$AOLDSLICE="2";
122
		$ATOFLASH="{$BOOT_DRIVE}s{$ASLICE}";
123
		$ACOMPLETE_PATH="{$BOOT_DRIVE}s{$ASLICE}a";
124
		$AGLABEL_SLICE="pfsense0";
125
		$AUFS_ID="0";
126
		$AOLD_UFS_ID="1";
127
		$ABOOTFLASH="{$BOOT_DRIVE}s{$AOLDSLICE}";
128
	}
129
	conf_mount_rw();
130
	exec("sysctl kern.geom.debugflags=16");	
131
	exec("gpart set -a active -i {$ASLICE} {$BOOT_DRIVE}");
132
	exec("/usr/sbin/boot0cfg -s {$ASLICE} -v /dev/{$BOOT_DRIVE}");
133
	exec("/sbin/tunefs -L ${AGLABEL_SLICE} /dev/$ACOMPLETE_PATH");
134
	exec("/bin/mkdir /tmp/{$AGLABEL_SLICE}");
135
	exec("/sbin/fsck_ufs -y /dev/{$ACOMPLETE_PATH}");
136
	exec("/sbin/mount /dev/ufs/{$AGLABEL_SLICE} /tmp/{$AGLABEL_SLICE}");
137
	$fstab = <<<EOF
138
/dev/ufs/{$AGLABEL_SLICE} / ufs ro 1 1
139
/dev/ufs/cf /cf ufs ro 1 1	
140
EOF;
141
	file_put_contents("/tmp/{$AGLABEL_SLICE}/etc/fstab", $fstab);
142
	exec("/sbin/umount /tmp/{$AGLABEL_SLICE}");
143
	exec("/sbin/sysctl kern.geom.debugflags=0");
144
	conf_mount_ro();
145
	$savemsg = "The boot slice has been set to {$BOOT_DRIVE} {$AGLABEL_SLICE}";
77
	nanobsd_set_boot_slice($_POST['bootslice']);
78
	$savemsg = "The boot slice has been set to " . nanobsd_get_active_slice();
146 79
	// Survey slice info
147
	detect_slice_info();
80
	nanobsd_detect_slice_info();
148 81

  
149 82
}
150 83

  
151 84
if($_POST['destslice']) {
152

  
153 85
echo <<<EOF
154 86
 	<div id="loading">
155 87
		<img src="/themes/metallic/images/misc/loader.gif">
......
157 89
		<p/>&nbsp;
158 90
	</div>
159 91
EOF;
160
	for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
161
	ob_implicit_flush(1);
162
	exec("/sbin/sysctl kern.geom.debugflags=16");
163
	exec("/bin/dd if=/dev/zero of=/dev/{$TOFLASH} bs=1m count=1");
164
	exec("/bin/dd if=/dev/{$BOOTFLASH} of=/dev/{$TOFLASH} bs=64k");
165
	exec("/sbin/tunefs -L {$GLABEL_SLICE} /dev/{$COMPLETE_PATH}");
166
	exec("/bin/mkdir /tmp/{$GLABEL_SLICE}");
167
	exec("/sbin/fsck_ufs -y /dev/{$COMPLETE_PATH}");
168
	exec("/sbin/mount /dev/ufs/{$GLABEL_SLICE} /tmp/{$GLABEL_SLICE}");
169
	exec("/bin/cp /etc/fstab /tmp/{$GLABEL_SLICE}/etc/fstab");
170
	$status = exec("sed -i \"\" \"s/pfsense{$OLD_UFS_ID}/pfsense{$UFS_ID}/g\" /tmp/{$GLABEL_SLICE}/etc/fstab");
171
	if($status) {
172
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
173
		$savemsg = "There was an error while duplicating the slice.  Operation aborted.";
174
	} else {
92
	if(nanobsd_clone_slice($_POST['destslice'])) {
175 93
		$savemsg = "The slice has been duplicated.<p/>If you would like to boot from this newly duplicated slice please set it using the bootup information area.";
176
		exec("/sbin/umount /tmp/{$GLABEL_SLICE}");
94
	} else {
95
		$savemsg = "There was an error while duplicating the slice.  Operation aborted.";
177 96
	}
178
	exec("/sbin/sysctl kern.geom.debugflags=0");
179 97
	// Re-Survey slice info
180
	detect_slice_info();
98
	nanobsd_detect_slice_info();
181 99
}
182 100

  
183 101
if ($savemsg)
......
217 135
							<form action="diag_nanobsd.php" method="post" name="iform">
218 136
								Bootup slice:
219 137
								<select name='bootslice'>
220
									<option value='<?php echo $BOOTFLASH; ?>'>
138
									<option value='<?php echo $BOOTFLASH; ?>'<?php if ($BOOTFLASH == $ACTIVE_SLICE) {?> selected<?php } ?>>
221 139
										<?php echo $BOOTFLASH; ?>
222 140
									</option>
223
									<option value='<?php echo $TOFLASH; ?>'>
224
										<?php echo "{$TOFLASH}"; ?>
141
									<option value='<?php echo $TOFLASH; ?>'<?php if ($TOFLASH == $ACTIVE_SLICE) {?> selected<?php } ?>>
142
										<?php echo $TOFLASH; ?>
225 143
									</option>
226 144
								</select>
227 145
								<br/>

Also available in: Unified diff