No man was more foolish when he had not a pen in his hand, or more wise when he had - Samuel Johnson
In this article, I'll go over concepts for partitioning a Linux disk.
The major Linux distros provide installers that are capable of selecting a default partitioning layout with minimal user input. However, as with many default situations, you can often do somewhat better by taking time to understand what's involved and building your own Linux partitions.
To do this, you need to understand a little about disk partitions, Linux filesystems, and the Linux file hierarchy. If you plan to use a default partition layout, you can skip the rest of this article, if you wish.
Partitions
You will need at least a few additional disk partitions for Linux. The installers make defining them rather
painless. However, you'll be more comfortable with this easy process once you understand PC partitions.
PC hard disks can contain up to four Primary partitions, or up to three Primary partitions plus one Extended partition hosting multiple Logical partitions. Although legacy OS's give partitions drive letters such as C:, D:, etc., Linux refers to partitions by physical drive letter and a number. IDE disks are abbreviated as "hd" and SCSI disks denoted "sd", so Linux calls your first IDE disk "hda", the second "hdb", etc. Thus, Linux will know an IDE Windows C: drive as "hda1". Partitions are also assigned numbers according to the sequence they appear in the partition table(s), that is, in the order they are defined. This means that you should define partitions in order of ascending location on your disk -- low to high -- just to help you visualize how it's laid out later on.
There's one small exception to sequential numbering that's a consequence of the partitioning rules: the first three numbers are reserved for use by Primary partitions and the fourth for the Extended partition. So the first Logical partition on the first physical IDE disk will named "hda5" under Linux. You can use Primary partitions for Linux, but it's usually easier to use all Logical partitions. Logical partitions work just fine under Linux and they have the advantage of being defined in the Extended partition table: if it's damaged, Primary partitions should be okay.
Filesystems
Another concept you'll want to get familiar with prior to defining Linux partitions relates to filesystems. The
term "filesystem" refers to disk internal structure within a partition. A legacy OS will use filesystems like FAT16,
FAT32, or NTFS. The default filesystem for Linux is "ext2", which is a hierarchical non-journaled filesystem. Others
exist, too.
The "ext2" filesystem is fairly robust, but it has a weakness: if it is stopped abruptly -- by a power failure, etc. -- after reboot it's marked "dirty" and its internal integrity must be checked with a "fsck" run. A "fsck" pass on a large disk can take a while, and it often performs some filesystem repairs to correct internal structural errors. This can lead to files that were being written getting truncated or lost by "fsck".
For a personal Linux system, journaling filesystems are more secure than "ext2" because, as the term implies, they keep a log or journal of every sector written. If a journaled filesystem is stopped abruptly, recovery is automatic at the next reboot: the journal is compared and any sector that's missing from the filesystem is quickly recovered, without needing to check the entire filesystem for errors. This is a great solution.
There are several journaling filesystems you can use under Linux. A few of the common ones are "ext3", "reiserfs", and "jfs". I personally like "ext3" because it's based on the mature "ext2" and compatible with that, in that any "ext2" filesystem can be converted to "ext3" and back again, using simple commands. However, others prefer "reiserfs" or "jfs". You can research these and choose. But, pick some journaling filesystem.
File Hierarchy
Linux uses a unified, hierarchical directory structure, in contrast with legacy systems that use a volume-based
file hierarchy. What I mean here is that, under Windows, you need to know what volume (C:, D:,...) a file resides on to
select it: the file's physical location is literally part of it's name. In this, Linux reveals its descent from and
affinity with Unix. Both are closer to mainframes in this, but those have centralized catalogs instead of storing
directories intermingled with data files.
In Linux, all directories are attached to the root directory, identified by a forward-slash, "/". This file hierarchy is a directory tree, built from a single root. Here's a listing of the second-level directories in a typical client PC Linux root directory, with contents descriptions:
/bin/ ---- system binaries
/boot/ --- system kernel, etc.
/data/ --- a user defined directory
/dev/ ---- system device tree
/etc/ ---- system configuration
/home/ --- users' subdirectories
/initrd/ - system initialization
/lib/ ---- system libraries
/mnt/ ---- system mount points
/opt/ ---- optional software
/proc/ --- system data
/root/ --- system root-user
/sbin/ --- system scripts
/tmp/ ---- system temporary
/user/ --- system user security
/usr/ ---- applications software
/var/ ---- system variables
The root directory "/" lives in the root partition, but some directories are in other partitions. During system initialization -- or in response to a mount command issued by the root user (or a system process) -- the other partitions or removable devices are attached (i.e., "mounted") to directory entries in the root directory tree. To see how initialization does this, here is a summary of a Linux file system table /etc/fstab:
/dev/hda6 /
/dev/hda5 /boot
/dev/hda7 /home
/dev/hda8 /var
/dev/hda9 swap
/dev/hda10 /usr
/dev/hda11 /data
I deleted system entries, parameters, and removable devices to highlight the partitions defined along with the mount points. See how it works?
Partition Layout
Having briefly reviewed disk partitions, filesystems, and the Linux file hierarchy, two questions remain. Why
might you want to define your own partition layout? What partitions configuration might be an optimum?
Some reasons for defining more partitions than a default layout include security, isolation, and convenience. Let me address each of these.
It's a common security precaution to set the /boot partition read-only, which puts another barrier in the way of anyone using your Linux system (including you) who might try to replace the Linux kernel or other boot files. Isolating the /boot files from the root partition also virtually eliminates the possibility that any error might overwrite the kernel. If you have an older hard disk with more than 1024 cylinders occupied by a legacy OS, you might need a small /boot partition within the first 1024 cylinders to boot Linux easily, but it depends on your configuration.
Isolating some directories like /home and /var from your root partition can prevent file downloads and processes like logging, traces, etc. from fragmenting or filling up the root partition. Filling up your system's root partition can cause bad things to happen, maybe a kernel panic. It is a good idea to isolate your /usr directory on a separate partition as well, since this is where all your applications reside, and it gets lots of activity during installation, and as you add and upgrade packages.
Having a separate /home partition is also convenient, as is a partition to keep your own work files like documents, spreadsheets, images, MP3s, etc. Your /home directory contains your desktop configuration and mail files, so you can keep those more easily across system upgrades if they are in a separate partition. And your /home and working directories are easy to replicate or backup if you have them on separate partitions.
Of course, you can always just use the default partitioning set up by an installer. Or you can simply define a swap partition, at least as large as the amount of memory you have, then set up a single root partition on the rest of your hard disk. However, here's what I use, for the reasons I've mentioned, showing the partitions defined, size, and space used:
Filesystem 1M-blocks - Used - Available - Use% - Mounted on
/dev/hda6 ------ 236 --- 51 ------- 173 -- 23% - /
/dev/hda5 ------- 31 ---- 4 -------- 26 -- 11% - /boot
/dev/hda7 ------ 749 -- 288 ------- 462 -- 39% - /home
/dev/hda8 ------ 365 --- 71 ------- 276 -- 21% - /var
/dev/hda9 ------ 488 --- 85 ------- 403 -- 17% - swap
/dev/hda10 ---- 3930 - 2045 ------ 1687 -- 55% - /usr
System Subtotal 5799 - 2544 ------ 3027 -- 44%
/dev/hda11 ---- 2795 - 2373 ------- 281 -- 90% - /data
Total --------- 8594 - 4917 ------ 3308 -- 57%
(1M-block = 1,048,576 bytes)
Covering these concepts and ideas for partitioning took more space than I'd anticipated. In the next article I'll cover the basic installation options presented by a major Linux distribution and then I'll go through an entire installation process from start to finish. Really I will. µ
See Also:
Installing Linux is easy, really!
Installing Linux is easy, continued
Installing Linux is easy, with care