prep 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. .I Start
  300. and
  301. .I end
  302. may be expressions using the operators
  303. .BR + ,
  304. .BR - ,
  305. .BR * ,
  306. and
  307. .BR / ,
  308. numeric constants, and the
  309. pseudovariables
  310. .B .
  311. and
  312. .BR $ .
  313. At the start of the program,
  314. .B .
  315. is set to zero; each time a partition is
  316. created, it is set to the end sector
  317. of the new partition.
  318. It can also be explicitly set using the
  319. .B .
  320. command.
  321. When evaluating
  322. .IR start ,
  323. .B $
  324. is set to one past the last disk sector.
  325. When evaluating
  326. .IR end ,
  327. .B $
  328. is set to the maximum value that
  329. .I end
  330. can take on without running off the disk
  331. or into another partition.
  332. Finally, the expression
  333. .IB n %
  334. evaluates to
  335. .RI ( n × disksize )/100.
  336. As an example,
  337. .B a
  338. .B .
  339. .B .+20%
  340. creates a new partition starting at
  341. .B .
  342. that takes up a fifth of the disk,
  343. and
  344. .B a
  345. .B 1000
  346. .B $
  347. creates a new partition starting at
  348. sector 1000 and
  349. extending as far as possible.
  350. .TP
  351. .B ".\fR \fInewdot"
  352. Set the value of the variable
  353. .B .
  354. to
  355. .IR newdot ,
  356. which is an arithmetic expression as described
  357. in the discussion of the
  358. .B a
  359. command.
  360. .TP
  361. .BI d " name"
  362. Delete the named partition.
  363. .TP
  364. .B h
  365. Print a help message listing command synopses.
  366. .TP
  367. .B p
  368. Print the disk partition table.
  369. Unpartitioned regions are also listed.
  370. The table consists of a number of lines containing
  371. partition name, beginning and ending sectors,
  372. and total size.
  373. A
  374. .B '
  375. is prefixed to the names of partitions
  376. whose entries have been modified but not written to disk.
  377. .I Fdisk
  378. adds to the end of each line a textual partition type,
  379. and places a
  380. .B *
  381. next to the name of the active partition
  382. (see the
  383. .B A
  384. command below).
  385. .TP
  386. .B P
  387. Print the partition table in the format accepted by the disk's
  388. .B ctl
  389. file, which is also the format of the output of the
  390. .B -p
  391. option.
  392. .TP
  393. .B w
  394. Write the partition table to disk.
  395. .I Prep
  396. will also inform the kernel of the changed
  397. partition table.
  398. The write will fail if any programs have any
  399. of the disk's partitions open.
  400. If the write fails (for this or any other reason),
  401. .I prep
  402. and
  403. .I fdisk
  404. will attempt to restore the partition table to
  405. its former state.
  406. .TP
  407. .B q
  408. Quit the program.
  409. If the partition table has been modified but not written,
  410. a warning is printed.
  411. Typing
  412. .B q
  413. again will quit the program.
  414. .PP
  415. .I Fdisk
  416. also has the following commands.
  417. .TP
  418. .BI A " name"
  419. Set the named partition active.
  420. The active partition is the one whose boot block is used
  421. when booting a PC from disk.
  422. .TP
  423. .B e
  424. Print the names of empty slots in the partition table, i.e., the
  425. valid names to use when creating a new partition.
  426. .PD
  427. .PP
  428. .I Format
  429. prepares for use the floppy diskette or hard disk partition in the file named
  430. .IR disk ,
  431. for example
  432. .B /dev/fd0disk
  433. or
  434. .BR /dev/sdC0/9fat .
  435. The options are:
  436. .TP
  437. .B -f
  438. Do not physically format the disc. Used
  439. to install a FAT file system on a
  440. previously formatted disc. If
  441. .I disk
  442. is not a floppy device, this flag is a no-op.
  443. .TP
  444. .B -t
  445. specify a density and type of disk to be prepared.
  446. The possible
  447. .I types
  448. are:
  449. .RS
  450. .TP
  451. .B 3½DD
  452. 3½" double density, 737280 bytes
  453. .TP
  454. .B 3½HD
  455. 3½" high density, 1474560 bytes
  456. .TP
  457. .B 5¼DD
  458. 5¼" double density, 368640 bytes
  459. .TP
  460. .B 5¼HD
  461. 5¼" high density, 1146880 bytes
  462. .TP
  463. .B hard
  464. fixed disk
  465. .PD
  466. .PP
  467. The default when
  468. .I disk
  469. is a floppy drive is the highest possible on the device.
  470. When
  471. .I disk
  472. is a regular file, the default is
  473. .BR 3½HD .
  474. When
  475. .I disk
  476. is an
  477. .IR sd (3)
  478. device, the default is
  479. .BR hard .
  480. .RE
  481. .TP
  482. .B -d
  483. initialize a FAT file system on the
  484. .IR disk .
  485. .TP
  486. .B -b
  487. use the contents of
  488. .I bootblock
  489. as a bootstrap block
  490. to be installed in sector 0.
  491. .PD
  492. .PP
  493. The remaining options have effect only when
  494. .B -d
  495. is specified:
  496. .TP
  497. .B -c
  498. use a FAT cluster size of
  499. .I csize
  500. sectors when creating the FAT.
  501. .TP
  502. .B -l
  503. add a
  504. .I label
  505. when creating the FAT file system.
  506. .TP
  507. .BI -r
  508. mark the first
  509. .I nresrv
  510. sectors of the partition as ``reserved''.
  511. Since the first sector always contains the
  512. FAT parameter block, this really marks
  513. the
  514. .IR nresrv -1
  515. sectors starting at sector 1 as ``reserved''.
  516. When formatting the
  517. .B 9fat
  518. partition,
  519. .B -r
  520. .B 2
  521. should be used to jump over the partition table sector.
  522. .PD
  523. .PP
  524. Again under
  525. .BR -d ,
  526. any
  527. .I files
  528. listed are added, in order,
  529. to the root
  530. directory of the FAT file system. The files are
  531. contiguously allocated.
  532. If a file is named
  533. .BR 9load ,
  534. it will be created with the
  535. .B SYSTEM
  536. attribute set so that
  537. .IR dossrv (4)
  538. keeps it contiguous when modifying it.
  539. .PP
  540. .I Format
  541. checks for a number of common mistakes; in particular,
  542. it will refuse to format a
  543. .B 9fat
  544. partition unless
  545. .B -r
  546. is specified with
  547. .I nresrv
  548. larger than two.
  549. It also refuses to format a raw
  550. .IR sd (3)
  551. partition that begins at offset zero in the disk.
  552. (The beginning of the disk should contain an
  553. .I fdisk
  554. partition table with master boot record,
  555. not a FAT file system or boot block.)
  556. Both checks are disabled by the
  557. .B -x
  558. option.
  559. The
  560. .B -v
  561. option prints debugging information.
  562. .PP
  563. The file
  564. .B /386/pbs
  565. is an example of a suitable
  566. .I bfile
  567. to make the disk a boot disk.
  568. It gets loaded by the BIOS at 0x7C00,
  569. reads the root directory into address 0x7E00, and looks at
  570. the first root directory entry.
  571. If that file is called
  572. .BR 9LOAD ,
  573. it uses
  574. single sector reads to load the file into address 0x10000 and then
  575. jumps to the loaded file image.
  576. The file
  577. .B /386/pbslba
  578. is similar, but because it uses LBA addressing (not supported
  579. by all BIOSes), it can access more than the first 8.5GB of the disk.
  580. .PP
  581. .I Mbr
  582. installs a new boot block in sector 0 (the master boot record)
  583. of a disk such as
  584. .BR /dev/sdC0/data .
  585. This boot block should not be confused with the
  586. boot block used by
  587. .IR format ,
  588. which goes in sector 0 of a partition.
  589. Typically, the boot block in the master boot record
  590. scans the PC partition table to find an active
  591. partition and then executes the boot block for
  592. that partition.
  593. The partition boot block then loads a bootstrap
  594. program such as
  595. .IR 9load (8),
  596. which then loads the operating system.
  597. If MS-DOS or Windows 9[58] is already installed
  598. on your hard disk, the master boot record
  599. already has a suitable boot block.
  600. Otherwise,
  601. .B /386/mbr
  602. is an appropriate
  603. .IR mbrfile .
  604. It detects and uses LBA addressing when available
  605. from the BIOS (the same could not
  606. be done in the case of
  607. .B pbs
  608. due to space considerations).
  609. If the
  610. .I mbrfile
  611. is not specified, a boot block is installed that
  612. prints a message explaining that the disk is not bootable.
  613. .SH EXAMPLES
  614. Initialize the kernel disk driver with the partition information
  615. from the FAT boot sectors.
  616. If Plan 9 partitions exist, pass that partition information as well.
  617. .IP
  618. .EX
  619. for(disk in /dev/sd??) {
  620. if(test -f $disk/data && test -f $disk/ctl)
  621. disk/fdisk -p $disk/data >$disk/ctl
  622. for(part in $disk/plan9*)
  623. if(test -f $part)
  624. disk/prep -p $part >$disk/ctl
  625. }
  626. .EE
  627. .PP
  628. Create a Plan 9 boot floppy on a previously formatted diskette:
  629. .IP
  630. .EX
  631. disk/format -b /386/pbs -df /dev/fd0disk /386/9load /tmp/plan9.ini
  632. .EE
  633. .PP
  634. Initialize the blank hard disk
  635. .BR /dev/sdC0/data .
  636. .IP
  637. .EX
  638. disk/mbr -m /386/mbr /dev/sdC0/data
  639. disk/fdisk -baw /dev/sdC0/data
  640. disk/prep -baw /dev/sdC0/plan9
  641. disk/format -b /386/pbs -d -r 2 /dev/sdC0/9fat 9load 9pcdisk plan9.ini
  642. .EE
  643. .PP
  644. .SH SOURCE
  645. .B /sys/src/cmd/disk/prep
  646. .br
  647. .B /sys/src/boot/pc
  648. .SH SEE ALSO
  649. .IR floppy (3),
  650. .IR sd (3),
  651. .IR 9load (8)
  652. .SH BUGS
  653. .I Format
  654. can create FAT12 and FAT16
  655. file systems, but not FAT32 file systems.
  656. The boot block can only read from
  657. FAT12 and FAT16 file systems.