If you experience any difficulty in accessing content on our website, please contact us at 1-866-333-8917 or email us at support@hudsonvalleyhost.com and we will make every effort to assist you.

By
 
December 3, 2018

UNDERSTANDING LINUX PARTITIONS

  Linux
Deluxe company -

Coming from the Windows world of C: and D:, I was initially flummoxed by the various partitions in the Linux world. I remember abandoning my first Linux Mint desktop installation when it asked me to allocate space for various partitions such as swap and boot. I think there may be others who faced a similar situation. I think this article will give you a brief idea of the various partitions on Linux.

Partitions & Partition Tables

Partitioning is a way to divide a single hard drive into many logical drives. A partition is treated as an independent drive and refers to a contiguous set of blocks on the said drive. Paritions host a certain kind of file system which is a numeric code associated with the partition type. For e.g., a Linux swap partition has the code 0x82. A partition table is an index that identifies how the hard drive is split into the different partitions.

Primary partitions are the initial partitions installed as part of the boot sector (typically 512 bytes). Logical partitions are sub partitions of the primary partitions which must be contiguous. The primary partition that contains logical partitions is called an extended partition.

There are two types of partition tables – Master Boot Record (MBR) and GUID Partition Table (GPT). The former is something you may have heard from the times of MS-DOS, GPT was introduced in the late 90s to overcome the limitations inherent in MBR.

Partitioning using MBR limited partitions to only 4 and each partition could not exceed 2TB in size. The number 4 may seem sufficient, but causes problems when multiple OS needs to be installed with each Operating system requiring a primary partition of its own. Further, MBR has data integrity issues as it is a single data structure could be damaged by hardware failure or carelessness. Following the primary partitions, additional logical partitions are defined in a linked-list structure. If one partition is damaged, the remaining logical partitions cannot be accessed. There are no inbuilt error-detection capabilities, so a faulty MBR is hard to detect.

GPT was defined as part of Intel’s Extensible Firmware Interface (EFI) which later evolved into the Unified EFI (UEFI) standard. GPT uses 64-bits for logical block addresses, twice of what MBR uses, exponentially increasing supported partition sizes to 8 ZB (8,600,000,000 TB). GPT is more reliable as it uses two locations for storing its data structures – at the beginning and at the end of the disk. This improves the chances of reliability in case something fails. You can now define 128 partitions though this can be changed if the software used to create the partitions allows it. Finally, GPT allows you to define partitions in a way that is human readable. As an administrator, you can define different file systems to be on different partitions that can be easily identified such as /home, /tmp and /boot

Having multiple partitions on your disk can greatly improve the efficiency of the disk. Based on the contents and average size of your files, you can choose an optimum block size for the partition. For e.g., if you have a large number of small files lesser than a kilobyte in size, having a partition with 4096 bytes as the block size means that storing each file wastes about 3KB.

To list the partitions on your system, use the command

# fdisk -l

OS manuals generally recommend creating the following partitions

  • A swap partition which is used to support virtual memory. Data is written into the swap partition when the RAM is running out of space to store data. The minimum size for the swap partition is 265MB. However, with the growing RAM sizes, it is crucial to allocate the right swap size when setting up your machine. A oft-quoted reference is twice the RAM size, but on a 64GB RAM system, allocating 128GB of disk space as swap is wasteful.

The recommended swap size is more of a function of system memory workload than of the actual RAM available to the system.

System RAM

Recommended SWAP space

<= 2GB

2 times the amount of RAM

Between 2 and 8 GB

Equal to the RAM size

Greater than 8GB

At least 4GB of RAM

Since swap is used to store virtual memory, it is recommended to allocate the swap partition on the fastest device. If you had a HDD and a SSD connected to the system, chose the SSD device to setup the swap partition

  • A /boot partition is used to store the operating system kernel and other files that are used in the bootstrap process. You should look to assign around 250MB for this partition which would be sufficient in most cases. It is also important to note that if you use hardware RAID and data is served by a RAID card, some BIOS do not allow for booting from the RAID array. A separate /boot partition is required outside of the RAID setup.
  • A root partition that is designed as “/”. Typically you will need between 3 and 5GB of space for this partition.
  • A home partition which is used to store user information and should ideally be separated from system data. An advantage of having the /home on a separate partition is that you can upgrade and reinstall your OS without losing user data.

You can also create separate partitions for other folders such as /tmp, /usr and /var. A separate partition for these folders is useful to prevent bad scripts from eating up disk space or placing your entire file system under a denial of service attack.

Subscribe Email