Overview

What is pdisk?

A simple editor for Apple disk partition format. There are two main versions of pdisk: one for MkLinux and one for the Mac OS. This document describes the Mac OS version of pdisk. Much of this document is also relevant to the MkLinux version, but check the manual page (pdisk.8) also.

What is the Apple disk partition format?

Most operating systems have ways to divide disks into several pieces - so that an entire disk does not have to be devoted to one filesystem, or even to one operating system. This division of the disk is usually called partitioning. In some systems the partitioning information is built into the operating system code, but that tends to be restrictive. In the Mac OS the partitioning information is stored on the first few blocks of the disk.

The Apple disk partition scheme was developed in 1986 by the A/UX team with input from the Mac OS and Apple II teams. There was an earlier partition scheme used in the first SCSI drives on the MacPlus, but that was replaced by the current scheme in the Macintosh II and subsequent machines and in subsequent operating system releases. The current scheme is supported by Mac OS, A/UX, ProDos, MkLinux, and "Rhapsody".

What is MkLinux?

Just in case you got pdisk not as part of an MkLinux release: MkLinux is a version of the Linux operating system, converted to run as a server process on top of the Mach microkernel. As with Linux, all of the operating system source code is available for download, including the Mach source. MkLinux runs on many of PowerPC based Macintosh machines.

Which Macintosh machines does pdisk run on?

The Mac OS binary should run on any PowerPC based Macintosh. It has been tested under System 7.6.1 and System 8, but should run on older versions of the Mac OS as well. A Mac OS 68000 binary is also distributed for those who may find it useful.

Why would I want to use pdisk on the Mac OS?

The main clients for the Mac OS version of pdisk are MkLinux users. pdisk was originally developed for MkLinux. The command syntax was originally identical to that for the 'fdisk' program. (fdisk is a Linux program which edits the DOS/Windows disk partition format.) The Mac OS version is a simple, crude port of the MkLinux version.

The advantages of pdisk over the various Mac OS disk partitioning programs (such as SilverLining, the FWB toolkit, Apple HD SC Setup, DriveSetup, etc) are:

The disadvantages of pdisk are:

Where can I get the source?

The main site for MkLinux is <http://www.mklinux.apple.com>. As of the time this document was written you could find the pdisk distributions at <ftp://ftp.mklinux.apple.com/pub/Other_tools/pdisk/>. This includes binary distributions for MkLinux and the Mac OS, as well as a source distribution.

Description of the program (as of version 0.7)

Though pdisk is a Macintosh program its interface is very un-Macintosh. pdisk is what is called a line-oriented program. In a line-oriented program you do things by typing on the keyboard and the program does not pay attention to the typing until the return key has been typed.

When you start up pdisk it brings up a window with some text in it. The last line of this text should be something like " Top level command (? for help): ". This is the prompt. If you type "?" followed by a return character you should get a list like this:

Notes:
    Disk have fake names of the form /dev/scsi<bus>.<id>
    For example, /dev/scsi0.1, /dev/scsi1.3, and so on.
    MkLinux style names are also allowed (i.e /dev/sda or /dev/hda),
    and these names follow the MkLinux DR3 conventions.
 
Commands are:
  h    print help
  v    print the version number and release date
  l    list device's map
  L    list all devices' maps
  e    edit device's map
  E    (edit map with specified block size)
  r    toggle readonly flag
  q    quit the program

Some of these commands need what are called arguments - for example l (list) and e (edit) need a single argument, the name of the device to list or edit. Commands which take arguments prompt for each argument in turn. You can also type any number of the arguments separated by spaces and those prompts will be skipped. Commands are case insensitive (e.g. h and H) except when the upper case letter does a variant form of the operation.

h
Prints just the command help. The difference between h and ? is the latter prints some helpful notes as well.
v
Prints a version number and release date. Matches the version in the GetInfo window for the application.
l
Prompts for the name of the device and then lists the partition map on that device.
L
Lists all the devices.
e
Prompts for the name of the device and then opens the partition map for editing.
E
Same as e, except also prompts for block size.
r
Toggles read-only setting. When read-only is on pdisk will not write a partition map.
q
Quit pdisk.

The form of the listing

This is a good point to show what the partition map listing looks like.

Partition map (with 512 byte blocks) on '/dev/scsi0.2' (/dev/sda)
   #:                 type name                length   base    ( size )
   1:  Apple_partition_map Apple                   63 @ 1      
   2:       Apple_Driver43*Macintosh               54 @ 64     
   3:       Apple_Driver43*Macintosh               74 @ 118    
   4:        Apple_Patches Patch Partition        512 @ 192    
   5:            Apple_HFS untitled           2117430 @ 704     (  1.0G)
   6:           Apple_Free Extra                   10 @ 2118134
 
