Partitions and the Partition Table

CS 321 2007 Lecture, Dr. Lawlor

So you've got a disk.  The disk stores bytes.  You can in theory access the raw disk (and some database systems do this for speed!), but it's way more common to build several layers of storage on top of the raw disk bytes:

Example: Windows Disk Manager

To get to the Windows Disk Manager, first right-click on "My Computer" and hit "Manage", then select "Disk Manager" near the bottom of the left-hand side list.  This shows you all your disks, and importantly all your partitions:

Window XP Partitoin Manager, showing partitions

The original design of the IBM PC's "boot sector" (the first 512 bytes of the disk) left room for only four "primary" partitions.  Since people running multiple operating systems often want more than this, you can also make an "extended" partition (in green above) that counts as a primary partition, but contains other smaller "logical drive" partitions inside of it.   You can also leave unpartitioned space on your disk, which can later be used to create new partitions.

If your partition table gets horribly screwed up, you may still be able to recover your partitions and all their data using a tool like TestDisk.

Example: Linux fdisk

The same disk viewed in Windows above can be examined in Linux like so:
root@dellawlor:/home/olawlor/class/cs321/lecture/fs_fat # fdisk /dev/hda
Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 6 48163+ de Dell Utility
/dev/hda2 * 7 4262 34186320 7 HPFS/NTFS
/dev/hda3 * 4263 7910 29302560 83 Linux
/dev/hda4 7911 9729 14611117+ 5 Extended
/dev/hda5 7911 8519 4891761 83 Linux
/dev/hda6 8520 9128 4891761 83 Linux
/dev/hda7 9129 9372 1959898+ 83 Linux
/dev/hda8 9373 9495 987966 82 Linux swap
/dev/hda9 9496 9520 200781 b W95 FAT32
/dev/hda10 9521 9545 200781 b W95 FAT32
/dev/hda11 9546 9570 200781 83 Linux
/dev/hda12 9571 9729 1277136 83 Linux

Command (m for help): q
Again, I've got a bunch of partitions.  /dev/hda2 is my Windows partition.  /dev/hda3 is my main Linux partition.  /dev/hda4 is my extended partition, which contains hda5 through hda12.

Boot Process

  1. Power flows into the CPU
  2. The CPU begins executing the BIOS, which is stored in flash ROM on your motherboard.
  3. The BIOS looks for a disk whose first sector ends with the two bytes "0xaa 0x55".  This is a "boot sector", or "master boot record".
  4. The BIOS executes the boot sector, which has to contain raw 16-bit mode x86 machine code.
  5. The boot sector code looks at the partition table (stored inside itself), and finds the boot loader on your boot partition.  This is usually NTLDR for Windows systems, or Grub or LILO for Linux.
  6. The boot loader finds the OS kernel on the disk.
  7. The OS kernel starts running, loads up the disks, starts processes, and the machine can then be used for real work.