| PREP(8) | System Manager's Manual | PREP(8) |
prep, fdisk, format, mbr - prepare hard and floppy diskettes, flashes
disk/prep [ -bcfnprw ] [ -a name ]... [ -s sectorsize ] plan9partition
disk/fdisk [ -abfprw ] [ -s sectorsize ] disk
disk/format [ -dfvx ] [ -b bootblock ] [ -c csize ] [ -l label ] [ -r nresrv ] [ -t type ] disk [ file... ]
disk/mbr [ -9 ] [ -m mbrfile ]
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 0x39 are Plan 9 partitions. Inferno uses the same type and follows other Plan 9 conventions described here. The names of PC partitions are chosen by convention from the type: dos, 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).
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). Inferno again uses the same conventions. The table is a sequence of lines of the format part name start end, where start and 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.
The Plan 9 partition often contains a number of conventionally named subpartitions. Only 9fat, fs and nvram are currently used by Inferno, but the others are included for reference. They include:
Fdisk edits the PC partition table and is usually invoked with a disk like /dev/sdC0/data as its argument, while prep edits the Plan 9 partition table and is usually invoked with a disk partition like /dev/sdC0/plan9 as its argument. Fdisk works in units of disk ``cylinders'': the cylinder size in bytes is printed when fdisk starts. Prep works in units of disk sectors, which are almost always 512 bytes. Fdisk and prep share most of their options:
If neither the -p flag nor the -w flag is given, prep and 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 pn, secondary partitions sn. The number of primary partitions plus number of contiguous chains of secondary partitions cannot exceed four.
The commands are as follows. In the descriptions, read ``sector'' as ``cylinder'' when using fdisk.
Fdisk also has the following commands.
Format prepares for use the floppy diskette or hard disk partition in the file named disk, for example /dev/fd0disk or /dev/sdC0/9fat. The options are:
The default when disk is a floppy drive is the highest possible on the device. When disk is a regular file, the default is 3½HD. When disk is an sd (3) device, the default is hard.
The remaining options have effect only when -d is specified:
Again under -d, any 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 9load, it will be created with the SYSTEM attribute set so that dossrv (4) keeps it contiguous when modifying it.
Format checks for a number of common mistakes; in particular, it will refuse to format a 9fat partition unless -r is specified with nresrv larger than two. It also refuses to format a raw sd (3) partition that begins at offset zero in the disk. (The beginning of the disk should contain an fdisk partition table with master boot record, not a FAT file system or boot block.) Both checks are disabled by the -x option. The -v option prints debugging information.
The file /Inferno/386/pbs is an example of a suitable 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 9LOAD, it uses single sector reads to load the file into address 0x10000 and then jumps to the loaded file image. The file /Inferno/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.
Mbr installs a new boot block in sector 0 (the master boot record) of a disk such as /dev/sdC0/data. This boot block should not be confused with the boot block used by 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 9load(10.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, /Inferno/386/mbr is an appropriate mbrfile. It detects and uses LBA addressing when available from the BIOS (the same could not be done in the case of pbs due to space considerations). If the mbrfile is not specified, a boot block is installed that prints a message explaining that the disk is not bootable. The -9 option initialises the partition table to consist of one plan9 partition which spans the entire disc starting at the end of the first track.
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.
for(disk in /dev/sd??) {
if(ftest -f $disk/data && ftest -f $disk/ctl){
disk/fdisk -p $disk/data >$disk/ctl
}
for(part in $disk/plan9*){
if(ftest -f $part){
disk/prep -p $part >$disk/ctl
}
}
}
Create a boot floppy on a previously formatted diskette:
disk/format -b /Inferno/386/pbs -df /dev/fd0disk /Inferno/386/9load /tmp/plan9.ini
Initialize the blank hard disk /dev/sdC0/data.
disk/mbr -m /Inferno/386/mbr /dev/sdC0/data
disk/fdisk -baw /dev/sdC0/data
disk/prep -bw -a^(9fat fs) /dev/sdC0/plan9
disk/format -b /Inferno/386/pbslba -d -r 2 /dev/sdC0/9fat 9load 9pcdisk plan9.ini
/appl/cmd/disk/prep
/appl/cmd/disk/format.b
/os/boot/pc
floppy (3), sd (3), 9load(10.8), plan9.ini(10.8)
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.