The four main partitions on a disk drive are the boot partition, root partition, swap partition, and home partition. These partitions divide up the storage on a drive and allow different parts of the operating system and files to be separated from each other. Understanding what each partition is used for is important for setting up and maintaining a Linux system.
The Boot Partition
The boot partition contains the operating system kernel, bootloader, and other files necessary to boot the system. When a computer first turns on, it loads the bootloader from the boot partition, which then loads the Linux kernel into memory so the operating system can start.
The boot partition is usually small, only a few hundred megabytes, since it only needs to store the essential boot files. It is often flagged as bootable so the computer knows to load the bootloader from that partition.
On a Linux system, the boot partition will contain the GRUB or GRand Unified Bootloader. GRUB loads and passes control to the Linux kernel. The kernel initrd image may also reside on the boot partition.
Here are some key facts about the boot partition:
- Contains bootloader and kernel – GRUB bootloader files, Linux kernel image, and initrd initial RAM disk image are located on the boot partition.
- Small partition size – Usually between 100MB to 500MB, only needs to hold essential boot files.
- May be flagged as bootable – Partition marked as bootable so bootloader is loaded from that partition first.
- Formatted as ext2/ext3/ext4 – The boot partition is often formatted as ext2, ext3, or ext4 rather than other Linux file systems.
- Separate from root partition – Keeps boot files safely separated from root partition and operating system files.
Having a dedicated boot partition is beneficial since it prevents changes to other partitions from impacting the ability to boot into the Linux operating system.
The Root Partition
The root partition, denoted by a forward slash (/), contains the main Linux operating system files. This includes the directory structure, system configuration files, programs, libraries, and everything else needed to boot into the Linux system to a usable state.
Some of the key directories stored on the root partition include:
- /bin – Contains binary executable files for essential programs like cat, login, bash
- /boot – Holds some boot files, kernel initrd image, GRUB files
- /dev – Device files used to access devices on the system
- /etc – System configuration files reside in /etc, like fstab, passwd, hostname
- /lib – Library files used by binaries in /bin/ and /sbin/ directories
- /media – Mount points for removable media like USB drives
- /mnt – Temporary mount point for mounting file systems
- /opt – Optional application software packages
- /sbin – Essential system binaries like fsck, init, route
- /sys – Virtual system file system holding system hardware information
- /tmp – Temporary space where users and applications can write files
- /usr – User related programs and files
- /var – Variable data files like logs, databases, websites
The root partition is designated as the / mount point in Linux. Some key facts about the root partition:
- Contains operating system – All operating system files are on the root partition except for the bootloader.
- Mounted as read-write – The root partition must be mounted as read-write since system files change frequently.
- Always exists – Every Linux system has a root partition. A system cannot function without mounting the root partition.
- Larger partition size – The root partition often takes up most of the available disk space since it stores the operating system and user files.
- Formatted as ext3/ext4 – Linux root partitions typically use ext3 or ext4 file systems rather than Fat32 or NTFS.
- Represented by / – The root partition mount point is always / in the directory structure.
The contents of the root directory make up the core parts of the Linux operating system. All other mount points stem from the root partition.
The Swap Partition
The swap partition provides virtual memory for Linux. When the system needs more memory than is physically available in RAM, inactive pages in memory get swapped out to the swap partition on disk. This frees up that RAM for other processes to use.
The swap partition is an important component for Linux performance. Without swap space, a system could easily run out of memory which causes processes to crash. The key aspects of the swap partition include:
- Used as virtual memory – Pages of memory get swapped to disk when more space is needed in RAM.
- Often double RAM size – The swap partition size is often set to double the amount of RAM on the system.
- Reserved space – No files are stored on swap, only memory pages as needed.
- Formatted as swap – The swap partition is formatted with the Linux swap file system type.
- Enabled at boot – The swap partition must be enabled at boot time to be used.
- Mounted as swap – Swap partitions are enabled with the swapon command, not mounted.
The swap space is crucial for Linux performance. Without enough swap space, processes will be killed by the OOM killer if the system runs out of physical RAM space.
Some guidelines for sizing the swap partition:
Amount of RAM | Recommended Swap Size |
---|---|
Less than 2 GB | 2 x RAM |
2-8 GB | Equal to RAM |
8-64 GB | 0.5 x RAM |
64 GB or more | Workload Dependent |
For systems with smaller amounts of RAM, having a swap partition twice the size of RAM can prevent out of memory issues. For systems with large amounts of RAM, the swap partition can be smaller since physical RAM satisfies most memory requests.
The Home Partition
The home partition stores user files and documents. Under the Linux Filesystem Hierarchy Standard, user home directories are located under /home, for example /home/john for user john. The home partition is sometimes placed on a separate disk partition so it is kept separate from the operating system files.
Some key points about the home partition:
- Houses user files – User documents, photos, downloads, desktop and configuration files reside on the home partition
- Separate from root – Separating home from root partition protects user files if operating system needs reinstallation
- /home directory – User home directories are placed under the /home mount point
- Variable size – The home partition size depends on number of users and their storage requirements
- Private user data – Permissions on /home prevent other users from accessing files
- Backed up frequently – User files on home partition should be backed up regularly
The home partition stores user files separately from system files. This has several advantages:
- User files do not fill up the root partition and prevent operating system expansion
- Reinstalling the operating system does not overwrite user files and settings
- Permissions keep other users from accessing private data
- Backing up user data is simplified since it is stored in one partition
For desktop and laptop systems, dedicating an entire disk partition to user /home directories can improve performance, security, and recoverability.
Setting up Partitions
When installing Linux, partitions need to be set up on a storage drive. This involves dividing up the available space into separate partitions for /boot, / (root), swap, and /home based on requirements for that system.
Some things to consider when planning partition sizes:
- /boot – The boot partition only needs 100MB to 500MB in most cases. Don’t allocate more space than needed.
- / (root) – The root partition should get as much space as possible after /boot and swap partitions. Plan to have at least 10GB for the root partition.
- Swap – Size the swap partition based on the RAM on the system. For desktops, make swap 2 times RAM for less than 2GB of RAM. For systems with 2GB to 8GB RAM, make swap equal to RAM amount. For higher RAM use 0.5 x RAM.
- /home – Allocate as much space for /home as possible based on user storage requirements. Only make a separate /home if disk space is available.
The cfdisk or fdisk utilities can be used when installing Linux to create partitions on a new disk. The mkfs command will then format the partitions as ext4, ext3, or swap space.
An example partition layout using a 500GB disk:
Device | Partition | Type | Size |
---|---|---|---|
/dev/sda | /dev/sda1 | ext4 | 512MB |
/dev/sda | /dev/sda2 | swap | 8GB |
/dev/sda | /dev/sda3 | ext4 | 100GB |
/dev/sda | /dev/sda4 | ext4 | remainder |
This provides a 500MB /boot partition, 8GB swap, 100GB for root, and the rest for /home. The partitions then need to be mounted at the appropriate mount points by updating /etc/fstab.
Conclusion
The four standard partitions on a Linux system include:
- Boot partition – Contains bootloader and kernel, mounted at /boot
- Root partition – Houses the operating system, mounted at /
- Swap partition – Provides virtual memory for kernel, formatted as swap space
- Home partition – Stores user files under /home mount point
Using multiple partitions splits up the Linux operating system and user data onto separate sections of the disk. This improves security, organization, performance and recoverability of a Linux system.
The four partition layout is a tried and true approach for configuring disks on Linux and most distributions default to this partition scheme. Admins may customize partition sizes and locations during installation to suit their specific needs. However, following the standard four partition design ensures maximum compatibility and ease of use for most Linux systems.