prep 14 KB

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