Guide to Unix/Explanations/Partitioning Disks

< Guide to Unix < Explanations

This chapter describes different types of partitioning maps and the programs used to adjust partitioning maps.

A partition map divides the disk into partitions. Each partition can be formatted separately. Partitions are normally used for filesystems, which hold computer files, or swap, which is used as additional (but slower) memory by operating systems. The chapter for Filesystems and Swap described how Unix-like systems use partitions.

The Unix-like system is often installed on the same disk as some other operating system. In that case, both the Unix-like kernel and the other system must understand the same kind of partioning map.

MS-DOS or MBR partition maps (fdisk)

This section might need corrections.

The original IBM PC defined a simple partition map format for MS-DOS. Enshrined in the BIOS implementation of PC-style computers, this partition map is used by DOS and Windows. It is also used by most Linux systems on PC-style hardware for BIOS compatibility, and because Linux is often installed on the same disks as DOS and Windows. To distinguish this older partitioning format from newer formats available for Windows, Microsoft now uses the term MBR partitioning – so-called because the partition table is contained within the master boot record (MBR) – to describe the MS-DOS format. Much literature refers to this partitioning format by the terms DOS and MS-DOS.

With the MBR partition map:

To manipulate fdisk partitions, look for a program called FDISK.EXE on DOS or fdisk on Linux.

Apple partition maps

Mac OS hard disks normally contain Apple partioning maps. These maps are created when Apple's Drive Setup program was used to format the disk. With these partition maps:

To manipulate Apple partitions, go to a shell prompt on Mac OS X or *BSD and use pdisk or diskutil. Most GNU/Linux systems now call that same program mac-fdisk for some reason.

Partition Types

Actually, partition types on Apple partition maps can be arbitrary strings, for example "OpenBSD". Some operating systems are still stuck with "Apple_UNIX_SVR2" though.

Apple_partition_map This partition contains the partition map. It exists so that no other partition overlaps the partition map.
Mac OS classic drivers These tiny partitions would be after the partition map, but most disks now lack them. Mac OS 9 and earlier would load a device driver for the disk from these partitions. All other systems, including Mac OS X, do not use them.
Apple_HFS This is an HFS+ or HFS partition. Mac OS mounts all partitions of this type (unless the HFS do-not-mount flag is set). This might also be an MS-DOS format partition; Mac OS can also mount those.
Apple_UFS This is a UFS partition mounted by Mac OS X.
  • It has its own Apple-format disklabel and separate boot partition (Apple_Boot? not Apple_Bootstrap) in case someone copies a bootable copy of Mac OS X to the partition.
  • Especially with newer versions of Mac OS X, there is almost never a reason to use Apple_UFS. Use HFS+ instead. Trying to use Apple_UFS partitions with OpenBSD can corrupt data.
OpenBSD This is the OpenBSD slice. A disk must have zero or one of these.
Apple_Bootstrap The BIOS (Open Firmware) can boot from this partition, but Mac OS will not mount it. This partition type is used by "ybin" to contain "yaboot", the Linux bootloader. It can also contain an OS-menu with Mac OS 9, Mac OS X, and GNU/Linux as possible entries.
Apple_UNIX_SVR2 Nominally, it is an A/UX partition for Apple's port of SVR2 to the 68k Mac. However, Apple borrowed this partition type for their dualithic Linux for PowerPC Mac. Both Apple systems are obsolete, but now both Linux and NetBSD are using this partition type.
  • Using NetBSD's pdisk, you can flag two Apple_UNIX_SVR2 partitions as root and swap partitions. These become "a" and "b" when you boot NetBSD.
  • It is confusing if you have Linux and NetBSD on the same disk.
Apple_Free Map editors like pdisk create this "partition" whenever partitions are deleted. An "Apple_Free" partition is just unused space. There is usually one big "Apple_Free" partition.
  • Drive Setup on Mac OS X also insists on wasting 128 MB on an Apple_Free partition between the Apple_partion_map and the first Apple_HFS. If careful, one can use the 128 MB as swap for OpenBSD.

Example

On the example system, we use "pdisk" on OpenBSD to see the partition map. We run the "pdisk /dev/rwd0c" command on OpenBSD. On Mac OS X the command would be "pdisk /dev/disk0". Most Linux distros now give the name "mac-fdisk" to "pdisk", so the command would be "mac-fdisk /dev/hda". We use the pdisk command "p" to print the partition map and then "q" to quit.

# pdisk /dev/rwd0c
Edit /dev/rwd0c -
Command (? for help): p

Partition map (with 512 byte blocks) on '/dev/rwd0c'
 #:                type name                   length   base     ( size )
 1: Apple_partition_map Apple                      63 @ 1
 2:     Apple_Bootstrap untitled                 1954 @ 50331712
 3:           Apple_HFS Apple_HFS_Untitled_1 24903680 @ 262208   ( 11.9G)
 4:             OpenBSD OpenBSD              25165824 @ 25165888 ( 12.0G)
 5:     Apple_UNIX_SVR2 untitled             24064454 @ 50333666 ( 11.5G)
 6:          Apple_Free Extra                  262144 @ 64       (128.0M)
 7:     Apple_UNIX_SVR2 swap                  1099416 @ 74398120 (536.8M)
 8:          Apple_Free Extra                41712704 @ 75497536 ( 19.9G)

Device block size=512, Number of Blocks=117210240 (55.9G)
DeviceType=0x0, DeviceId=0x0

Command (? for help): q
#

BSD slices and partitions

This section might need corrections.

The terms "slice" and "partition" are often defined as follows:

The BSD partition map is called a disklabel. In the following discussion, "partition map" refers to a non-BSD partition map which is not a disklabel.

BSD partitioning is special because on a disk with *BSD installed, 'a' must be root and 'b' if it exists must be swap. The disklabel indicates the locations, types, and letters of all partitions. Because of these special traits, BSD disklabels are confined to slices on any disks that are also used by non-BSD operating systems. This leads to three situations when a disk is used with BSD:

  1. The disk has a partition map and a disklabel. The partition map is at the beginning of the disk (possibly after the MBR). One of the partitions is a BSD slice. The disklabel is at the beginning of the BSD slice. The *BSD system will use the disklabel while other systems use the partition map. A disk with OpenBSD/macppc installed uses this configuration.
  2. The disk has a partition map but no disklabel. If the disk is used with *BSD, the BSD kernel generates a partition map, assigning letters to all recognized types of partitions. With Apple partition maps, OpenBSD/macppc only recognizes Apple_HFS partitions. NetBSD/macppc recognizes both Apple_HFS and NetBSD (Apple_UNIX_SVR2) partitions, so NetBSD/macppc installations do not need a disklabel.
  3. The disk has only a disklabel. The disklabel is at the beginning of the disk, possibly after the MBR, and the entire disk is reserved to *BSD. Only *BSD can use this disk.

Is there room for the disklabel?

To make room for a disklabel, all UFS/FFS partitions leave the first bytes unused. Thus you can put a root UFS/FFS partition directly at the beginning of the disk (except the MBR) and still have room for a disklabel.

All UFS/FFS partitions must be listed in a disklabel to be useful. Mac OS X will put an Apple-specific disklabel on all Apple_UFS partitions because those are not listed in a BSD disklabel.

How does BSD read a non-BSD partition map?

The *BSD distros have different approaches for using non-BSD partitions, or having *BSD and a non-*BSD operating system on the same disk.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.