prep 13 KB

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