Mac HD Partitions

From FreekiWiki
Revision as of 11:24, 21 June 2012 by Mikem (talk | contribs)
Jump to navigation Jump to search

The Partitions

The discussion here assumes that the reader might be familiar with partitions on PC (x86) hard drives.

The Ubuntu install process on PowerPC machines (iMac, PowerMac, etc) creates four partitions. Using the command sudo fdisk -l /dev/hda in a terminal (assuming that the device is a hard drive and has been formatted by Ubuntu), the partition table can be printed out. Here is a typical example:

/dev/hda
        #                 type name           length   base     ( size )  system
/dev/hda1  Apple_partition_map Apple              63 @ 1        ( 31.5k)  Partition map
/dev/hda2      Apple_Bootstrap untitled         1954 @ 64       (977.0k)  NewWorld bootblock
/dev/hda3      Apple_UNIX_SVR2 untitled     13931641 @ 2018     (  6.6G)  Linux native
/dev/hda4      Apple_UNIX_SVR2 swap           734631 @ 13933659 (358.7M)  Linux swap

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

Note that this looks different from the x86 (PC) fdisk partition table, but the contents are essentially the same. One major difference is that the PPC partition table listing actually contains a reference to the table itself. Another difference is the partition type names. Let's examine the table a little more closely.

  • The table has several lines. The first line shows the device being examined, in this case /dev/hda. The second line contains column titles. The names are pretty much self explanatory; the '#' represents 'partition number'.
  • There is one line for each defined partition. If there is any unused space on the disk after all partitions are defined, there will be a line for that, also.
  • The disk size in blocks is shown at the end of the listing, along with the block size. Multiplying these numbers together gives the size of the disk in bytes, in this case, about 7.5GB.
  • The first partition, /dev/hda1, contains the partition table (called partition map here). It starts at block 1 and is 63 blocks long. It has no formal filesystem (i.e., it is raw data).
  • The second partition, /dev/hda2, contains the boot information. Its type and system designations indicate this. This partition is created as an hfs filesystem. (hfs is the original Apple filesystem type). It contains three files: ofboot.b, yaboot, and yaboot.conf. The partition can actually be mounted in Linux with type hfs, and the files manipulated. This partition starts at block 64, the first block after the end of the first partition, and is 1954 blocks long.
  • The third partition, /dev/hda3, is the Linux partition. It starts at block 2018, the first block after the end of the second partition. It's length is almost the entire rest of the disk, except for the space reserved for the swap partition. The Ubuntu installation partitioning process installs an ext3 filesystem here by default.
  • The fourth partition, /dev/hda4, is the swap partition. It start immediately after the Linux partition, and it's length represents approximately 1.5 times memory size.
  • Note that the lengths of all of the partitions do not add up to the length of the hard drive reported in the bottom two lines. In fact, they add up to exactly one less than the disk length. Traditionally, blocks on a hard drive are numbered starting at 0, and the the first block on a drive is reserved as the boot block or MBR as it it known in x86/PC land. The partition map starts at block 1, which is actually the second block on the drive. The rest of the partitions take up all the remaining blocks on the disk.

During Ubuntu installation from CD, at the partition creation step, the size of the swap partition is calculated from the memory size, and the size of the Linux partition is caclulated as whatever is left over. This information will be used later in this article when talking about Manual Partitioning. Notice that the base, or start, block of a partition can be calculated by adding the lengths of all previous partitions, and then adding one to that total. Another way to find the start block of the next partition is to add a partition's length and start block.

Manual Partitioning

The Ubuntu installation partitioning process can be duplicated manually. Such an approach is useful, for example, in replicating Ubuntu PowerPC Linux disks for savingtime during Mac Rebuild.

A common utility program for creating partitions, and the one that will be used in examples here, is fdisk. Again, its behavior. appearance and functionality are not exactly the same as its PC counterpart. It is invoked on a terminal command line with a single argument: the name of the device to be partitioned. The first response is a repetition of the deivce name, and a command inout request:

$ fdisk /dev/hda
/dev/hda
Command (? for help):

Typing ? at this point will produce a list of possible commands:

Command (? for help): ?
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
  b    create new 800K bootstrap partition
  c    create new Linux partition
  C    (create with type also specified)
  d    delete a partition
  r    reorder partition entry in map
  w    write the partition table
  q    quit editing (don't save changes)

When creating partitions, is is always a good idea to use the p command frequently to check you work. No changes are actually written to the disk until you use the wcommand, but it is a good idea to check yourself anywa as you go along. As always, there is a man page for fdisk that gives more information.

We will use the example scenario suggested earlier, replicating an PowerPC Ubuntu installed hard drive, to step through partition table creation. We make several assumptions:

  1. the boot drive is separate from the source and target drives. Four our purposes the source drive is /dev/hdc and the target drive is /dev/hdd.
  2. that the target disk, /dev/hdd, is completely empty, and needs a new partition map created
  3. that the source drive, /dev/hdc, was installed normally from an alternate install CD.

When fdisk /dev/hdd is run from the command line, the fdisk command prompt appears as usual. At this point entering the command p results in a message that no partition map is defined:

<text of p command response here>

The i command will create an empty partition map. A p command at this point will show a partition map with one entry, the partition map itself, beginning at block 1 with length 63.

<text of partion map creation and empty partition map response here>

We will create the rest of the partitions in the order that they will appear finally in the partition map. To create the boot, or second, partition, (remember that the partition map is actually the first partition), use the C (capital C) command. A little explanation is required here. There is a command b to explicitly create an 800k boot partition. Such a partition is 1600 blocks long, but if you look back in The Partitions, you will see that see that we need a partition that is 1954 blocks long. The C command gives us more control to do that, but we pay the price of having to specify more of the creation information.

The Ccommand will prompt for start block, length, partition name and partition type. For our purposes, the start block number is the sum of the previous partition lengths plus 1. Since there is only one previous partition, and it is 63 blocks long, this boot partition starts at block 64. We know that we want this partition to be 1954 blocks long. The name doesn't really matter, and the Ubuntu install process uses the name untitled, so we will, too. The partition type is important: Apple_Bootstrap, because the boot process looks for a partition of this type to find the boot files.

<text of boot partition creation dialog  and p command here>

The third partition is created with the c command. The dialog in this case prompts for start, length and name. As before, the name is not important, and we use untitled. The start block is 2018, which is the sum of the lengths of the previous partitions plus 1 (63 + 1954 +1). The size will take a little work to come up with. The trick here is to figure out how big the swap (fourth) partition should be, and subtract that from the unused space. It was pointed out earlier that any unused space shows up as the last line in the partition table. Let's use the example partition table in The Partitions. The partition table liste above shows that the remaining space is 14666272 blocks. If we assume that the target system (the one this drive will go into) has 256 MB of memory, then we can estimate that the swap space required is 384MB, or 750000 blocks. (The actual calculation used by Ubuntu is not this simple, and the result is a little different). We can now calculate the Linux partition length as (14666272 - 750000), or 13916272 blocks.

<text of c command dialog and p command here>

The fourth (swap) partition is also created with the c command, but with a lot less work. The start block is the calculated simply by adding the start block and length of the third partition, and the length of the swap partition is 750000 as we calculated before. The name of this partition apparently is important. The name swap seems to be recognized by fdisk as significant, as seen in the final output of the pcommand.

<text of swap c command dialog and p command here>

There is a script that automates the generation of these commands for a particular device.