Device block size=512, Number of Blocks=2118143
DeviceType=0x0, DeviceId=0x0
Drivers-
1: @ 64 for 20, type=0x1
2: @ 118 for 32, type=0xffff

The first line indicates what device this is and what size blocks the partition map is using. Most partition maps will use 512-byte blocks, but partition maps can use 1024-byte (1K) or 2048-byte (2K) blocks instead. If we are able to deduce an MkLinux name different from the name then the MkLinux name is given in parentheses.

Next is the partition list. Each partition (or piece) of the disk takes one line of the list. The data describing the partition is called the partition map entry. The entries are listed in order by index. For each entry, the following information is displayed:

Following the partition list is information from block zero of the device which describes the location of drivers.

Editing Partition Tables

The e command at the top level menu opens a partition map for editing. The prompt is then changed to "Command (? for help):". If you type "?" followed by a return character you should get a list like this:

Notes:
  Base and length fields are blocks, which vary in size between media.
  The name of a partition is descriptive text.
 
Commands are:
  h    help
  p    print the partition table
  P    (print ordered by base address)
  i    initialize partition map
  s    change size of partition map
  c    create new partition (standard MkLinux type)
  C    (create with type also specified)
  n    (re)name a partition
  d    delete a partition
  r    reorder partition entry in map
  w    write the partition table
  q    quit editing (don't save changes)

Commands which take arguments prompt for each argument in turn. You can also type any number of the arguments separated by spaces and those prompts will be skipped. The only exception to typeahead are the confirmation prompts on the i and w commands. Commands can are case insensitive (e.g. h and H) except when the upper case letter does a variant form of the operation.

Partitions are always specified by their number, which the index of the partition entry in the partition map. Many of the commands will change the index numbers of other partitions besides the affected partition. You are advised to print the table as frequently as necessary.

Creating more than fifteen partitions is not advised. There is currently a bug in the some (all?) of the kernels which causes access to the whole disk fail if more than fifteen partitions are in the map.

h
Prints just the command help. The difference between h and ? is the latter prints some helpful notes as well.
p
Prints the partition table. The form is identical to the listing described above.
P
Identical to p, except the entries are listed in the order of the partitions on the disk (i.e. by the increasing base value) rather than in index order.
i
Initializes the partition map (rarely used). This command prompts for the size of the device. WARNING - if you write the map after initializing it you will delete all the drivers on the device. That makes the device invisible to the Mac OS. pdisk is not able to install drivers.
s
Change the size of the partition map partition. The partition map's size must be less than or equal to the size of the partition it is contained in. This is mostly useful when you want to do tricky things like making a disk with multiple partitioning schemes on it.
c
Create a new partition takes three arguments.
The first argument is the base address (in partition blocks) of the partition. Besides a raw number, you can also specify a partition number followed by the letter 'p' to indicate that the first block of the new partition should be the same as the first block of that existing free space partition.
The second argument is the length of the partition in partition blocks. This can be a raw number or can be a partition number followed by the letter 'p' to use the size of that partition or can be a number followed by 'k', 'm', or 'g' to indicate the size in kilobytes, megabytes, or gigabytes respectively. (These are powers of 1024, of course, not powers of 1000.)
The last argument is the name of the partition. This can be a single word without quotes, or a string surrounded by single or double quotes.
The type of the created partition is set to the correct type for MkLinux ("Apple_UNIX_SVR2").
C
Identical to the c command, with the addition of a prompt for the partition type after the other arguments. The type can be a single word without quotes, or a string surrounded by single or double quotes.
n
Rename a partition. Do not change the name of any partition whose type starts with "Apple_Driver". The MacOS looks at the names of those partitions. All other partitions should be okay to change.
d
Delete a partition. When a partition is deleted it's type is changed to free ("Apple_Free") and then it is combined with any adjacent free space.
r
Reorder takes the current index and the desired new index. If you give a new index which is greater than the last index the entry will be moved to the last index.
w
Write does write the partition map out, but pdisk does not yet flush the appropriate caches and unmount volumes so the partition map is not reinterpreted. In order to use the new partition map you must reboot your machine. Sorry.
q
Quit out of editing. Returns to the top level prompt. If you have modified the partition map you are NOT asked if you want to save the changes, instead the changes are quietly thrown away.

Known problems

This is an awful Mac OS application, it should be rewritten to look the way a Mac OS app should look.
The code assumes a better understanding of the partitioning scheme than most people care to acquire.
 
Even more help should be available during user input.


eryk@apple.com