File Systems / Partitions

The disk can be divided into smaller, separate pieces called Partitions

Partitions on an Intel PC Extended partition

Partition Example: a machine with a SCSI drive

# sfdisk -l

Disk /dev/sda: 522 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls   #blocks   Id  System
/dev/sda1   *      0+    459     460-  3694918+  83  Linux
/dev/sda2        460     521      62    498015    5  Extended
/dev/sda3          0       -       0         0    0  Empty
/dev/sda4          0       -       0         0    0  Empty
/dev/sda5        460+    480      21-   168651   82  Linux swap
/dev/sda6        481+    521      41-   329301   83  Linux
In the above example partitions 3 and 4 are empty. Any idea why?

Why is the first logical partition always hda5?

Here is an example of an IDE disk:

# sfdisk -l -x

Disk /dev/hda: 4111 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls   #blocks   Id  System
/dev/hda1   *      0+     12      13-   104391   83  Linux
/dev/hda2         13     535     523   4200997+  83  Linux
/dev/hda3        536     666     131   1052257+  82  Linux swap
/dev/hda4        667    4110    3444  27663930    5  Extended

/dev/hda5        667+   1189     523-  4200966   83  Linux
    -           1190+   1451     262-  2104484    5  Extended
    -            667     666       0         0    0  Empty
    -            667     666       0         0    0  Empty

/dev/hda6       1190+   1451     262-  2104483+  83  Linux
    -           1452+   1974     523-  4200966+   5  Extended
    -           1190+   1190-      0         0    0  Empty
    -           1190+   1190-      0         0    0  Empty

/dev/hda7       1452+   1974     523-  4200966   83  Linux
    -           1452+   1452-      0         0    0  Empty
    -           1452+   1452-      0         0    0  Empty
    -           1452+   1452-      0         0    0  Empty
Notice that each partition table has 4 entries: one logical partition, one extended partition, and two unused.

Why Partition?

Disk Organization

The disk controller is software that knows how to position the heads in the right location to access or write data. For example, the kernel needs to access cylinder 10, sector 5  on the disk. The controller knows to move the heads 2.398cm from the edge of the platter in order to access data.

Partitions and Mount Points

Hierarchical Structure

File Systems Mounted in the Directory Structure

|----------------------------------------------------------
|                                                         |
|  |-------------------------|                            |
|  |Root partition /dev/hda1 |                            |
|  |                         |                            |
|  | / ___________ /bin      | -------------> /dev/hda1   |
|  |        |_____ /usr      |                            |
|  |        |_____ /etc      |                            |
|  |        |_____ /sbin     |                            |--> hda
|  |        |_____ /boot     |                            |
|  |        |_____ /dev      |                            |
|  |        |_____ /lib      |                            |
|  |        |_____ /mnt      |                            |
|  |                |___ /master -------------> NFS mounted filesystem
|  |-------------------------|                            |
|           |----- swap        -------------> /dev/hda5   |
|           |_____ /home       -------------> /dev/hda2   |
|           |_____ /var        -------------> /dev/hda3   |
|---------------------------------------------------------|

|---------------------------------------------------------|
|           |_____ /export     -------------> /dev/hdb1   |
|           |----- swap        -------------> /dev/hdb2   |--> hdb
|---------------------------------------------------------|

The /etc/fstab file for this machine would look something like:

Device          Mount Point  FS Type    Options     Dump Fsck
/dev/hda1        /             ext2    defaults        1 1
/dev/hda2        /home         swap    defaults        0 0
/dev/hda3        /var          ext2    defaults        1 2
/dev/hdb1        /export       swap    defaults        0 0
/dev/hda5        swap          swap    defaults        0 0
/dev/hdb2        swap          swap    defaults        0 0
/proc            /proc         proc    defaults        0 0
/dev/fd0         /mnt/floppy   ext2    noauto,owner    0 0
/dev/cdrom       /mnt/cdrom    iso9660 noauto,owner,ro 0 0
112instructor:/export  /mnt/master  nfs  ro,auto,nouser  0 0

Back to you disk:

Information that defines the "physical disk geometry" for your hard disk

To figure out the number of bytes of data on your disk:

(# of cylinders) × (# heads) × (63 sectors/track) × (512 bytes/sector)

For my old IDE disk at home:

(3148 cyl) × (16 heads) × (63 sectors/track) × (512 bytes/sect)

1,624,670,208 bytes -->  1.6 GB