prep 13 KB

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