start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

44.4. Disk Partitioning

A physical disk can be divided into smaller blocks, called partitions. Unix disk devices operate on partitions, where each device is a single partition. The simplest configuration is one big partition for the entire disk.

The advantage to having filesystems on separate partitions is that different parts of your operating system are somewhat protected from each other. If your users have filled up /home, programs writing log files in /var aren't affected if /home and /var are separate partitions. If your disk gets corrupted, only the corrupted partition is damaged. The disadvantage is that, in most cases, if you mistakenly allocated too little disk space for a partition, you can't steal space from your /var to give you more room on /home once your system is set up.

On non-PC hardware, partitioning is generally simple enough; use format or disklabel to write a partition table onto the disk. Traditionally, partitions are named with a letter following the device name, for example, /dev/ad0a, /dev/ad0c and so forth. By convention, partition a is for a root filesystem (/), b is for swap space, c represents the whole disk, and so forth. Of course, every current platform changes this in some way. Check the manpages for the various tools mentioned for more details on what to do for your specific platform.

Solaris's disk device naming scheme is /dev/dsk/c?t?d?s?, where each ? is a number. The c is for controller, the t for target (a physical address on the controller), the d for disk, and the s for slice, another concept like partition. In this case, rather than partition c representing the whole disk, slice 2 does. This set of four numbers uniquely identifies a specific partition (slice) on a specific disk. Solaris uses format to manipulate partition tables.

On PC hardware, it's a bit more complicated, because the PC BIOS has a concept of partitions built into its understanding of disks. Unixes like Linux and FreeBSD that run on this hardware need to coexist with this partition table, especially if you want a machine that can dual-boot Unix and Windows. The BIOS understands no more than four primary partitions on each disk, due to the way it addresses partitions. To get around this limitation, one primary partition can be set to be an extended partition, which can then serve as a container for a different partition addressing scheme. Partitions within an extended partition are called logical partitions and have a few restrictions, but they aren't limited to four. The BIOS requires a primary partition to boot; it can't boot from a logical partition.

Linux names the IDE hard drives /dev/hda through /dev/hdd and the SCSI drives /dev/sda through /dev/sdg. Higher letters are possible with extra controllers. The device name itself represents the whole disk, as partition c and slice 2 did above. Linux uses the BIOS nomenclature and uses primary partitions, extended partitions and logical partitions. Primary partitions get partition numbers one through four, and thus partition two on the second IDE disk would be /dev/hdb2. Logical partitions get numbers higher than four. Linux uses fdisk to manipulate partition tables.

FreeBSD calls the BIOS primary partitions slices and doesn't use extended or logical partitions. Its own partitions within a slice are then just called partitions. This has the advantage of allowing a fairly traditional a through h partitioning, which just lives in a particular slice. So the swap partition within the second BIOS slice of the first IDE drive would be /dev/ad0s2b. FreeBSD uses fdisk to deal with slices and disklabel to manipulate partition tables.

As you can see, each platform has its own idiosyncrasies, but each unambiguously defines a scheme for uniquely referring to a particular partition on a particular disk. This lets us decide where we want our filesystems and refer to them in mount commands and in /etc/fstab (Section 44.5).

-- DJPH



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.