File Systems / Partitions
The disk can be divided into smaller, separate pieces
called Partitions
-
particularly important in dual booting (windows will own
some partitions and Linux others)
-
partitions also can be used to separate file systems owned
by the same OS
-
partition refers to separated spaces
Partitions on an Intel PC
-
The partition table can define only 4 partitions
-
4 primary partitions or 3 primary partitions
and one extended partition
-
logical drives can be added to extended partitions
-
extended partitions by themselves cannot be mounted
Extended partition
-
provides a way to define more than 4 partitions on a single
disk
-
an extended partition is like a drive within a drive
-
contains a linked list of partition table sectors for the
logical
drives within it
-
Advanced Concept: the first table describes three primary
partitions, the extended partition and the location of the next partition
table sector
Partition Example: a machine with a SCSI drive
sfdisk options
-
-l : list the partitions of a device
-
-x : show the extended partitions
# 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?
-
Helps you organize your data
-
Makes backups simpler
-
Makes upgrades simpler
-
Can improve performance
-
put swap partition on a different disk
-
Be careful, this is a can be a destructive process!
-
make sure you plan first and understand thoroughly what you
are doing
Disk Organization
Platters
-
Several platters are stored one on top of another
-
Data recorded on both sides
-
One arm between every two platters with two read/write heads
Tracks
-
Surface of platter divided into concentric circles (tracks)
-
Each track divided into sectors
-
A sector is the smallest addressable unit of a disk
Cylinders
-
Stack of tracks (or rings) directly above and below each
other is a cylinder
-
Data on a cylinder accessed without moving the arm
Sectors
Seek
-
Arm movement is a disk seek
-
The slowest part of physically accessing data from disk
The Hard-Disk Drive
Like a miniature clean-room on the inside. Air is
drawn into the hard drive through a filter and circulated. This creates
a positive pressure inside the drive that helps prevent contaminants from
entering the drive case.
The Platters
Inside a hard-disk drive you will see platters sitting
on a spindle. Each platter has two read/write record heads-one for each
side of the platter. These heads are responsible for aligning the magnetic
particles in such a way that data can be recorded and read. The head
does not actually come into direct contact with the platter to write or
read the data.
A small electrical motor is needed to drive the platter.
The
fast spinning of the platter helps create a cushion of air keeping the
record head aloft. The head usually rides about 0.5 microns above the
platter-a distance smaller than the diameter of a human hair.
Format of the Platter
The tracks, or concentric magnetic grooves, are placed
onto the platter with the read/write head. This occurs when your hard drive
is formatted. Each track is then divided into sectors (see diagram).
Each sector can hold 512 bytes of data.
Disk Controller
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
-
The top of the structure is the root (/) directory
-
Under the root are directories critical to system operation
$ ls /
bin dev lost+found proc sbin usr
boot etc home lib mnt opt root tmp var
Below I highlighted the filesystems which I recommend
occupying their own partition.
swap partition
-
Swap partitions are used to support virtual memory.
-
The minimum size of your swap partition should be twice the
amount of RAM.
-
If you have a separate disk, you could configure swap space
on that disk as well
-
spreads the disk activity over two disks and improve the
performance
-
set the priority of each swap area to the same value for
this to work.
root partition (/)
-
The root filesystem is at the top of the directory structure.
-
Underneath / are directories used by your system to boot
the system, tools to manage the system, log files, user home directories
config files, etc.
-
The size of the root partition depends completely on how
you slice the rest of your disk. It should be about 150 MB if you intend
to create a separate /usr, /var, and /home partition.
/etc filesystem
-
Contains system configuratoin files used by system administrators.
-
Usually lives on root partition.
-
Small in size.
/usr filesytem
-
The /usr partition is where much of the software on a Linux
system resides.
-
This partition should be no smaller then 300MB for minimum
installation
-
The entire distribution requires nearly 4 GB of space!
-
If possible, be generous with the /usr partition.
-
Most RPM-based packages are installed under /usr
/sbin filesystem
-
typically mounted on the root partition
-
Contains system utilities needed for system startup
/home partition
-
This is where users' home directories go.
-
On a multiuser system it is good to create a separate partition
for your users.
/usr/local filesystem
-
Typically this filesystem contains software that is not available
as an RPM package.
-
The size depends on the amount of additional software you
anticipate putting on your system.
-
You can make the /usr partition large to accommodate /usr/local
or create a separate partition for /usr/local.
/usr/src filesystem
-
Linux Kernel Sources -- The complete sources for the Linux
kernel are stored here
-
Sources For RPM-Based Packages
-
If a source package file (aka SRPM) is installed, the files
are stored here and often packages are built here.
-
Keep this in mind when sizing /usr.
/tmp filesystem
-
The /tmp filesystem is for temporary files.
-
Creating a partition dedicated to /tmp is a good idea for
larger, multiuser systems or network server machines.
-
The reason is that many active users can fill the root partition
(/), if /tmp is located there.
-
Reserving 150 MB for /tmp is a good place to start. Bigger
is better
/var partition
-
You system will write to log files in /var/log
-
Files queued for printing will normally be written to /var/spool
-
User email is also stored in /var/mail
-
Web pages and FTP file are normally stored under /var
-
It is best to make /var its own partition.
-
300 MB, if you can spare it, is a good starting point.
/opt filesytem
-
Most often found on Solaris machines
-
Some third-party software is designed to install itself under
/opt.
-
Software that attempts to install itself under /opt will
end up on the root partition if you do not make a separate partition.
/boot partition
-
All the files LILO or Grub need to access (at boot time)
are in the /boot directory.
-
including the Linux kernel which is about 2 megabytes.
-
You may need to locate the physical partition ahead of the
1023rd cylinder boundary on your disk
-
30 MB should be plenty for the /boot partition
File Systems Mounted in the Directory Structure
-
All the directories that live directly under / live
on the root partition.
-
such as /etc, /sbin, /usr, /boot, /home, /export, etc.
-
Some of these directories may be mount points and have partitions
mounted on them
-
these partitions contain other filesystems
|----------------------------------------------------------
|
|
| |-------------------------|
|
| |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
|---------------------------------------------------------|
-
Remember that that a partition is a physical separation of
space on a disk.
-
In the above example, /home is a mount point for /dev/hda2.
-
The directory /home must first be created under /
-
which provides a mount point for the device.
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
-
bytes per sector (typically 512 bytes)
-
sectors per track (typically 63)
-
number of cylinders (variable -- lots on the newer big disks
-
number of heads (variable)
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