prep 14 KB

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