123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- .TH PREP 8
- .SH NAME
- prep, fdisk, format, mbr \- prepare hard and floppy diskettes, flashes
- .SH SYNOPSIS
- .B disk/prep
- [
- .B -abcfnprw
- ]
- [
- .B -s
- .I sectorsize
- ]
- .I plan9partition
- .PP
- .B disk/fdisk
- [
- .B -abfprw
- ]
- [
- .B -s
- .I sectorsize
- ]
- .I disk
- .PP
- .B disk/format
- [
- .B -dfvx
- ]
- [
- .B -b
- .I bootblock
- ]
- [
- .B -c
- .I csize
- ]
- [
- .B -l
- .I label
- ]
- [
- .B -r
- .I nresrv
- ]
- [
- .B -t
- .I type
- ]
- .I disk
- [
- .IR file ...
- ]
- .PP
- .B disk/mbr
- [
- .B -m
- .I mbrfile
- ]
- .SH DESCRIPTION
- A partition table is stored on a hard disk to specify the division of
- the physical disk into a set of logical units.
- On PCs, the partition table is stored at the end of the master boot record
- of the disk.
- Partitions of type
- .B 0x39
- are Plan 9 partitions.
- The names of PC partitions are chosen by convention from the type:
- .BR dos ,
- .BR plan9 ,
- etc.
- Second and subsequent partitions of the same type on a given disk are given
- unique names by appending a number (or a period and a number if the name
- already ends in a number).
- .PP
- Plan 9 partitions (and Plan 9 disks on non-PCs) are
- themselves divided, using a textual partition table, called the Plan 9 partition table, in the second
- sector of the partition (the first is left for architecture-specific boot data, such as PC boot blocks).
- The table is a sequence of lines of the format
- .BI part " name start end" \fR,
- where
- .I start
- and
- .I end
- name the starting and ending sector.
- Sector 0 is the first sector of the Plan 9 partition or disk,
- regardless of its position in a larger disk.
- Partition extents do not contain the ending sector,
- so a partition from 0 to 5 and a partition from 5 to 10
- do not overlap.
- .PP
- The Plan 9 partition often contains a number of
- conventionally named subpartitions.
- They include:
- .TF cache
- .TP
- .B 9fat
- A small FAT file system used to hold
- configuration information
- (such as
- .B plan9.ini
- and
- .BR plan9.nvr )
- and kernels.
- This typically begins in the first sector
- of the partition, and contains the partition
- table as a ``reserved'' sector.
- See the discussion of the
- .B -r
- option to
- .IR format .
- .TP
- .B cache
- A
- .IR cfs (4)
- file system cache.
- .TP
- .B fs
- A
- .IR kfs (4)
- file system.
- .TP
- .B swap
- A
- .IR swap (8)
- swap partition.
- .PD
- .PP
- .I Fdisk
- edits the PC partition table and is usually
- invoked with a disk like
- .B /dev/sdC0/data
- as its argument, while
- .I prep
- edits the Plan 9 partition table
- and is usually invoked with a disk partition
- like
- .B /dev/sdC0/plan9
- as its argument.
- .I Fdisk
- works in units of disk ``cylinders'': the cylinder
- size in bytes is printed when
- .I fdisk
- starts.
- .I Prep
- works in units of disk sectors, which are almost always 512 bytes.
- .I Fdisk
- and
- .I prep
- share most of their options:
- .TP
- .B -a
- Automatically partition the disk.
- .I Fdisk
- will create a Plan 9
- partition in the largest unused area on the disk,
- doing nothing if a
- Plan 9 partition already exists.
- If no other partition on the disk is marked active (i.e. marked as the boot partition),
- .I fdisk
- will mark the new partition active.
- .I Prep
- will create
- .BR 9fat ,
- .BR swap ,
- and
- .B fs
- partitions, doing
- nothing if the disk
- has already been partitioned.
- If the
- .B -c
- option is present,
- .I prep
- will also create a
- .B cache
- partition.
- If the
- .B -n
- option is present,
- .I prep
- will create a one-sector
- .B nvram
- partition.
- .TP
- .B -b
- Start with a blank disk, ignoring any extant partition table.
- .TP
- .B -p
- Print a sequence of commands that when sent to the disk device's
- .B ctl
- file
- will bring the partition
- table information kept by
- the
- .IR sd (3)
- driver up to date.
- Then exit.
- .I Prep
- will check to see if it is being called with a disk partition
- (rather than an entire disk) as its argument; if so, it
- will translate the printed sectors by the partition's offset
- within the disk.
- Since
- .I fdisk
- operates on a table of unnamed partitions,
- it assigns names based on the partition type
- (e.g.,
- .BR plan9 ,
- .BR dos ,
- .BR ntfs ,
- .BR linux ,
- .BR linuxswap )
- and resolves collisions by appending a numbered suffix.
- (e.g.,
- .BR dos ,
- .BR dos.1 ,
- .BR dos.2 ).
- .TP
- .B -r
- In the absence of the
- .B -p
- and
- .B -w
- flags,
- .I prep
- and
- .I fdisk
- enter an interactive partition editor;
- the
- .B -r
- flag runs the editor in read-only mode.
- .TP
- .BI -s " sectorsize"
- Specify the disk's sector size.
- In the absence of this flag,
- .I prep
- and
- .I fdisk
- look for a disk
- .B ctl
- file and read it to find the disk's sector size.
- If the
- .B ctl
- file cannot be found, a message is printed and
- a sector size of 512 bytes is assumed.
- .TP
- .B -w
- Write the partition table to the disk and exit.
- This is useful when used in conjunction with
- .B -a
- or
- .BR -b .
- .PP
- If neither the
- .B -p
- flag nor the
- .B -w
- flag is given,
- .I prep
- and
- .I fdisk
- enter an interactive partition editor that
- operates on named partitions.
- The PC partition table distinguishes between
- primary partitions, which can be listed in the boot
- sector at the beginning of the disk,
- and secondary (or extended) partitions, arbitrarily
- many of which may be chained together in place
- of a primary partition.
- Primary partitions are named
- .BR p \fIn\fR,
- secondary partitions
- .BR s \fIn\fR.
- The number of primary partitions plus number of contiguous chains of
- secondary partitions cannot exceed four.
- .PP
- The commands are as follows.
- In the descriptions, read ``sector'' as ``cylinder'' when using
- .IR fdisk .
- .TP
- .B "a\fR \fIname\fR [ \fIstart\fR [ \fIend\fR ] ]"
- Create a partition named
- .I name
- starting at sector offset
- .I start
- and ending at offset
- .IR end .
- The new partition will not be created if
- it overlaps an extant partition.
- If
- .I start
- or
- .I end
- are omitted,
- .I prep
- and
- .I fdisk
- will prompt for them.
- .I Start
- and
- .I end
- may be expressions using the operators
- .BR + ,
- .BR - ,
- .BR * ,
- and
- .BR / ,
- numeric constants, and the
- pseudovariables
- .B .
- and
- .BR $ .
- At the start of the program,
- .B .
- is set to zero; each time a partition is
- created, it is set to the end sector
- of the new partition.
- It can also be explicitly set using the
- .B .
- command.
- When evaluating
- .IR start ,
- .B $
- is set to one past the last disk sector.
- When evaluating
- .IR end ,
- .B $
- is set to the maximum value that
- .I end
- can take on without running off the disk
- or into another partition.
- Finally, the expression
- .IB n %
- evaluates to
- .RI ( n × disksize )/100.
- As an example,
- .B a
- .B .
- .B .+20%
- creates a new partition starting at
- .B .
- that takes up a fifth of the disk,
- and
- .B a
- .B 1000
- .B $
- creates a new partition starting at
- sector 1000 and
- extending as far as possible.
- .TP
- .B ".\fR \fInewdot"
- Set the value of the variable
- .B .
- to
- .IR newdot ,
- which is an arithmetic expression as described
- in the discussion of the
- .B a
- command.
- .TP
- .BI d " name"
- Delete the named partition.
- .TP
- .B h
- Print a help message listing command synopses.
- .TP
- .B p
- Print the disk partition table.
- Unpartitioned regions are also listed.
- The table consists of a number of lines containing
- partition name, beginning and ending sectors,
- and total size.
- A
- .B '
- is prefixed to the names of partitions
- whose entries have been modified but not written to disk.
- .I Fdisk
- adds to the end of each line a textual partition type,
- and places a
- .B *
- next to the name of the active partition
- (see the
- .B A
- command below).
- .TP
- .B P
- Print the partition table in the format accepted by the disk's
- .B ctl
- file, which is also the format of the output of the
- .B -p
- option.
- .TP
- .B w
- Write the partition table to disk.
- .I Prep
- will also inform the kernel of the changed
- partition table.
- The write will fail if any programs have any
- of the disk's partitions open.
- If the write fails (for this or any other reason),
- .I prep
- and
- .I fdisk
- will attempt to restore the partition table to
- its former state.
- .TP
- .B q
- Quit the program.
- If the partition table has been modified but not written,
- a warning is printed.
- Typing
- .B q
- again will quit the program.
- .PP
- .I Fdisk
- also has the following commands.
- .TP
- .BI A " name"
- Set the named partition active.
- The active partition is the one whose boot block is used
- when booting a PC from disk.
- .TP
- .B e
- Print the names of empty slots in the partition table, i.e., the
- valid names to use when creating a new partition.
- .PD
- .PP
- .I Format
- prepares for use the floppy diskette or hard disk partition in the file named
- .IR disk ,
- for example
- .B /dev/fd0disk
- or
- .BR /dev/sdC0/9fat .
- The options are:
- .TP
- .B -f
- Do not physically format the disc. Used
- to install a FAT file system on a
- previously formatted disc. If
- .I disk
- is not a floppy device, this flag is a no-op.
- .TP
- .B -t
- specify a density and type of disk to be prepared.
- The possible
- .I types
- are:
- .RS
- .TP
- .B 3½DD
- 3½" double density, 737280 bytes
- .TP
- .B 3½HD
- 3½" high density, 1474560 bytes
- .TP
- .B 5¼DD
- 5¼" double density, 368640 bytes
- .TP
- .B 5¼HD
- 5¼" high density, 1146880 bytes
- .TP
- .B hard
- fixed disk
- .PD
- .PP
- The default when
- .I disk
- is a floppy drive is the highest possible on the device.
- When
- .I disk
- is a regular file, the default is
- .BR 3½HD .
- When
- .I disk
- is an
- .IR sd (3)
- device, the default is
- .BR hard .
- .RE
- .TP
- .B -d
- initialize a FAT file system on the
- .IR disk .
- .TP
- .B -b
- use the contents of
- .I bootblock
- as a bootstrap block
- to be installed in sector 0.
- .PD
- .PP
- The remaining options have effect only when
- .B -d
- is specified:
- .TP
- .B -c
- use a FAT cluster size of
- .I csize
- sectors when creating the FAT.
- .TP
- .B -l
- add a
- .I label
- when creating the FAT file system.
- .TP
- .BI -r
- mark the first
- .I nresrv
- sectors of the partition as ``reserved''.
- Since the first sector always contains the
- FAT parameter block, this really marks
- the
- .IR nresrv -1
- sectors starting at sector 1 as ``reserved''.
- When formatting the
- .B 9fat
- partition,
- .B -r
- .B 2
- should be used to jump over the partition table sector.
- .PD
- .PP
- Again under
- .BR -d ,
- any
- .I files
- listed are added, in order,
- to the root
- directory of the FAT file system. The files are
- contiguously allocated.
- If a file is named
- .BR 9load ,
- it will be created with the
- .B SYSTEM
- attribute set so that
- .IR dossrv (4)
- keeps it contiguous when modifying it.
- .PP
- .I Format
- checks for a number of common mistakes; in particular,
- it will refuse to format a
- .B 9fat
- partition unless
- .B -r
- is specified with
- .I nresrv
- larger than two.
- It also refuses to format a raw
- .IR sd (3)
- partition that begins at offset zero in the disk.
- (The beginning of the disk should contain an
- .I fdisk
- partition table with master boot record,
- not a FAT file system or boot block.)
- Both checks are disabled by the
- .B -x
- option.
- The
- .B -v
- option prints debugging information.
- .PP
- The file
- .B /386/pbs
- is an example of a suitable
- .I bfile
- to make the disk a boot disk.
- It gets loaded by the BIOS at 0x7C00,
- reads the root directory into address 0x7E00, and looks at
- the first root directory entry.
- If that file is called
- .BR 9LOAD ,
- it uses
- single sector reads to load the file into address 0x10000 and then
- jumps to the loaded file image.
- The file
- .B /386/pbslba
- is similar, but because it uses LBA addressing (not supported
- by all BIOSes), it can access more than the first 8.5GB of the disk.
- .PP
- .I Mbr
- installs a new boot block in sector 0 (the master boot record)
- of a disk such as
- .BR /dev/sdC0/data .
- This boot block should not be confused with the
- boot block used by
- .IR format ,
- which goes in sector 0 of a partition.
- Typically, the boot block in the master boot record
- scans the PC partition table to find an active
- partition and then executes the boot block for
- that partition.
- The partition boot block then loads a bootstrap
- program such as
- .IR 9load (8),
- which then loads the operating system.
- If MS-DOS or Windows 9[58] is already installed
- on your hard disk, the master boot record
- already has a suitable boot block.
- Otherwise,
- .B /386/mbr
- is an appropriate
- .IR mbrfile .
- It detects and uses LBA addressing when available
- from the BIOS (the same could not
- be done in the case of
- .B pbs
- due to space considerations).
- If the
- .I mbrfile
- is not specified, a boot block is installed that
- prints a message explaining that the disk is not bootable.
- .SH EXAMPLES
- Initialize the kernel disk driver with the partition information
- from the FAT boot sectors.
- If Plan 9 partitions exist, pass that partition information as well.
- .IP
- .EX
- for(disk in /dev/sd??) {
- if(test -f $disk/data && test -f $disk/ctl)
- disk/fdisk -p $disk/data >$disk/ctl
- for(part in $disk/plan9*)
- if(test -f $part)
- disk/prep -p $part >$disk/ctl
- }
- .EE
- .PP
- Create a Plan 9 boot floppy on a previously formatted diskette:
- .IP
- .EX
- disk/format -b /386/pbs -df /dev/fd0disk /386/9load /tmp/plan9.ini
- .EE
- .PP
- Initialize the blank hard disk
- .BR /dev/sdC0/data .
- .IP
- .EX
- disk/mbr -m /386/mbr /dev/sdC0/data
- disk/fdisk -baw /dev/sdC0/data
- disk/prep -baw /dev/sdC0/plan9
- disk/format -b /386/pbs -d -r 2 /dev/sdC0/9fat 9load 9pcdisk plan9.ini
- .EE
- .PP
- .SH SOURCE
- .B /sys/src/cmd/disk/prep
- .br
- .B /sys/src/boot/pc
- .SH SEE ALSO
- .IR floppy (3),
- .IR sd (3),
- .IR 9load (8)
- .SH BUGS
- .I Format
- can create FAT12 and FAT16
- file systems, but not FAT32 file systems.
- The boot block can only read from
- FAT12 and FAT16 file systems.
|