prep 13 KB

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