prep 14 KB

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