Linux Professional Institute Learning Logo.
Skip to main content
  • Home
    • All Resources
    • LPI Learning Materials
    • Become a Contributor
    • Publishing Partners
    • Become a Publishing Partner
    • About
    • FAQ
    • Contributors
    • Roadmap
    • Contact
  • LPI.org
102.1 Lesson 1
Topic 101: System Architecture
101.1 Determine and configure hardware settings
  • 101.1 Lesson 1
101.2 Boot the system
  • 101.2 Lesson 1
101.3 Change runlevels / boot targets and shutdown or reboot system
  • 101.3 Lesson 1
Topic 102: Linux Installation and Package Management
102.1 Design hard disk layout
  • 102.1 Lesson 1
102.2 Install a boot manager
  • 102.2 Lesson 1
102.3 Manage shared libraries
  • 102.3 Lesson 1
102.4 Use Debian package management
  • 102.4 Lesson 1
102.5 Use RPM and YUM package management
  • 102.5 Lesson 1
102.6 Linux as a virtualization guest
  • 102.6 Lesson 1
Topic 103: GNU and Unix Commands
103.1 Work on the command line
  • 103.1 Lesson 1
  • 103.1 Lesson 2
103.2 Process text streams using filters
  • 103.2 Lesson 1
103.3 Perform basic file management
  • 103.3 Lesson 1
  • 103.3 Lesson 2
103.4 Use streams, pipes and redirects
  • 103.4 Lesson 1
  • 103.4 Lesson 2
103.5 Create, monitor and kill processes
  • 103.5 Lesson 1
  • 103.5 Lesson 2
103.6 Modify process execution priorities
  • 103.6 Lesson 1
103.7 Search text files using regular expressions
  • 103.7 Lesson 1
  • 103.7 Lesson 2
103.8 Basic file editing
  • 103.8 Lesson 1
Topic 104: Devices, Linux Filesystems, Filesystem Hierarchy Standard
104.1 Create partitions and filesystems
  • 104.1 Lesson 1
104.2 Maintain the integrity of filesystems
  • 104.2 Lesson 1
104.3 Control mounting and unmounting of filesystems
  • 104.3 Lesson 1
104.5 Manage file permissions and ownership
  • 104.5 Lesson 1
104.6 Create and change hard and symbolic links
  • 104.6 Lesson 1
104.7 Find system files and place files in the correct location
  • 104.7 Lesson 1
How to get certified
  1. Topic 102: Linux Installation and Package Management
  2. 102.1 Design hard disk layout
  3. 102.1 Lesson 1

102.1 Lesson 1

Certificate:

LPIC-1

Version:

5.0

Topic:

102 Linux Installation and Package Management

Objective:

102.1 Design hard disk layout

Lesson:

1 of 1

Introduction

To succeed in this objective, you need to understand the relationship between disks, partitions, filesystems and volumes.

Think of a disk (or storage device, since modern devices do not contain any “disks” at all) as a “physical container” for you data.

Before a disk can be used by a computer it needs to be partitioned. A partition is a logical subset of the physical disk, like a logical “fence”. Partitioning is a way to “compartmentalize” information stored on the disk, separating, for example, operating system data from user data.

Every disk needs at least one partition, but can have multiple partitions if needed, and information about them is stored in a partition table. This table includes information about the first and last sectors of the partition and its type, as well as further details on each partition.

Inside each partition there is a filesystem. The filesystem describes the way the information is actually stored on the disk. This information includes how the directories are organized, what is the relationship between them, where is the data for each file, etc.

Partitions cannot span multiple disks. But using the Logical Volume Manager (LVM) multiple partitions can be combined, even across disks, to form a single logical volume.

Logical volumes abstract the limitations of the physical devices and let your work with “pools” of disk space that can be combined or distributed in a much more flexible way than traditional partitions. LVM is useful in situations where you would need to add more space to a partition without having to migrate the data to a larger device.

In this objective you will learn how to design a disk partitioning scheme for a Linux system, allocating filesystems and swap space to separate partitions or disks when needed.

How to create and manage partitions and filesystems will be discussed in other lessons. We will discuss an overview of LVM in this objective, but a detailed explanation is out of the scope.

