Managing storage on Linux Virtual Private Servers (VPS) requires that you know how to make partitions. If you are new to Linux or already using Linux, this guide will take you through the basics and then into the advanced. Partitioning lets you allocate space, utilize resources intelligently, and organize your server data as you like. We will start to partition on Linux with a tutorial about VPS configurations.

Partitioning is dividing a disk into segments, allowing each section to act independently. On a VPS, partitioning helps you manage data better, isolate different parts of your system, and back up individual segments if needed.
Whether setting up a web server, database, or personal projects, partitioning gives structure to your server’s storage.
Root Partition (/): The root partition holds core system files and essential binaries, serving as the main directory for the Linux operating system. It is crucial for the system’s functionality as all other directories are mounted under it.
Home Partition (/home): This partition keeps user-specific files, like documents and settings, aside from system files, so when you update or reinstall your system, you don’t have to worry about your user data.
Swap Partition: The swap partition acts as virtual memory, using disk space to support RAM when it’s full. It helps manage memory-intensive processes, improving system performance and stability.
Boot Partition (/boot): This partition contains essential boot files, including the Linux kernel and bootloader. Separating it from other partitions safeguards critical files needed to start the OS.
EFI Partition (/boot/efi): This partition contains files it is needed for booting in UEFI mode on systems that use UEFI, usually formatted in FAT32. It is essential for UEFI modern compatibility.
These partitions improve organization, security, and performance by separating system, user, and critical data.
Understanding these terms will help as we explore partitioning methods.
To view the current partitions on your VPS, use the following command:
lsblk

With this command you can decide which space to use by viewing a tree-like structure of your disk with this command.
Several tools are available in Linux for creating and managing disk space. The most popular are:
Since the VPS environment is dependent on the command line, we’ll concentrate on the fdisk and the parted.
Creating partitions on MBR-based disks is a simple task using the fdisk utility. Here’s a step-by-step guide to using fdisk:
Open fdisk on the disk you want to partition. For example, if your disk is /dev/sda, type:
sudo fdisk /dev/sda
Type p to view existing partitions on the disk.
Command (m for help): p
To create a new partition, type n and follow the prompts.
Once you’re satisfied with your changes, type w to write them to the disk.
Command (m for help): w

After this, reboot your system, if necessary, to apply the changes.
For more complex partitioning, parted is a robust tool that supports both MBR and GPT disks.
Begin by opening part on the target disk:
sudo parted /dev/sda
If the disk doesn’t have a partition table, create one using either msdos (MBR) or gpt:
(parted) mklabel gpt

Creating a partition with parted involves specifying the size directly:
(parted) mkpart primary ext4 1MiB 500MiB

This example creates a primary partition with the ext4 file system, starting at 1MB and ending at 500MB.
List the partitions with:
(parted) print

When done, Exit parted:
(parted) quit

LVM is an advanced partitioning method that adds flexibility. With LVM, you can resize partitions without rebooting or repartitioning.
Initialize the Physical Volume:
sudo pvcreate /dev/sda1

sudo vgcreate vg_name /dev/sda1

sudo lvcreate -L 5G -n lv_name vg_name

sudo mkfs.ext4 /dev/vg_name/lv_name

sudo mount /dev/vg_name/lv_name /mnt

LVM is useful for environments where storage needs fluctuate or grow over time.
Mounting connects a partition to a directory so you can access it.
Create a Mount Point:
sudo mkdir /mnt/my_partition

sudo mount /dev/sda1 /mnt/my_partition


A new partition must be formatted with a file system before use. Common file systems in Linux are ext4, xfs, and btrfs.
For ext4, format a partition using:
sudo mkfs.ext4 /dev/sda1

For xfs, use:
sudo mkfs.xfs /dev/sda1

Choose a file system based on your use case. ext4 is popular for its stability, while xfs performs well with large files.
The fstab file controls automatic mounting on startup, making it a time-saver for VPS management.
Open the fstab file with your favorite editor:
sudo nano /etc/fstab

/dev/sda1 /mnt/my_partition ext4 defaults 0 2

Test by unmounting and remounting:
sudo umount /mnt/my_partition

sudo mount -a

fstab helps ensure that partitions load automatically, simplifying server restarts and reboots.
Partitioning issues can crop up, but most have straightforward solutions.
Regularly verify your partition setup to avoid downtime or data loss.
Partitioning in Linux, particularly on VPS setups, is a powerful way to optimize storage and manage data. By learning both basic and advanced techniques, you can confidently structure your VPS to meet your specific needs. From using fdisk and parted for partitioning to configuring LVM and automating mounts with fstab, you have the tools to customize your VPS storage efficiently.

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.