]> git.lizzy.rs Git - plan9front.git/blob - sys/man/8/prep
33773c96bef88334979e4517334f0581d1da9604
[plan9front.git] / sys / man / 8 / prep
1 .TH PREP 8
2 .SH NAME
3 prep, fdisk, format, mbr \- prepare disks, floppies and flashes
4 .SH SYNOPSIS
5 .B disk/prep
6 [
7 .B -bcfnprw
8 ]
9 [
10 .B -a
11 .I name
12 ]...
13 [
14 .B -s
15 .I sectorsize
16 ]
17 .I plan9partition
18 .PP
19 .B disk/fdisk
20 [
21 .B -abfprw
22 ]
23 [
24 .B -s
25 .I sectorsize
26 ]
27 .I disk
28 .PP
29 .B disk/format
30 [
31 .B -dfvx
32 ]
33 [
34 .B -b
35 .I bootblock
36 ]
37 [
38 .B -c
39 .I csize
40 ]
41 [
42 .B -l
43 .I label
44 ]
45 [
46 .B -r
47 .I nresrv
48 ]
49 [
50 .B -t
51 .I type
52 ]
53 .I disk
54 [
55 .IR file ...
56 ]
57 .PP
58 .B disk/mbr
59 [
60 .B -9
61 ]
62 [
63 .B -m
64 .I mbrfile
65 ]
66 .I disk
67 .SH DESCRIPTION
68 A partition table is stored on a hard disk to specify the division of
69 the physical disk into a set of logical units.
70 On PCs, the partition table is stored at the end of the master boot record
71 of the disk.
72 Partitions of type
73 .B 0x39
74 are Plan 9 partitions.
75 The names of PC partitions are chosen by convention from the type:
76 .BR dos ,
77 .BR plan9 ,
78 etc.
79 Second and subsequent partitions of the same type on a given disk are given
80 unique names by appending a number (or a period and a number if the name
81 already ends in a number).
82 .PP
83 Plan 9 partitions (and Plan 9 disks on non-PCs) are
84 themselves divided, using a textual partition table, called the Plan 9 partition table, in the second
85 sector of the partition (the first is left for architecture-specific boot data, such as PC boot blocks).
86 The table is a sequence of lines of the format
87 .BI part " name start end" \fR,
88 where
89 .I start
90 and
91 .I end
92 name the starting and ending sector.
93 Sector 0 is the first sector of the Plan 9 partition or disk,
94 regardless of its position in a larger disk.
95 Partition extents do not contain the ending sector,
96 so a partition from 0 to 5 and a partition from 5 to 10
97 do not overlap.
98 .PP
99 The Plan 9 partition often contains a number of
100 conventionally named subpartitions.
101 They include:
102 .TF arenas
103 .TP
104 .B 9fat
105 A small FAT file system used to hold
106 configuration information
107 (such as
108 .B plan9.ini
109 and
110 .BR plan9.nvr )
111 and kernels.
112 This typically begins in the first sector
113 of the partition, and contains the partition
114 table as a ``reserved'' sector.
115 See the discussion of the
116 .B -r
117 option to
118 .IR format .
119 .TP
120 .B arenas
121 A
122 .IR venti (8)
123 arenas partition.
124 .TP
125 .B bloom
126 A
127 .IR venti (8)
128 bloom-filter partition.
129 .TP
130 .B cache
131 A
132 .IR cfs (4)
133 file system cache.
134 .TP
135 .B fscache
136 A
137 .IR cwfs (4)
138 worm cache partition.
139 .TP
140 .B fsworm
141 A
142 .IR cwfs (4)
143 worm filesystem.
144 .TP
145 .B fs
146 A
147 .IR kfs (4)
148 file system.
149 .TP
150 .B fscfg
151 A one-sector partition used to store an
152 .IR fs (3)
153 configuration.
154 .TP
155 .B isect
156 A
157 .IR venti (8)
158 index section.
159 .TP
160 .B nvram
161 A one-sector partition used to simulate non-volatile RAM on PCs.
162 .TP
163 .B other
164 A non-archived
165 .IR cwfs (4)
166 file system.
167 .TP
168 .B swap
169 A
170 .IR swap (8)
171 swap partition.
172 .PD
173 .PP
174 .I Fdisk
175 edits the PC partition table and is usually
176 invoked with a disk like
177 .B /dev/sdC0/data
178 as its argument, while
179 .I prep
180 edits the Plan 9 partition table
181 and is usually invoked with a disk partition
182 like
183 .B /dev/sdC0/plan9
184 as its argument.
185 .I Fdisk
186 works in units of disk ``cylinders'': the cylinder
187 size in bytes is printed when
188 .I fdisk
189 starts.
190 .I Prep
191 works in units of disk sectors, which are almost always 512 bytes.
192 .I Fdisk
193 and
194 .I prep
195 share most of their options:
196 .TF -a
197 .PD
198 .TP
199 .B -a
200 Automatically partition the disk.
201 .I Fdisk
202 will create a Plan 9
203 partition in the largest unused area on the disk,
204 doing nothing if a
205 Plan 9 partition already exists.
206 If no other partition on the disk is marked active (i.e. marked as the boot partition),
207 .I fdisk
208 will mark the new partition active.
209 .IR Prep 's
210 .B -a
211 flag takes the name of a partition to create.
212 (See the list above for partition names.)
213 It can be repeated to specify a list of partitions to create.
214 If the disk is currently unpartitioned,
215 .I prep
216 will create the named partitions on the disk,
217 attempting to use the entire disk in a sensible manner.
218 The partition names must be from the list given above.
219 .TP
220 .B -b
221 Start with a blank disk, ignoring any extant partition table.
222 .TP
223 .B -p
224 Print a sequence of commands that when sent to the disk device's
225 .B ctl
226 file
227 will bring the partition
228 table information kept by
229 the
230 .IR sd (3)
231 driver up to date.
232 Then exit.
233 .I Prep
234 will check to see if it is being called with a disk partition
235 (rather than an entire disk) as its argument; if so, it
236 will translate the printed sectors by the partition's offset
237 within the disk.
238 Since
239 .I fdisk
240 operates on a table of unnamed partitions,
241 it assigns names based on the partition type
242 (e.g.,
243 .BR plan9 ,
244 .BR dos ,
245 .BR ntfs ,
246 .BR linux ,
247 .BR linuxswap )
248 and resolves collisions by appending a numbered suffix.
249 (e.g.,
250 .BR dos ,
251 .BR dos.1 ,
252 .BR dos.2 ).
253 .TP
254 .B -r
255 In the absence of the
256 .B -p
257 and
258 .B -w
259 flags,
260 .I prep
261 and
262 .I fdisk
263 enter an interactive partition editor;
264 the
265 .B -r
266 flag runs the editor in read-only mode.
267 .TP
268 .BI -s " sectorsize"
269 Specify the disk's sector size.
270 In the absence of this flag,
271 .I prep
272 and
273 .I fdisk
274 look for a disk
275 .B ctl
276 file and read it to find the disk's sector size.
277 If the
278 .B ctl
279 file cannot be found, a message is printed and
280 a sector size of 512 bytes is assumed.
281 .TP
282 .B -w
283 Write the partition table to the disk and exit.
284 This is useful when used in conjunction with
285 .B -a
286 or
287 .BR -b .
288 .PP
289 If neither the
290 .B -p
291 flag nor the
292 .B -w
293 flag is given,
294 .I prep
295 and
296 .I fdisk
297 enter an interactive partition editor that
298 operates on named partitions.
299 The PC partition table distinguishes between
300 primary partitions, which can be listed in the boot
301 sector at the beginning of the disk,
302 and secondary (or extended) partitions, arbitrarily
303 many of which may be chained together in place
304 of a primary partition.
305 Primary partitions are named
306 .BR p \fIn\fR,
307 secondary partitions
308 .BR s \fIn\fR.
309 The number of primary partitions plus number of contiguous chains of
310 secondary partitions cannot exceed four.
311 .PP
312 The commands are as follows.
313 In the descriptions, read ``sector'' as ``cylinder'' when using
314 .IR fdisk .
315 .TF ".\fI newdot
316 .PD
317 .TP
318 .B "a\fR \fIname\fR [ \fIstart\fR [ \fIend\fR ] ]"
319 Create a partition named
320 .I name
321 starting at sector offset
322 .I start
323 and ending at offset
324 .IR end .
325 The new partition will not be created if
326 it overlaps an extant partition.
327 If
328 .I start
329 or
330 .I end
331 are omitted,
332 .I prep
333 and
334 .I fdisk
335 will prompt for them.
336 In
337 .IR fdisk ,
338 the newly created partition has type
339 .RB `` PLAN9 ;''
340 to set a different type, use the
341 .B t
342 command (q.v.).
343 .I Start
344 and
345 .I end
346 may be expressions using the operators
347 .BR + ,
348 .BR - ,
349 .BR * ,
350 and
351 .BR / ,
352 numeric constants, and the
353 pseudovariables
354 .B .
355 and
356 .BR $ .
357 At the start of the program,
358 .B .
359 is set to zero; each time a partition is
360 created, it is set to the end sector
361 of the new partition.
362 It can also be explicitly set using the
363 .B .
364 command.
365 When evaluating
366 .IR start ,
367 .B $
368 is set to one past the last disk sector.
369 When evaluating
370 .IR end ,
371 .B $
372 is set to the maximum value that
373 .I end
374 can take on without running off the disk
375 or into another partition.
376 Numeric constants followed by
377 .LR k ,
378 .LR m ,
379 .LR g ,
380 or
381 .LR t
382 (or upper-case equivalents)
383 are scaled to the respective size in kilo-, mega-, giga-, or tera-bytes.
384 Finally, the expression
385 .IB n %
386 evaluates to
387 .RI ( n × disksize )/100.
388 As examples,
389 .L "a . .+20%"
390 creates a new partition starting at
391 .B .
392 that takes up a fifth of the disk,
393 .L "a . .+21G"
394 creates a new partition starting at
395 .B .
396 that takes up 21 gigabytes (21×2\u\s-130\s0\d bytes),
397 and
398 .L "a 1000 $"
399 creates a new partition starting at
400 sector 1000 and
401 extending as far as possible.
402 .TP
403 .B ".\fR \fInewdot"
404 Set the value of the variable
405 .B .
406 to
407 .IR newdot ,
408 which is an arithmetic expression as described
409 in the discussion of the
410 .B a
411 command.
412 .TP
413 .BI d " name"
414 Delete the named partition.
415 .TP
416 .B h
417 Print a help message listing command synopses.
418 .TP
419 .B p
420 Print the disk partition table.
421 Unpartitioned regions are also listed.
422 The table consists of a number of lines containing
423 partition name, beginning and ending sectors,
424 and total size.
425 A
426 .B '
427 is prefixed to the names of partitions
428 whose entries have been modified but not written to disk.
429 .I Fdisk
430 adds to the end of each line a textual partition type,
431 and places a
432 .B *
433 next to the name of the active partition
434 (see the
435 .B A
436 command below).
437 .TP
438 .B P
439 Print the partition table in the format accepted by the disk's
440 .B ctl
441 file, which is also the format of the output of the
442 .B -p
443 option.
444 .TP
445 .B w
446 Write the partition table to disk.
447 .I Prep
448 will also inform the kernel of the changed
449 partition table.
450 The write will fail if any programs have any
451 of the disk's partitions open.
452 If the write fails (for this or any other reason),
453 .I prep
454 and
455 .I fdisk
456 will attempt to restore the partition table to
457 its former state.
458 .TP
459 .B q
460 Quit the program.
461 If the partition table has been modified but not written,
462 a warning is printed.
463 Typing
464 .B q
465 again will quit the program.
466 .PP
467 .I Fdisk
468 also has the following commands.
469 .TF "t \fR[\fI type \fR]
470 .PD
471 .TP
472 .BI A " name
473 Set the named partition active.
474 The active partition is the one whose boot block is used
475 when booting a PC from disk.
476 .TP
477 .B e
478 Print the names of empty slots in the partition table, i.e., the
479 valid names to use when creating a new partition.
480 .TP
481 .BI t " \fR[\fI type \fR]
482 Set the partition type.  If it is not given,
483 .I fdisk
484 will display a list of choices and then prompt for it.
485 .PD
486 .PP
487 .I Format
488 prepares for use the floppy diskette or hard disk partition in the file named
489 .IR disk ,
490 for example
491 .B /dev/fd0disk
492 or
493 .BR /dev/sdC0/9fat .
494 The options are:
495 .TP
496 .B -f
497 Do not physically format the disc. Used
498 to install a FAT file system on a
499 previously formatted disc. If
500 .I disk
501 is not a floppy device, this flag is a no-op.
502 .TP
503 .B -t
504 specify a density and type of disk to be prepared.
505 The possible
506 .I types
507 are:
508 .RS
509 .TP
510 .B 3½DD
511 3½" double density, 737280 bytes
512 .TP
513 .B 3½HD
514 3½" high density, 1474560 bytes
515 .TP
516 .B 5¼DD
517 5¼" double density, 368640 bytes
518 .TP
519 .B 5¼HD
520 5¼"  high density, 1146880 bytes
521 .TP
522 .B hard
523 fixed disk
524 .PD
525 .PP
526 The default when
527 .I disk
528 is a floppy drive is the highest possible on the device.
529 When
530 .I disk
531 is a regular file, the default is
532 .BR 3½HD .
533 When
534 .I disk
535 is an
536 .IR sd (3)
537 device, the default is
538 .BR hard .
539 .RE
540 .TP
541 .B -d
542 initialize a FAT file system on the
543 .IR disk .
544 .TP
545 .B -b
546 use the contents of
547 .I bootblock
548 as a bootstrap block
549 to be installed in sector 0.
550 .PD
551 .PP
552 The remaining options have effect only when
553 .B -d
554 is specified:
555 .TP
556 .B -c
557 use a FAT cluster size of
558 .I csize
559 sectors when creating the FAT.
560 .TP
561 .B -l
562 add a
563 .I label
564 when creating the FAT file system.
565 .TP
566 .BI -r
567 mark the first
568 .I nresrv
569 sectors of the partition as ``reserved''.
570 Since the first sector always contains the
571 FAT parameter block, this really marks
572 the
573 .IR nresrv -1
574 sectors starting at sector 1 as ``reserved''.
575 When formatting the
576 .B 9fat
577 partition,
578 .B -r
579 .B 2
580 should be used to jump over the partition table sector.
581 .PD
582 .PP
583 Again under
584 .BR -d ,
585 any
586 .I files
587 listed are added, in order,
588 to the root
589 directory of the FAT file system.  The files are
590 contiguously allocated.
591 .PP
592 .I Format
593 checks for a number of common mistakes; in particular,
594 it will refuse to format a
595 .B 9fat
596 partition unless
597 .B -r
598 is specified with
599 .I nresrv
600 larger than two.
601 It also refuses to format a raw
602 .IR sd (3)
603 partition that begins at offset zero in the disk.
604 (The beginning of the disk should contain an
605 .I fdisk
606 partition table with master boot record,
607 not a FAT file system or boot block.)
608 Both checks are disabled by the
609 .B -x
610 option.
611 The
612 .B -v
613 option prints debugging information.
614 .PP
615 The file
616 .B /386/pbs
617 is an example of a suitable
618 .I bfile
619 to make the disk a boot disk.
620 It gets loaded by the BIOS at 0x7C00,
621 reads the first sector of the
622 root directory into address 0x7E00, and looks for
623 a directory entry named
624 .BR 9BOOTFAT .
625 If it finds such an entry,
626 it uses
627 single sector reads to load the file into address 0x7C00 and then
628 jumps to the loaded file image.
629 .PP
630 .I Mbr
631 installs a new boot block in sector 0 (the master boot record)
632 of a disk such as
633 .BR /dev/sdC0/data .
634 If
635 .I mbrfile
636 contains more than one sector of `boot block',
637 the rest will be copied into the first track of the
638 disk, if it fits.
639 This boot block should not be confused with the
640 boot block used by
641 .IR format ,
642 which goes in sector 0 of a partition.
643 Typically, the boot block in the master boot record
644 scans the PC partition table to find an active
645 partition and then executes the boot block for
646 that partition.
647 The partition boot block then loads a bootstrap
648 program such as
649 .IR 9boot (8),
650 which then loads the operating system.
651 If MS-DOS or Windows 9[58] is already installed
652 on your hard disk, the master boot record
653 already has a suitable boot block.
654 Otherwise,
655 .B /386/mbr
656 is an appropriate
657 .IR mbrfile .
658 It detects and uses LBA addressing when available
659 from the BIOS (the same could not
660 be done in the case of
661 .B pbs
662 due to space considerations).
663 If the
664 .I mbrfile
665 is not specified, a boot block is installed that
666 prints a message explaining that the disk is not bootable.
667 The
668 .B -9
669 option initialises the partition table to consist of one
670 .BR plan9
671 partition which spans the entire disc starting at the end of the
672 first track.
673 .SH EXAMPLES
674 Initialize the kernel disk driver with the partition information
675 from the FAT boot sectors.
676 If Plan 9 partitions exist, pass that partition information as well.
677 .IP
678 .EX
679 for(disk in /dev/sd??) {
680         if(test -f $disk/data && test -f $disk/ctl)
681                 disk/fdisk -p $disk/data >$disk/ctl
682         for(part in $disk/plan9*)
683                 if(test -f $part)
684                         disk/prep -p $part >$disk/ctl
685 }
686 .EE
687 .PP
688 Initialize the blank hard disk
689 .BR /dev/sdC0/data .
690 .IP
691 .EX
692 disk/mbr -m /386/mbr /dev/sdC0/data
693 disk/fdisk -baw /dev/sdC0/data
694 disk/prep -bw -a^(9fat nvram fscache fsworm other swap) /dev/sdC0/plan9
695 disk/format -b /386/pbs -d -r 2 /dev/sdC0/9fat \e
696         /386/9bootfat /386/9pcf /tmp/plan9.ini
697 .EE
698 .SH FILES
699 .TF /386/mbr.bootmgr
700 .TP
701 .B /386/mbr
702 .TP
703 .B /386/mbr.bootmgr
704 self-configuring `smart boot manager'
705 .SH SOURCE
706 .TF /sys/src/cmd/disk/prep
707 .TP
708 .B /sys/src/cmd/disk/prep
709 .TP
710 .B /sys/src/boot/pc
711 .TP
712 .B /n/sources/extra/bootmgr.tgz
713 source for
714 .BR /386/mbr.bootmgr ;
715 compilable on (l)unix
716 .SH SEE ALSO
717 .IR floppy (3),
718 .IR sd (3),
719 .IR usb (4),
720 .IR 9boot (8),
721 .IR partfs (8)
722 .SH BUGS
723 .I Format
724 can create FAT12 and FAT16
725 file systems, but not FAT32 file systems.
726 The boot block can only read from
727 FAT12 and FAT16 file systems.
728 .PP
729 If
730 .L "prep -p"
731 doesn't find a Plan 9 partition table,
732 it will emit commands to delete
733 .I all
734 extant partitions.
735 Similarly,
736 .L "fdisk -p"
737 will delete all partitions,
738 including
739 .LR data ,
740 if there are no partitions defined in the MBR.