prep 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. .TH PREP 8
  2. .SH NAME
  3. prep, fdisk, format, mbr \- prepare disks, floppies and 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. Numeric constants followed by
  368. .LR k ,
  369. .LR m ,
  370. .LR g ,
  371. or
  372. .LR t
  373. (or upper-case equivalents)
  374. are scaled to the respective size in kilo-, mega-, giga-, or tera-bytes.
  375. Finally, the expression
  376. .IB n %
  377. evaluates to
  378. .RI ( n × disksize )/100.
  379. As examples,
  380. .L "a . .+20%"
  381. creates a new partition starting at
  382. .B .
  383. that takes up a fifth of the disk,
  384. .L "a . .+21G"
  385. creates a new partition starting at
  386. .B .
  387. that takes up 21 gigabytes (21×2\u\s-130\s0\d bytes),
  388. and
  389. .L "a 1000 $"
  390. creates a new partition starting at
  391. sector 1000 and
  392. extending as far as possible.
  393. .TP
  394. .B ".\fR \fInewdot"
  395. Set the value of the variable
  396. .B .
  397. to
  398. .IR newdot ,
  399. which is an arithmetic expression as described
  400. in the discussion of the
  401. .B a
  402. command.
  403. .TP
  404. .BI d " name"
  405. Delete the named partition.
  406. .TP
  407. .B h
  408. Print a help message listing command synopses.
  409. .TP
  410. .B p
  411. Print the disk partition table.
  412. Unpartitioned regions are also listed.
  413. The table consists of a number of lines containing
  414. partition name, beginning and ending sectors,
  415. and total size.
  416. A
  417. .B '
  418. is prefixed to the names of partitions
  419. whose entries have been modified but not written to disk.
  420. .I Fdisk
  421. adds to the end of each line a textual partition type,
  422. and places a
  423. .B *
  424. next to the name of the active partition
  425. (see the
  426. .B A
  427. command below).
  428. .TP
  429. .B P
  430. Print the partition table in the format accepted by the disk's
  431. .B ctl
  432. file, which is also the format of the output of the
  433. .B -p
  434. option.
  435. .TP
  436. .B w
  437. Write the partition table to disk.
  438. .I Prep
  439. will also inform the kernel of the changed
  440. partition table.
  441. The write will fail if any programs have any
  442. of the disk's partitions open.
  443. If the write fails (for this or any other reason),
  444. .I prep
  445. and
  446. .I fdisk
  447. will attempt to restore the partition table to
  448. its former state.
  449. .TP
  450. .B q
  451. Quit the program.
  452. If the partition table has been modified but not written,
  453. a warning is printed.
  454. Typing
  455. .B q
  456. again will quit the program.
  457. .PP
  458. .I Fdisk
  459. also has the following commands.
  460. .TP
  461. .BI A " name
  462. Set the named partition active.
  463. The active partition is the one whose boot block is used
  464. when booting a PC from disk.
  465. .TP
  466. .B e
  467. Print the names of empty slots in the partition table, i.e., the
  468. valid names to use when creating a new partition.
  469. .TP
  470. .BI t " \fR[\fI type \fR]
  471. Set the partition type. If it is not given,
  472. .I fdisk
  473. will display a list of choices and then prompt for it.
  474. .PD
  475. .PP
  476. .I Format
  477. prepares for use the floppy diskette or hard disk partition in the file named
  478. .IR disk ,
  479. for example
  480. .B /dev/fd0disk
  481. or
  482. .BR /dev/sdC0/9fat .
  483. The options are:
  484. .TP
  485. .B -f
  486. Do not physically format the disc. Used
  487. to install a FAT file system on a
  488. previously formatted disc. If
  489. .I disk
  490. is not a floppy device, this flag is a no-op.
  491. .TP
  492. .B -t
  493. specify a density and type of disk to be prepared.
  494. The possible
  495. .I types
  496. are:
  497. .RS
  498. .TP
  499. .B 3½DD
  500. 3½" double density, 737280 bytes
  501. .TP
  502. .B 3½HD
  503. 3½" high density, 1474560 bytes
  504. .TP
  505. .B 5¼DD
  506. 5¼" double density, 368640 bytes
  507. .TP
  508. .B 5¼HD
  509. 5¼" high density, 1146880 bytes
  510. .TP
  511. .B hard
  512. fixed disk
  513. .PD
  514. .PP
  515. The default when
  516. .I disk
  517. is a floppy drive is the highest possible on the device.
  518. When
  519. .I disk
  520. is a regular file, the default is
  521. .BR 3½HD .
  522. When
  523. .I disk
  524. is an
  525. .IR sd (3)
  526. device, the default is
  527. .BR hard .
  528. .RE
  529. .TP
  530. .B -d
  531. initialize a FAT file system on the
  532. .IR disk .
  533. .TP
  534. .B -b
  535. use the contents of
  536. .I bootblock
  537. as a bootstrap block
  538. to be installed in sector 0.
  539. .PD
  540. .PP
  541. The remaining options have effect only when
  542. .B -d
  543. is specified:
  544. .TP
  545. .B -c
  546. use a FAT cluster size of
  547. .I csize
  548. sectors when creating the FAT.
  549. .TP
  550. .B -l
  551. add a
  552. .I label
  553. when creating the FAT file system.
  554. .TP
  555. .BI -r
  556. mark the first
  557. .I nresrv
  558. sectors of the partition as ``reserved''.
  559. Since the first sector always contains the
  560. FAT parameter block, this really marks
  561. the
  562. .IR nresrv -1
  563. sectors starting at sector 1 as ``reserved''.
  564. When formatting the
  565. .B 9fat
  566. partition,
  567. .B -r
  568. .B 2
  569. should be used to jump over the partition table sector.
  570. .PD
  571. .PP
  572. Again under
  573. .BR -d ,
  574. any
  575. .I files
  576. listed are added, in order,
  577. to the root
  578. directory of the FAT file system. The files are
  579. contiguously allocated.
  580. If a file is named
  581. .BR 9load ,
  582. it will be created with the
  583. .B SYSTEM
  584. attribute set so that
  585. .IR dossrv (4)
  586. keeps it contiguous when modifying it.
  587. .PP
  588. .I Format
  589. checks for a number of common mistakes; in particular,
  590. it will refuse to format a
  591. .B 9fat
  592. partition unless
  593. .B -r
  594. is specified with
  595. .I nresrv
  596. larger than two.
  597. It also refuses to format a raw
  598. .IR sd (3)
  599. partition that begins at offset zero in the disk.
  600. (The beginning of the disk should contain an
  601. .I fdisk
  602. partition table with master boot record,
  603. not a FAT file system or boot block.)
  604. Both checks are disabled by the
  605. .B -x
  606. option.
  607. The
  608. .B -v
  609. option prints debugging information.
  610. .PP
  611. The file
  612. .B /386/pbs
  613. is an example of a suitable
  614. .I bfile
  615. to make the disk a boot disk.
  616. It gets loaded by the BIOS at 0x7C00,
  617. reads the first sector of the
  618. root directory into address 0x7E00, and looks for
  619. a directory entry named
  620. .BR 9LOAD .
  621. If it finds such an entry,
  622. it uses
  623. single sector reads to load the file into address 0x10000 and then
  624. jumps to the loaded file image.
  625. The file
  626. .B /386/pbslba
  627. is similar, but because it uses LBA addressing (not supported
  628. by older BIOSes), it can access more than the first 8.5GB of the disk.
  629. .PP
  630. .I Mbr
  631. installs a new boot block in sector 0 (the master boot record)
  632. of a disk such as
  633. .BR /dev/sdC0/data .
  634. If
  635. .I mbrfile
  636. contains more than one sector of `boot block',
  637. the rest will be copied into the first track of the
  638. disk, if it fits.
  639. This boot block should not be confused with the
  640. boot block used by
  641. .IR format ,
  642. which goes in sector 0 of a partition.
  643. Typically, the boot block in the master boot record
  644. scans the PC partition table to find an active
  645. partition and then executes the boot block for
  646. that partition.
  647. The partition boot block then loads a bootstrap
  648. program such as
  649. .IR 9load (8),
  650. which then loads the operating system.
  651. If MS-DOS or Windows 9[58] is already installed
  652. on your hard disk, the master boot record
  653. already has a suitable boot block.
  654. Otherwise,
  655. .B /386/mbr
  656. is an appropriate
  657. .IR mbrfile .
  658. It detects and uses LBA addressing when available
  659. from the BIOS (the same could not
  660. be done in the case of
  661. .B pbs
  662. due to space considerations).
  663. If the
  664. .I mbrfile
  665. is not specified, a boot block is installed that
  666. prints a message explaining that the disk is not bootable.
  667. The
  668. .B -9
  669. option initialises the partition table to consist of one
  670. .BR plan9
  671. partition which spans the entire disc starting at the end of the
  672. first track.
  673. .SH EXAMPLES
  674. Initialize the kernel disk driver with the partition information
  675. from the FAT boot sectors.
  676. If Plan 9 partitions exist, pass that partition information as well.
  677. .IP
  678. .EX
  679. for(disk in /dev/sd??) {
  680. if(test -f $disk/data && test -f $disk/ctl)
  681. disk/fdisk -p $disk/data >$disk/ctl
  682. for(part in $disk/plan9*)
  683. if(test -f $part)
  684. disk/prep -p $part >$disk/ctl
  685. }
  686. .EE
  687. .PP
  688. Create a Plan 9 boot floppy on a previously formatted diskette.
  689. .IP
  690. .EX
  691. disk/format -b /386/pbs -df /dev/fd0disk \e
  692. /386/9load /tmp/plan9.ini /386/9pcf.gz
  693. .EE
  694. .PP
  695. Initialize the blank hard disk
  696. .BR /dev/sdC0/data .
  697. .IP
  698. .EX
  699. disk/mbr -m /386/mbr /dev/sdC0/data
  700. disk/fdisk -baw /dev/sdC0/data
  701. disk/prep -bw -a^(9fat nvram fossil cache swap) /dev/sdC0/plan9
  702. disk/format -b /386/pbslba -d -r 2 /dev/sdC0/9fat \e
  703. /386/9load /386/9pcf /tmp/plan9.ini
  704. .EE
  705. .PP
  706. Create a bootable USB disk or flash-memory device to be booted
  707. via the BIOS and containing only a FAT
  708. .I fdisk
  709. partition.
  710. .IP
  711. .EX
  712. mount /srv/usb /n/usb
  713. ls /n/usb/sdU* # note the sdU* number
  714. disk/partfs /n/usb/sdU13.0/data
  715. disk/mbr -m /386/mbr /dev/sdXX/data
  716. disk/fdisk -baw /dev/sdXX/data
  717. disk/fdisk /dev/sdXX/data
  718. # delete p1 and create a new FAT16 p1 of about 100MB,
  719. # and mark it active. write and quit.
  720. disk/format -b /386/pbslba -d -r 2 /dev/sdXX/dos \e
  721. /386/9load /386/9pcf /tmp/plan9.ini
  722. .EE
  723. .SH SOURCE
  724. .B /sys/src/cmd/disk/prep
  725. .br
  726. .B /sys/src/boot/pc
  727. .SH SEE ALSO
  728. .IR floppy (3),
  729. .IR sd (3),
  730. .IR usb (4),
  731. .IR 9load (8),
  732. .IR partfs (8)
  733. .SH BUGS
  734. .I Format
  735. can create FAT12 and FAT16
  736. file systems, but not FAT32 file systems.
  737. The boot block can only read from
  738. FAT12 and FAT16 file systems.
  739. .PP
  740. If
  741. .L "prep -p"
  742. doesn't find a Plan 9 partition table,
  743. it will emit commands to delete
  744. .I all
  745. extant partitions.
  746. Similarly,
  747. .L "fdisk -p"
  748. will delete all partitions,
  749. including
  750. .LR data ,
  751. if there are no partitions defined in the MBR.