1
0

prep 15 KB

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