Mount Points

Before a filesystem can be accessed on Linux it needs to be mounted. This means attaching the filesystem to a specific point in your system’s directory tree, called a mount point.

When mounted, the contents of the filesystem will be available under the mount point. For example, imagine you have a partition with your users' personal data (their home directories), containing the directories /john, /jack and /carol. When mounted under /home, the contents of those directories will be available under /home/john, /home/jack and /home/carol.

The mount point must exist before mounting the filesystem. You cannot mount a partition under /mnt/userdata if this directory does not exist. However if the directory does exist and contains files, those files will be unavailable until you unmount the filesystem. If you list the contents of the directory, you will see the files stored on the mounted filesystem, not the original contents of the directory.

Filesystems can be mounted anywhere you want. However, there are some good practices that should be followed to make system administration easier.

Traditionally, /mnt was the directory under which all external devices would be mounted and a number of pre-configured anchor points for common devices, like CD-ROM drives (/mnt/cdrom) and floppy disks (/mnt/floppy) existed under it.

This has been superseded by /media, which is now the default mount point for any user-removable media (e.g. external disks, USB flash drives, memory card readers, optical disks, etc.) connected to the system.

On most modern Linux distributions and desktop environments, removable devices are automatically mounted under /media/USER/LABEL when connected to the system, where USER is the username and LABEL is the device label. For example, a USB flash drive with the label FlashDrive connected by the user john would be mounted under /media/john/FlashDrive/. The way this is handled is different depending on the desktop environment.

That being said, whenever you need to manually mount a filesystem, it is good practice to mount it under /mnt. The specific commands to control the mounting and unmounting of filesystems under Linux will be discussed in another lesson.

Keeping Things Separated

On Linux, there are some directories that you should consider keeping on separate partitions. There are many reasons for this: for example, by keeping bootloader-related files (stored on /boot) on a boot partition, you ensure your system will still be able to boot in case of a crash on the root filesystem.

Keeping user’s personal directories (under /home) on a separate partition makes it easier to reinstall the system without the risk of accidentally touching user data. Keeping data related to a web or database server (usually under /var) on a separate partition (or even a separate disk) makes system administration easier should you need to add more disk space for those use cases.

There may even be performance reasons to keep certain directories on separate partitions. You may want to keep the root filesystem (/) on a speedy SSD unit, and bigger directories like /home and /var on slower hard disks which offer much more space for a fraction of the cost.

The Boot Partition (/boot)

The boot partition contains files used by the bootloader to load the operating system. On Linux systems the bootloader is usually GRUB2 or, on older systems, GRUB Legacy. The partition is usually mounted under /boot and its files are stored in /boot/grub.

Technically a boot partition is not needed, since in most cases GRUB can mount the root partition (/) and load the files from a separate /boot directory.

However, a separate boot partition may be desired for safety (ensuring the system will boot even in case of a root filesystem crash), or if you wish to use a filesystem which the bootloader cannot understand in the root partition, or if it uses an unsupported encryption or compression method.

The boot partition is usually the first partition on the disk. This is because the original IBM PC BIOS addressed disks using cylinders, heads and sectors (CHS), with a maximum of 1024 cylinders, 256 heads and 63 sectors, resulting in a maximum disk size of 528 MB (504 MB under MS-DOS). This means that anything past this mark would not be accessible on legacy systems, unless a different disk addressing scheme (like Logical Block Addressing, LBA) was used.

So for maximum compatibility, the boot partition is usually located at the start of the disk and ends before cylinder 1024 (528 MB), ensuring that no matter what, the machine will be always able to load the kernel.

Since the boot partition only stores the files needed by the bootloader, the initial RAM disk and kernel images, it can be quite small by today’s standards. A good size is around 300 MB.

The EFI System Partition (ESP)

The EFI System Partition (ESP) is used by machines based on the Unified Extensible Firmware Interface (UEFI) to store boot loaders and kernel images for the operating systems installed.

This partition is formatted in a FAT-based filesystem. On a disk partitioned with a GUID Partition Table it has a globally unique identifier of C12A7328-F81F-11D2-BA4B-00A0C93EC93B. If the disk was formatted under the MBR partitioning scheme the partition ID is 0xEF.

