Description: How to use mac-fdisk, and general partitioning guide for PowerMacs
Keywords: boot bootloader yaboot ybin GNU Linux GNU/Linux OpenFirmware dual-boot dualboot multi-boot multiboot bootmenu menu bootstrap Apple_Bootstrap partition lilo mac-fdisk pdisk

    This explains the basics of creating partitions with mac-fdisk in a
    step by step manner.  Note if you need to share the disk with MacOS
    you will need to first create the MacOS partitions with the MacOS
    utility Drive setup.  When creating the MacOS partitions you should
    first create with Drive setup a placeholder HFS partition as big as
    the total space ALL of your planned GNU/Linux partitions will take.
    For example, if you plan to have 4 1GB Linux partitions you would make
    the HFS placeholder partition 4GB.  You will delete this partition
    with mac-fdisk and create the Linux partitions in the space it leaves
    behind.  The MacOS partition[s] should be last on the disk.

    For Newworld systems you *must* have an 800K partition with type
    Apple_Bootstrap appearing *before* any MacOS partitions.

    DO NOT try and create Linux partitions with Apple's Drive setup!

    If you are not going to keep MacOS and intend to have a GNU/Linux only
    disk/system you should use the `i' command to mac-fdisk to clear out
    the partition table and make a new empty one, however mac-fdisk
    occasionally miscalculates the number of blocks the disk has.  When
    you run the `i' command it will prompt you for the number of blocks
    the disk has, make sure this number is correct before accepting it.

    NOTE: the mac-fdisk in Debian woody has been fixed, and no longer has
    this problem. If you are using mac-fdisk with Debian woody
    boot-floppies you need not find the number of blocks yourself as
    described below.

    To find out the number of blocks the disk has do the following (you
    can skip this if using Debian woody mac-fdisk):

    # cat /proc/partitions

    find the device you are partitioning, for example `hda' you should see
    something like this:

    ...
       3     0   20044080 hda
    ...

    take the number next to `hda' and double it, in this example you would
    get 40088160 that is the number of 512 byte blocks /dev/hda has, this
    is the number mac-fdisk should give as the default when you use the
    `i' command, if not type it in yourself.

    If you are sharing the disk with MacOS you should have already created
    two HFS partitions, the first just a placeholder to reserve the space
    for all your Linux partitions.  The second for MacOS.  Note if you
    want to also install MacOSX, you should use Drive setup to create a
    3rd partition type Apple_UFS, or MacOSX.  The MacOSX installer uses
    this as a placeholder partition, it will delete it and create 2
    bootstrap partitions and then recreate the Apple_UFS partition.  It is
    important that you not create the Apple_UFS partition before the
    GNU/Linux placeholder otherwise the MacOSX bootstrap partition will be
    ahead of the Linux bootstrap partition. Using HFS+ for MacOSX is not
    recommended as MacOS will debless the OSX partition rendering it
    unbootable.  GNU/Linux also has read-only support for UFS unlike HFS+.

    First you need to find and delete the placeholder partition:

    when you enter mac-fdisk you get the following prompt:

    Command (? for help):

    the first command you should give is the `p' print command:

    Command (? for help): p
    /dev/sdb
            #                    type name                length   base    ( size )  system
    /dev/sdb1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sdb2          Apple_Driver43 Macintosh               54 @ 64      ( 27.0k)  Driver 4.3
    /dev/sdb3          Apple_Driver43 Macintosh               74 @ 118     ( 37.0k)  Driver 4.3
    /dev/sdb4      Apple_Driver_IOKit Macintosh              512 @ 192     (256.0k)  Unknown
    /dev/sdb5           Apple_Patches Patch Partition        512 @ 704     (256.0k)  Unknown
    /dev/sdb6               Apple_HFS untitled            194557 @ 1216    ( 95.0M)  HFS
    /dev/sdb7               Apple_HFS untitled 2          333025 @ 195773  (162.6M)  HFS
    /dev/sdb8              Apple_Free Extra                   10 @ 528798  (  5.0k)  Free space

    Block size=512, Number of Blocks=528807
    DeviceType=0x0, DeviceId=0x0
    Drivers-
    1: @ 64 for 22, type=0x1
    2: @ 118 for 36, type=0xffff

    In this case the placeholder partition is 95MB (absurd but this is
    just a demonstration)

    Note that partitions 2-5 are MacOS cruft, they are only required if
    you are keeping MacOS, they are completly unnecessary if you delete
    MacOS.  It is reccommended that you remove all of these driver
    partitions if you do not plan to keep MacOS, do this with the `i'
    command.

    to delete this partition we use the `d' command and use the partition
    number, in this case 6:

    Command (? for help): d
    Partition number: 6
    Command (? for help): p
    /dev/sdb
            #                    type name                length   base    ( size )  system
    /dev/sdb1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sdb2          Apple_Driver43 Macintosh               54 @ 64      ( 27.0k)  Driver 4.3
    /dev/sdb3          Apple_Driver43 Macintosh               74 @ 118     ( 37.0k)  Driver 4.3
    /dev/sdb4      Apple_Driver_IOKit Macintosh              512 @ 192     (256.0k)  Unknown
    /dev/sdb5           Apple_Patches Patch Partition        512 @ 704     (256.0k)  Unknown
    /dev/sdb6              Apple_Free Extra               194557 @ 1216    ( 95.0M)  Free space
    /dev/sdb7               Apple_HFS untitled 2          333025 @ 195773  (162.6M)  HFS
    /dev/sdb8              Apple_Free Extra                   10 @ 528798  (  5.0k)  Free space

    as you can see there is now just a free space hole.

    create the bootstrap partition:

    If your using the mac-fdisk in Debian woody you can do this using the
    `b' command which will automatically create the partition with the
    correct type and size:

    Command (? for help): b
    First block: 6P
    Command (? for help): p
    /dev/sdb
            #                    type name                length   base    ( size )  system
    /dev/sdb1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sdb2          Apple_Driver43 Macintosh               54 @ 64      ( 27.0k)  Driver 4.3
    /dev/sdb3          Apple_Driver43 Macintosh               74 @ 118     ( 37.0k)  Driver 4.3
    /dev/sdb4      Apple_Driver_IOKit Macintosh              512 @ 192     (256.0k)  Unknown
    /dev/sdb5           Apple_Patches Patch Partition        512 @ 704     (256.0k)  Unknown
    /dev/sdb6         Apple_Bootstrap bootstrap             1600 @ 1216    (800.0k)  Unknown
    /dev/sdb7              Apple_Free Extra               192957 @ 2816    ( 94.2M)  Free space
    /dev/sdb8               Apple_HFS untitled 2          333025 @ 195773  (162.6M)  HFS
    /dev/sdb9              Apple_Free Extra                   10 @ 528798  (  5.0k)  Free space

    Otherwise you will have to create it manually, note that the `C'
    command is NOT the same as the `c' command:

    Command (? for help): C
    First block: 6P
    Length in blocks: 800K
    Name of partition: bootstrap
    Type of partition: Apple_Bootstrap
    Command (? for help): p
    /dev/sdb
            #                    type name                length   base    ( size )  system
    /dev/sdb1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sdb2          Apple_Driver43 Macintosh               54 @ 64      ( 27.0k)  Driver 4.3
    /dev/sdb3          Apple_Driver43 Macintosh               74 @ 118     ( 37.0k)  Driver 4.3
    /dev/sdb4      Apple_Driver_IOKit Macintosh              512 @ 192     (256.0k)  Unknown
    /dev/sdb5           Apple_Patches Patch Partition        512 @ 704     (256.0k)  Unknown
    /dev/sdb6         Apple_Bootstrap bootstrap             1600 @ 1216    (800.0k)  Unknown
    /dev/sdb7              Apple_Free Extra               192957 @ 2816    ( 94.2M)  Free space
    /dev/sdb8               Apple_HFS untitled 2          333025 @ 195773  (162.6M)  HFS
    /dev/sdb9              Apple_Free Extra                   10 @ 528798  (  5.0k)  Free space

    For `First block:' we used the first Apple_Free partition, partition 6
    hence `6P' you can use this syntax to avoid having to calculate the
    block offsets yourself.  Also note that the Apple_Free partition is
    now partition 7 and is 1600 blocks smaller, this will occur each time
    you create new partitions in that space until there is no more space
    left and this Apple_Free partition will simply be gone.

    Now create the rest of your GNU/Linux partitions, this will show only
    one partition.

    Command (? for help): c
    First block: 7P
    Length in blocks: 7P
    Name of partition: /
    Command (? for help): p
    /dev/sdb
            #                    type name                length   base    ( size )  system
    /dev/sdb1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sdb2          Apple_Driver43 Macintosh               54 @ 64      ( 27.0k)  Driver 4.3
    /dev/sdb3          Apple_Driver43 Macintosh               74 @ 118     ( 37.0k)  Driver 4.3
    /dev/sdb4      Apple_Driver_IOKit Macintosh              512 @ 192     (256.0k)  Unknown
    /dev/sdb5           Apple_Patches Patch Partition        512 @ 704     (256.0k)  Unknown
    /dev/sdb6         Apple_Bootstrap bootstrap             1600 @ 1216    (800.0k)  Unknown
    /dev/sdb7         Apple_UNIX_SVR2 /                   192957 @ 2816    ( 94.2M)  Linux native
    /dev/sdb8               Apple_HFS untitled 2          333025 @ 195773  (162.6M)  HFS
    /dev/sdb9              Apple_Free Extra                   10 @ 528798  (  5.0k)  Free space

    In this example we used the `c' command instead of `C' the difference
    is `c' does not ask for a partition type, which we needed to enter to
    get the special Apple_Bootstrap partition.  Also note that we used the
    7P syntax for the `Length of Blocks:' this means use all the space the
    selected Apple_Free partition has.  For other partitions you would
    want to use xyzM for number of MegaBytes similar to the above 800K for
    800 KiloBytes used for the bootstrap partition.

    The partition name does not matter except for the swap partition,
    where it should be `swap'.  I find it useful to use the mountpoint
    path as a partition name.

    once your are satisfied with your partitioning enter the `w' command
    to save changes:

    Command (? for help): w
    Writing the map destroys what was there before. Is that okay? [n/y]: y
    The partition table has been altered!

    SCSI device sdb: hdwr sector= 512 bytes. Sectors= 528808 [258 MB] [0.3 GB]
     sdb: sdb1 sdb2 sdb3 sdb4 sdb5 sdb6 sdb7 sdb8 sdb9
    SCSI device sdb: hdwr sector= 512 bytes. Sectors= 528808 [258 MB] [0.3 GB]
     sdb: sdb1 sdb2 sdb3 sdb4 sdb5 sdb6 sdb7 sdb8 sdb9
    Command (? for help):

    now quit mac-fdisk with the `q' command:

    Command (? for help): q

    If you are not going to keep MacOS then you should clear the partition
    table like so:

    Command (? for help): i
    map already exists
    do you want to reinit? [n/y]: y
    size of 'device' is 528808 blocks:
    new size of 'device' is 528808 blocks
    Command (? for help): p
    /dev/sda
            #                    type name                length   base    ( size )  system
    /dev/sda1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sda2              Apple_Free Extra               528744 @ 64      (258.2M)  Free space

    Block size=512, Number of Blocks=528808
    DeviceType=0x0, DeviceId=0x0

    Command (? for help):

    Note if mac-fdisk's idea of the `size of 'device'' is wrong then enter
    the correct value as described above.

    Clearing the partition table has the advantage of getting rid of all
    the MacOS cruft partitions created by Drive setup, those partitions
    are only required when sharing the disk with MacOS.

    create your partitions as shown in the previous example.

    ---- REORDERING PARTITIONS ----

    MacOSX uses Apple_UFS partitions created by Drive setup as a
    placeholder, it deletes them and create two bootstrap partitions of
    its own then recreates the Apple_UFS partition.  You should always
    create the GNU/Linux placeholder before any MacOS or MacOSX partitions
    but in case you didn't here is how to fix things.

    Reordering partitions is useful if you accidently created your
    bootstrap partition after your MacOS partitions, and its too late to
    repartition.

    the fix fortunatly is pretty simple, once you boot back into a
    GNU/Linux system run mac-fdisk (aka pdisk) and use the `p' command to
    print the partition table.  Find the new number of your Bootstrap
    partition and then use the `r' command to move it back where it
    belongs, here is an example:

    [root@socrates /root]# mac-fdisk /dev/sda
    Command (? for help): p
    /dev/sda
            #                    type name                length   base    ( size )  system
    /dev/sda1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sda2              Apple_Boot MacOSX_Bootstrap     16384 @ 64      (  8.0M)  Unknown
    /dev/sda3            Apple_Second MacOSX_Second_stage   2048 @ 16448   (  1.0M)  Unknown
    /dev/sda4               Apple_HFS MacOS9              102400 @ 18496   ( 50.0M)  HFS
    /dev/sda5               Apple_UFS MacOSX              112640 @ 120896  ( 55.0M)  Unknown
    /dev/sda6         Apple_Bootstrap bootstrap             1600 @ 233536  (800.0k)  Unknown
    /dev/sda7         Apple_UNIX_SVR2 GNU/Linux           293672 @ 235136  (143.4M)  Linux native

    Block size=512, Number of Blocks=528808
    DeviceType=0x0, DeviceId=0x0

    Command (? for help): r
    Partition number: 6
    New number: 2
    Command (? for help): p
    /dev/sda
            #                    type name                length   base    ( size )  system
    /dev/sda1     Apple_partition_map Apple                   63 @ 1       ( 31.5k)  Partition map
    /dev/sda2         Apple_Bootstrap bootstrap             1600 @ 233536  (800.0k)  Unknown
    /dev/sda3              Apple_Boot MacOSX_Bootstrap     16384 @ 64      (  8.0M)  Unknown
    /dev/sda4            Apple_Second MacOSX_Second_stage   2048 @ 16448   (  1.0M)  Unknown
    /dev/sda5               Apple_HFS MacOS9              102400 @ 18496   ( 50.0M)  HFS
    /dev/sda6               Apple_UFS MacOSX              112640 @ 120896  ( 55.0M)  Unknown
    /dev/sda7         Apple_UNIX_SVR2 GNU/Linux           293672 @ 235136  (143.4M)  Linux native

    Block size=512, Number of Blocks=528808
    DeviceType=0x0, DeviceId=0x0

    Command (? for help): w
    Writing the map destroys what was there before. Is that okay? [n/y]: y
    The partition table has been altered!

    SCSI device sda: hdwr sector= 512 bytes. Sectors= 528808 [258 MB] [0.3 GB]
     sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7
    SCSI device sda: hdwr sector= 512 bytes. Sectors= 528808 [258 MB] [0.3 GB]
     sda: sda1 sda2 sda3 sda4 sda5 sda6 sda7
    Command (? for help): q
    [root@socrates /root]#

    That should take care of the problem.  You may also have to fix your
    /etc/fstab if your GNU/Linux partitions moved, however that is beyond
    the spoke of this document.