Menu

[r402]: / trunk / www / disks_init.php  Maximize  Restore  History

Download this file

341 lines (304 with data), 12.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/local/bin/php
<?php
/*
disks_init.php
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2007 Olivier Cochard-Labbé <olivier@freenas.org>.
All rights reserved.
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
All rights reserved.
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 ``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 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.
*/
require("guiconfig.inc");
$pgtitle = array(gettext("Disks"),gettext("Initialize"));
if (!is_array($config['disks']['disk']))
$config['disks']['disk'] = array();
disks_sort();
if (!is_array($config['gconcat']['vdisk']))
$config['gconcat']['vdisk'] = array();
gconcat_sort();
if (!is_array($config['gmirror']['vdisk']))
$config['gmirror']['vdisk'] = array();
gmirror_sort();
if (!is_array($config['graid5']['vdisk']))
$config['graid5']['vdisk'] = array();
graid5_sort();
if (!is_array($config['gstripe']['vdisk']))
$config['gstripe']['vdisk'] = array();
gstripe_sort();
if (!is_array($config['gvinum']['vdisk']))
$config['gvinum']['vdisk'] = array();
gvinum_sort();
/* Get all fstype supported by FreeNAS. */
$a_fst = get_fstype_list();
// Remove NTFS: can't format on NTFS under FreeNAS
unset($a_fst['ntfs']);
// Remove cd9660: can't format a CD/DVD !
unset($a_fst['cd9660']);
// Remove the first blank line 'unknown'
$a_fst = array_slice($a_fst, 1);
/* Get disk configurations. */
$a_disk = &$config['disks']['disk'];
$a_gconcat = &$config['gconcat']['vdisk'];
$a_gmirror = &$config['gmirror']['vdisk'];
$a_gstripe = &$config['gstripe']['vdisk'];
$a_graid5 = &$config['graid5']['vdisk'];
$a_gvinum = &$config['gvinum']['vdisk'];
$a_alldisk = array_merge($a_disk,$a_gconcat,$a_gmirror,$a_gstripe,$a_graid5,$a_gvinum);
if ($_POST) {
unset($input_errors);
unset($errormsg);
unset($do_format);
/* input validation */
$reqdfields = explode(" ", "disk type");
$reqdfieldsn = array(gettext("Disk"),gettext("Type"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
if (!$input_errors) {
$do_format = true;
$disk = $_POST['disk'];
$type = $_POST['type'];
$notinitmbr= $_POST['notinitmbr'];
/* Check if disk is mounted. */
if(disks_check_mount_fullname($disk)) {
$errormsg = sprintf( gettext("The disk is currently mounted! <a href=%s>Unmount</a> this disk first before proceeding."), "disks_mount_tools.php?disk={$disk}&action=umount");
$do_format = false;
}
if ($do_format) {
/* Get the id of the disk array entry. */
$NotFound = 1;
$id = array_search_ex($disk, $a_disk, "fullname");
/* disk */
if ($id !== false) {
/* Set new filesystem type. */
$a_disk[$id]['fstype'] = $type;
$NotFound = 0;
} else {
$id = array_search_ex($disk, $a_gmirror, "fullname");
}
/* gmirror */
if (($id !== false) && $NotFound) {
/* Set new filesystem type. */
$a_gmirror[$id]['fstype'] = $type;
$NotFound = 0;
} else {
$id = array_search_ex($disk, $a_gstripe, "fullname");
}
/* gstripe */
if (($id !== false) && $NotFound) {
/* Set new filesystem type. */
$a_gstripe[$id]['fstype'] = $type;
$NotFound = 0;
} else {
$id = array_search_ex($disk, $a_gconcat, "fullname");
}
/* gconcat */
if (($id !== false) && $NotFound) {
/* Set new filesystem type. */
$a_gconcat[$id]['fstype'] = $type;
$NotFound = 0;
} else {
$id = array_search_ex($disk, $a_graid5, "fullname");
}
/* graid5 */
if (($id !== false) && $NotFound) {
/* Set new filesystem type. */
$a_graid5[$id]['fstype'] = $type;
$NotFound = 0;
} else {
$id = array_search_ex($disk, $a_gvinum, "fullname");
}
/* gvinum */
if (($id !== false) && $NotFound) {
/* Set new filesystem type. */
$a_gvinum[$id]['fstype'] = $type;
$NotFound = 0;
}
write_config();
}
}
}
if (!isset($do_format)) {
$do_format = false;
$disk = '';
$type = '';
}
?>
<?php include("fbegin.inc"); ?>
<script language="JavaScript">
<!--
function disk_change() {
switch(document.iform.disk.value)
{
<?php foreach ($a_alldisk as $diskv): ?>
case "<?=$diskv['fullname'];?>":
<?php $i = 0;?>
<?php foreach ($a_fst as $fstval => $fstname): ?>
document.iform.type.options[<?=$i++;?>].selected = <?php if($diskv['fstype'] == $fstval){echo "true";}else{echo "false";};?>;
<?php endforeach; ?>
break;
<?php endforeach; ?>
}
}
// -->
</script>
<?php if($input_errors) print_input_errors($input_errors);?>
<?php if($errormsg) print_error_box($errormsg);?>
<form action="disks_init.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td valign="top" class="vncellreq"><?=gettext("Disk"); ?></td>
<td class="vtable">
<select name="disk" class="formfld" id="disk" onchange="disk_change()">
<?php foreach ($a_alldisk as $diskv): ?>
<?php if (strcmp($diskv['size'],"NA") == 0) continue; ?>
<option value="<?=$diskv['fullname'];?>" <?php if ($diskv['name'] == $disk) echo "selected";?>><?php echo htmlspecialchars($diskv['name'] . ": " .$diskv['size'] . " (" . $diskv['desc'] . ")");?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<td valign="top" class="vncellreq"><?=gettext("File system"); ?></td>
<td class="vtable">
<select name="type" class="formfld" id="type">
<?php foreach ($a_fst as $fstval => $fstname): ?>
<option value="<?=$fstval;?>" <?php if($type == $fstval) echo 'selected';?>><?=htmlspecialchars($fstname);?></option>
<?php endforeach; ?>
</select>
</td>
<tr>
<td width="22%" valign="top" class="vncell"><strong><?=gettext("Don't Erase MBR"); ?><strong></td>
<td width="78%" class="vtable">
<input name="notinitmbr" id="notinitmbr" type="checkbox" value="yes" >
<?=gettext("don't erase the MBR (useful for some RAID controller cards)"); ?><br>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Format disk");?>" onclick="return confirm('<?=gettext("Do you really want to format this disk? All data will be lost!");?>')">
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<? if ($do_format)
{
echo(gettext("<strong>Disk initialization details:</strong>"));
echo('<pre>');
ob_end_flush();
// Erase MBR if not checked
if (!$notinitmbr) {
echo "Erasing MBR and all paritions:\n";
system("dd if=/dev/zero of=" . escapeshellarg($disk) . " bs=32k count=640");
}
else
echo "Keeping the MBR and all partitions\n";
switch ($type)
{
case "ufs":
// Initialize disk
echo "Creating one parition:\n";
system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
// Initialise the partition (optional)
echo "Initializing parition:\n";
system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
// Create s1 label
echo "Creating BSD label:\n";
system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
// Create filesystem
echo "Creating Filesystem:\n";
system("/sbin/newfs -U " . escapeshellarg($disk) . "s1");
echo "Done!\n";
break;
case "ufs_no_su":
// Initialize disk
echo "Creating one parition:\n";
system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
// Initialise the partition (optional)
echo "Initializing parition:\n";
system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
// Create s1 label
echo "Creating BSD label:\n";
system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
// Create filesystem
echo "Creating Filesystem:\n";
system("/sbin/newfs -m 0 " . escapeshellarg($disk) . "s1");
echo "Done!\n";
break;
case "ufsgpt":
// Create GPT partition table
echo "Destroying old GTP information:\n";
system("/sbin/gpt destroy " . escapeshellarg($disk));
echo "Creating GPT partition:\n";
system("/sbin/gpt create -f " . escapeshellarg($disk));
system("/sbin/gpt add -t ufs " . escapeshellarg($disk));
// Create filesystem
echo "Creating Filesystem with Soft Updates:\n";
system("/sbin/newfs -U " . escapeshellarg($disk) . "p1");
echo "Done!\n";
break;
case "ufsgpt_no_su":
// Create GPT partition table
echo "Destroying old GTP information:\n";
system("/sbin/gpt destroy " . escapeshellarg($disk));
echo "Creating GPT partition:\n";
system("/sbin/gpt create -f " . escapeshellarg($disk));
system("/sbin/gpt add -t ufs " . escapeshellarg($disk));
// Create filesystem
echo "Creating Filesystem without Soft Updates:\n";
system("/sbin/newfs -m 0 " . escapeshellarg($disk) . "p1");
echo "Done!\n";
break;
case "softraid":
// Initialize disk
system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
// Initialise the partition (optional)
system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
// Delete old gmirror information */
system("/sbin/gmirror clear " . escapeshellarg($disk));
echo "Done!\n";
break;
case "msdos":
// Initialize disk
system("/sbin/fdisk -I -b /boot/mbr " . escapeshellarg($disk));
// Initialise the partition (optional) */
system("/bin/dd if=/dev/zero of=" . escapeshellarg($disk) . "s1 bs=32k count=16");
// Create s1 label
system("/sbin/bsdlabel -w " . escapeshellarg($disk) . "s1 auto");
// Create filesystem
system("/sbin/newfs_msdos -F 32 " . escapeshellarg($disk) . "s1");
echo "Done!\n";
break;
}
echo('</pre>');
}
?>
</td>
</tr>
</table>
</form>
<p><span class="vexpl"><span class="red"><strong><?=gettext("Warning");?>:<br></strong></span><?=gettext("This step will erase all your partition, create partition number 1 and format the hard drive with the file system specified.");?></span></p>
<p><span class="vexpl"><?=gettext("UFS and variants are the NATIVE file format for FreeBSD (the underlying OS of FreeNAS). Attempting to use other file formats such as FAT, FAT32, EXT2, EXT3, or NTFS can result in unpredictable results, file corruption, and loss of data!");?></p>
</td></tr>
</table>
<script language="JavaScript">
<!--
disk_change();
//-->
</script>
<?php include("fend.inc"); ?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.