Best Practices for Linux Partitioning and
Why They Matter
Eng. Nabil Abbas
Introduction:
●
Partitioning a Linux disk properly can enhance
performance, security, and ease of maintenance.
The best partitioning scheme depends on factors
like the system type (desktop, server, embedded),
workload, and storage size.
Why Use Separate Partitions?
●
Separating different parts of the file system into
different partitions offers several benefits:
– Data Protection: Prevents system failures or reinstallations
from wiping user data.
– Performance Optimization: Some filesystems perform
better when used for specific workloads.
– Security & Stability: Corruption in one partition doesn't
affect others.
– Easier Backups & Upgrades: Data can be preserved even if
the OS is reinstalled.
General Best Practices for
Partitioning (based on 500GB to
1TB
●
“/ (root):
– 20 to 30GB
– Contains os and application
– Keeping it separate makes system maintenance easier
●
/boot:
– 200MB to 1GB
– Store the kernel and bootlaoder file
– Ensure boot files are not affected by root filessytem
corruptoin
SWAP
●
4GB to 2xRAM
●
Act as virtual memory
●
Help with performace esapecially on low RAM
system
●
/home:
– Varies (rest of disk).
– Store user data and config
– Protoect user files from OS issues or reinstalls
–
When to use separate partiatoins:
●
/boot:
– Why? Some older BIOS systems and encrypted LVM
setups require a separate /boot partition.
●
Use Case:
– If using LVM or full-disk encryption, bootloaders may
not handle encrypted partitions properly.
– Some UEFI systems need an EFI System Partition
(ESP) (~512MB) formatted as FAT32.
VAR
●
in a Separate Partition (10-20GB)
●
Why? Prevents log growth and application data
from filling up root.
●
Use Case:
●
Web servers, databases, mail servers generate large logs.
●
If /var is part of root (/), excessive log growth can crash the
OS.
/home in a Separate Partition
●
Why? Protects user data from OS crashes, making
reinstallation easier.
●
Use Case:
– If a user needs to reinstall Linux, a separate /home
keeps their files safe.
– Multi-user systems benefit because each user’s data
remains intact during updates.
●
Swap Partition
●
Why? Provides extra memory if RAM is full.
●
Use Case:
– If running RAM-intensive applications (video editing,
VMs, databases).
– For hibernate (suspend-to-disk), swap must be at least
equal to RAM size.
Example of Disks Partition
& Why
●
Basic Desktop Setup:
●
Use Case: A typical user with general applications
and internet browsing.
●
/ (Root) - 30GB
●
/home - Rest of the disk
●
Swap - 4GB
●
Why? User data remains separate, and swap
prevents slowdowns.
Developer / Power User Setup
●
Use Case: Needs flexible storage for development,
testing, and backups.
●
/ - 40GB
●
/home - 200GB
●
/var - 30GB (log and package storage)
●
Swap - 8GB
●
Why? Ensures logs, cache, and user data do not
interfere with the OS.
Server Setup (Web, Database,
Mail, etc.)
●
/ - 20GB
●
/boot - 1GB
●
/var - 50GB (to store logs, databases, etc.)
●
/home - Separate partition (for admin files only)
●
Swap - 16GB (large memory operations)
●
Why? Protects system stability by isolating logs,
databases, and user data.
General rules
●
Use separate partitions for /boot, /var, and /home based on
system needs.
●
For servers, ensure /var is isolated to prevent logs from filling
up root.
●
For personal systems, a separate /home partition makes
reinstalls easier.
●
Use LVM for flexibility if storage needs may change over
time.
●
Choose swap size based on RAM and workload requirements.
Security-Focused Setup (LVM
+ Encryption)
●
Use Case: Requires encryption and LVM flexibility.
●
/boot - 512MB
●
LVM Volume Group:
●
/ - 30GB
●
/home - 100GB
●
Swap - 8GB
●
Why? LVM allows resizing partitions as needed, and
encryption secures data.
LVM
Introduction:
●
The Logical Volume Manager (LVM) is a widely
utilized storage management system in Linux
environments, particularly in enterprise settings. Its
popularity cames from the flexibility and advanced
features it offers over traditional partitioning
methods.
Key Factors Contributing to
LVM's Popularity:
●
Dynamic Resizing:
– LVM allows for the resizing of logical volumes without unmounting, providing
adaptability to changing storage needs.
●
Snapshot Capability:
– The ability to create snapshots facilitates efficient backups and system recovery
processes.
●
Storage Pooling:
– By aggregating multiple physical volumes into a single volume group, LVM
simplifies storage management and enhances scalability.
●
Performance Optimization:
– Features like striping and mirroring can improve performance and data
redundancy.
Resizing without LVM:
●
Resizing a Partition Without LVM
●
You can resize a partition manually, but it requires:
●
Unallocated Space: You need free space adjacent to the partition.
●
Unmounting the Partition: You cannot resize a mounted partition.
●
Using a Live CD/USB: Recommended for system partitions like / or /home.
●
Steps to Resize Without LVM:
●
Back Up Data: Resizing can lead to data loss if interrupted.
●
Boot into a Live Environment (e.g., Ubuntu Live USB).
●
Use gparted or parted:
●
Open gparted (GUI) or use parted (CLI) to resize partitions.
●
Move Partitions if Needed: If free space is not adjacent, you may need to move partitions first.
●
Apply Changes & Reboot.
Why LVM Is Better for
Resizing
●
LVM allows resizing on a running system (no need
for live USB).
●
You can grow or shrink logical volumes easily
with lvextend or lvreduce.
●
More flexible if you expect storage needs to
change over time.
LVM configuraton
Scenario:
●
You have newly installed disk.
●
It is needed to split them in two two parts
●
Install lvm on them.
●
Expand the storage as needed.
Lsblk:
●
Check with this command the make sure the divce
is shown.
●
You can use lsblk -f to see filesystem.
Fdisk:
●
Issue the command as root:
– Sudo fdisk /dev/sdb #the sdb may by differ from your system
●
Press n for new partaition, p for primary, and then select size
as the following driven menue guides you.
●
You should be able to select more then one disk if you select
the size lower than the full disk size.
●
Select “t” to select partaition table, then choose 8e for lvm.
●
Do the same thing for the second disk.
●
Press “w” to write to the disk.
lsblk
●
Use this command to check how many disk block
are there
●
To see the fstype and size.
●
To check mount point if exist
‘pvcreate’ command:
●
Create physical volume:
– ‘sudo pvcreate /dev/sdb1 /dev/sdb2’
●
To remove it:
– ‘sudo pvremove /dev/sdb1 /dev/sdb2’
●
To see the create ones:
– ‘sudo pvdisplay’
‘vgcreate’ command:
●
The command create volume gorup:
– ‘sudo vgcreate my_vg /dev/sdb1 /dev/sdb2’
●
You can create one the extend later the other one:
– ‘sudo vgcreate my_vg /dev/sdb1’
– ‘sudo vgextend my_vg /dev/sdb2’
●
To remove sdb2 from my_vg:
– ‘sudo vgreduce my_vg /dev/sdb2’
●
The two disk must be in the same disk to be extended.
●
To remove volume group use the command:
– ‘sudo vgremove my_vg’
‘vgs’ command:
●
Give overview to all volumes and size
●
Use it to check weather the size is extended.
– ‘sudo vgs’
●
If vfree is 0, mean the whole volume is configured
with file system and can not be extened.
‘lvcreate’
●
To create lvm.
– ‘sudo lvcreate -L +250M -n my_lv my_vg’
●
The command above will use vg to create lv.
●
Check with ‘sudo vgs’
●
Check also with ‘sudo lvdisplay’
●
Then ‘sudo mkfs.ext4 /dev/my_vg/my_lg’
●
Then “sudo mount /dev/my_vg/my_lg’
How to extend the size of the
volume
●
You need to check with :
– ‘sudo vgs’
●
If extra space exist you can use it.
●
Then “sudo lvextend -L +288M
/dev/my_vg/my_lv’
●
Then resize file system:
– ‘sudo resize2fs /dev/my_vg/my_lv’