On machines running Microsoft Windows this partition is usually the first one on the disk, although this is not required. The ESP is created (or populated) by the operating system upon installation, and on a Linux system is mounted under /boot/efi.

The /home Partition

Each user in the system has a home directory to store personal files and preferences, and most of them are located under /home. Usually the home directory is the same as the username, so the user John would have his directory under /home/john.

However there are exceptions. For example the home directory for the root user is /root and some system services may have associated users with home directories elsewhere.

There is no rule to determine the size of a partition for the /home directory (the home partition). You should take into account the number of users in the system and how it will be used. A user which only does web browsing and word processing will require less space than one who works with video editing, for example.

Variable Data (/var)

This directory contains “variable data”, or files and directories the system must be able to write to during operation. This includes system logs (in /var/log), temporary files (/var/tmp) and cached application data (in /var/cache).

/var/www/html is also the default directory for the data files for the Apache Web Server and /var/lib/mysql is the default location for database files for the MySQL server. However, both of these can be changed.

One good reason for putting /var in a separate partition is stability. Many applications and processes write to /var and subdirectories, like /var/log or /var/tmp. A misbehaved process may write data until there is no free space left on the filesystem.

If /var is under / this may trigger a kernel panic and filesystem corruption, causing a situation that is difficult to recover from. But if /var is kept under a separate partition, the root filesystem will be unaffected.

Like in /home there is no universal rule to determine the size of a partition for /var, as it will vary with how the system is used. On a home system, it may take only a few gigabytes. But on a database or web server much more space may be needed. In such scenarios, it may be wise to put /var on a partition on a different disk than the root partition adding an extra layer of protection against physical disk failure.

Swap

The swap partition is used to swap memory pages from RAM to disk as needed. This partition needs to be of a specific type, and set-up with a proper utility called mkswap before it can be used.

The swap partition cannot be mounted like the others, meaning that you cannot access it like a normal directory and peek at its contents.

A system can have multiple swap partitions (though this is uncommon) and Linux also supports the use of swap files instead of partitions, which can be useful to quickly increase swap space when needed.

The size of the swap partition is a contentious issue. The old rule from the early days of Linux (“twice the amount of RAM”) may not apply anymore depending on how the system is being used and the amount of physical RAM installed.

On the documentation for Red Hat Enterprise Linux 7, Red Hat recommends the following:

Amount of RAM Recommended Swap Size Recommended Swap Size with Hibernation

< 2 GB of RAM

2x the amount of RAM

3x the amount of RAM

2-8 GB of RAM

Equal to the amount of RAM

2x the amount of RAM

8-64 GB of RAM

At least 4 GB

1.5x the amount of RAM

> 64 GB of RAM

At least 4 GB

Not recommended

Of course the amount of swap can be workload dependent. If the machine is running a critical service, such as a database, web or SAP server, it is wise to check the documentation for these services (or your software vendor) for a recommendation.

Note

For more on creating and enabling swap partitions and swap files, see Objective 104.1 of LPIC-1.

LVM

We have already discussed how disks are organized into one or more partitions, with each partition containing a filesystem which describes how files and associated metadata are stored. One of the downsides of partitioning is that the system administrator has to decide beforehand how the available disk space on a device will be distributed. This can present some challenges later, if a partition requires more space than originally planned. Of course partitions can be resized, but this may not be possible if, for example, there is no free space on the disk.

Logical Volume Management (LVM) is a form of storage virtualization that offers system administrators a more flexible approach to managing disk space than traditional partitioning. The goal of LVM is to facilitate managing the storage needs of your end users. The basic unit is the Physical Volume (PV), which is a block device on your system like a disk partition or a RAID array.

PVs are grouped into Volume Groups (VG) which abstract the underlying devices and are seen as a single logical device, with the combined storage capacity of the component PVs.

Each volume in a Volume Group is subdivided into fixed-sized pieces called extents. Extents on a PV are called Physical Extents (PE), while those on a Logical Volume are Logical Extents (LE). Generally, each Logical Extent is mapped to a Physical Extent, but this can change if features like disk mirroring are used.

Volume Groups can be subdivided into Logical Volumes (LVs), which functionally work in a similar way to partitions but with more flexibility.

