Guide to Unix/Explanations/Partitioning Disks
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.
- On i386 hardware, fdisk partitioning is common. It is used by DOS, Windows, and Linux. The BIOS which boots the computer starts the Master Boot Record (MBR) on the disk. The MBR understands the fdisk format.
- On Macintoshes, the Apple partition map allows the disk to contain one or more Macintosh (HFS+ or the older HFS) partitions. The BIOS (Open Firmware) can boot the Macintosh without an MBR, because the BIOS can find bootloader files on HFS+ and HFS partitions.
- The *BSD systems can use an MBR with a *BSD partition map, but most configurations use a non-BSD partition map with a "slice" that contains a *BSD partition map and partitions.
MS-DOS or MBR partition maps (fdisk)
[edit | edit source]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:
- The master boot record (MBR) is not part of any partition. The MBR contains a bootstrap loader program and a basic partition table in a fixed location.
- The basic partition table is limited to four primary partitions. If you want more partitions, one of the primary partitions must be identified as an extended partition. The extended partition can be divided into logical partitions. For example, Windows might be installed on primary partitions 1 (drive C:) and 2 (drive D:). Linux might be using 3 partitions (root /, swap, and home /home). Root is on primary partion 3. Primary partition 4 is the extended partition, and contains swap and /home as logical partitions, and possibly extra space for future logical partitions.
- A primary partition might also be a *BSD slice. That means that it contains a *BSD disklabel and several *BSD partitions.
- One primary partition might be marked active. The default MBR boot loader (the one from MS-DOS and FreeDOS) boots the active primary partition. However, some MBR boot loaders like GRUB might give you a menu instead of booting the active partition.
- You can declare the type of each partition. Some systems use the type to find their filesystems. BSD uses the type to find its slice, but Linux ignores the types completely. Linux instead goes by its /etc/fstab file.
To manipulate fdisk partitions, look for a program called FDISK.EXE on DOS or fdisk on Linux.
Apple partition maps
[edit | edit source]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:
- Partition 1 contains the partition map.
- For some reason, Drive Setup insists on creating 128 MB of unused Apple_Free space as partition 2. Some older disks with Mac OS 9 drivers installed have several tiny partitions, starting at 2, which are only used by Mac OS 9 and older.
- You can create at least 17 partitions, and probably more.
- There is no Master Boot Record (MBR).
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
[edit | edit source]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.
|
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.
|
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.
|
Example
[edit | edit source]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
[edit | edit source]This section might need corrections.
The terms "slice" and "partition" are often defined as follows:
- A partition is an entry (filesystem or swap) in the BSD disklabel.
- A slice is the partition of the non-BSD partition map (like fdisk or Apple) which contains the BSD disklabel and partitions.
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:
- 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.
- 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.
- 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?
[edit | edit source]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?
[edit | edit source]The *BSD distros have different approaches for using non-BSD partitions, or having *BSD and a non-*BSD operating system on the same disk.
- If NetBSD sees an Apple partitioning map, it will assign letters to all of the HFS+ partitions and NetBSD partitions.
- If OpenBSD sees an Apple partitioning map, it will search for a partition of type "OpenBSD", and use the disklabel on that partition. If no disklabel exists, OpenBSD assigns letters to all "Apple_HFS" (HFS+) partitions, starting with letter 'i'. When creating a disklabel, one starts with the HFS+ partitions already in the disklabel. Then one adds OpenBSD partitions by dividing the "OpenBSD" Apple partition into several disklabel partitions, which is a form of secondary partitioning. Use disklabel -E to edit the disklabel.