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