The size of a Logical Volume, as specified during its creation, is in fact defined by the size of the physical extents (4 MB by default) multiplied by the number of extents on the volume. From this it is easy to understand that to grow a Logical Volume, for example, all that the system administrator has to do is add more extents from the pool available in the Volume Group. Likewise, extents can be removed to shrink the LV.

After a Logical Volume is created it is seen by the operating system as a normal block device. A device will be created in /dev, named as /dev/VGNAME/LVNAME, where VGNAME is the name of the Volume Group, and LVNAME is the name of the Logical Volume.

These devices can be formatted with a desired filesystem using standard utilities (like mkfs.ext4, for example) and mounted using the usual methods, either manually with the mount command or automatically by adding them to the /etc/fstab file.

Guided Exercises

  1. On Linux systems, where are the files for the GRUB bootloader stored?

  2. Where should the boot partition end to ensure that a PC will always be able to load the kernel?

  3. Where is the EFI partition usually mounted?

  4. When manually mounting a filesystem, under which directory should it usually be mounted?

Explorational Exercises

  1. What is the smallest unit inside of a Volume Group?

  2. How is the size of a Logical Volume defined?

  3. On a disk formatted with the MBR partitioning scheme, which is the ID of the EFI System Partition?

  4. Besides swap partitions, how can you quickly increase swap space on a Linux system?

Summary

In this lesson you learned about partitioning, which directories are usually kept in separate partitions and why this is done. Also, we discussed an overview of LVM (Logical Volume Management) and how it can offer a more flexible way to allocate your data and disk space compared to traditional partitioning.

The following files, terms and utilities have been discussed:

/

The Linux root filesystem.

/var

The standard location for “variable data”, data that can shrink and grow over time.

/home

The standard parent directory for home directories of regular users on a system.

/boot

The standard location for the boot loader files, Linux kernel and initial RAM disk.

EFI System Partition (ESP)

Used by systems that have UEFI implemented for the storage of the system’s boot files.

Swap space

Used to swap out kernel memory pages when RAM is heavily used.

Mount points

Directory locations where a device (such as a hard disk) will be mounted to.

Partitions

Divisions on a hard disk.

Answers to Guided Exercises

  1. On Linux systems, where are the files for the GRUB bootloader stored?

    Under /boot/grub.

  2. Where should the boot partition end to ensure that a PC will always be able to load the kernel?

    Before cylinder 1024.

  3. Where is the EFI partition usually mounted?

    Under /boot/efi.

  4. When manually mounting a filesystem, under which directory should it usually be mounted?

    Under /mnt. However, this is not mandatory. You can mount a partition under any directory you want.

Answers to Explorational Exercises

  1. What is the smallest unit inside of a Volume Group?

    Volume Groups are subdivided into extents.

  2. How is the size of a Logical Volume defined?

    By the size of the physical extents multiplied by the number of extents on the volume.

  3. On a disk formatted with the MBR partitioning scheme, which is the ID of the EFI System Partition?

    The ID is 0xEF.

  4. Besides swap partitions, how can you quickly increase swap space on a Linux system?

    Swap files can be used.

Linux Professional Insitute Inc. All rights reserved. Visit the Learning Materials website: https://learning.lpi.org
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Next Lesson

102.2 Install a boot manager (102.2 Lesson 1)

Read next lesson

Linux Professional Insitute Inc. All rights reserved. Visit the Learning Materials website: https://learning.lpi.org
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

LPI is a non-profit organization.

© 2023 Linux Professional Institute (LPI) is the global certification standard and career support organization for open source professionals. With more than 200,000 certification holders, it's the world’s first and largest vendor-neutral Linux and open source certification body. LPI has certified professionals in over 180 countries, delivers exams in multiple languages, and has hundreds of training partners.

Our purpose is to enable economic and creative opportunities for everybody by making open source knowledge and skills certification universally accessible.

  • LinkedIn
  • flogo-RGB-HEX-Blk-58 Facebook
  • Twitter
  • Contact Us
  • Privacy and Cookie Policy

Spot a mistake or want to help improve this page? Please let us know.

© 1999–2023 The Linux Professional Institute Inc. All rights reserved.