Operations 16 min read

Zero‑to‑Hero Linux Installation: Mastering Partition Strategies

This guide walks you through why proper Linux partitioning matters, presents production‑grade and scenario‑specific layouts, covers hardware checks, BIOS/UEFI settings, step‑by‑step partitioning with fdisk/GPT and LVM, filesystem choices, security hardening, automation scripts, monitoring, and best‑practice tips for a flawless system install.

Raymond Ops
Raymond Ops
Raymond Ops
Zero‑to‑Hero Linux Installation: Mastering Partition Strategies

Why Partition Strategy Matters

Incorrect partitioning is likened to a faulty house wiring plan; fixing it later is costly. A well‑designed layout prevents log overflows, data loss, and performance bottlenecks.

Recommended Partition Layouts

Production Server

# Standard server layout (500 GB example)
/boot   - 1GB   (boot partition)
/       - 50GB  (root)
/home   - 100GB (user data)
/var    - 150GB (logs & cache)
/tmp    - 20GB  (temporary files)
/opt    - 100GB (third‑party software)
swap   - 16GB  (swap, 1‑2× RAM)
/data   - remaining (application data)

Desktop Users

/       - 100GB (system + software)
/home   - remaining (personal files)
swap   - 8GB   (if RAM < 16GB)

Development Environments

/       - 80GB   (system core)
/home   - 200GB  (projects)
/var    - 50GB   (build cache)
/opt    - 100GB  (tools)
swap   - 16GB
/workspace - remaining (code)

Cloud Servers

/       - 40GB   (minimal system)
/var    - 60GB   (logs & monitoring)
/data   - remaining (application data)
swap   - file‑based (flexible)

Pre‑Installation Hardware Checks

BIOS/UEFI Settings

# Detect boot mode
[ -d /sys/firmware/efi ] && echo "UEFI mode" || echo "Legacy mode"
# Recommended BIOS options
Secure Boot: off
SATA Mode: AHCI
Virtualization: enabled
UEFI Boot: enabled

Disk Health

# SMART health check
smartctl -a /dev/sda
# Bad block scan
badblocks -v /dev/sda
# Performance test
hdparm -tT /dev/sda
# Key SMART attributes
Reallocated_Sector_Ct > 0 → replace disk
Current_Pending_Sector > 0 → replace immediately
UDMA_CRC_Error_Count > 1000 → check cables

Partitioning Walkthrough

Method 1: Manual fdisk (recommended)

# View disks
lsblk
fdisk -l
# Start fdisk on /dev/sda
fdisk /dev/sda
# Create GPT table
 g
# EFI partition (512 MiB)
 n
1

+512M
 t
1
 # EFI System
# /boot partition (1 GiB)
 n
2
+1G
 t
2
20   # Linux filesystem
# LVM partition (rest of disk)
 n
3


 t
3
30   # Linux LVM
 w   # write changes

Method 2: LVM‑based dynamic layout (enterprise)

# Physical volume
pvcreate /dev/sda3
# Volume group
vgcreate vg_system /dev/sda3
# Logical volumes
lvcreate -L 50G -n lv_root vg_system   # / (root)
lvcreate -L 150G -n lv_var vg_system   # /var
lvcreate -L 100G -n lv_home vg_system  # /home
lvcreate -L 20G -n lv_tmp vg_system    # /tmp
lvcreate -L 16G -n lv_swap vg_system   # swap
# Resize later
lvextend -L +50G /dev/vg_system/lv_var
resize2fs /dev/vg_system/lv_var

Filesystem Selection

Common choices and trade‑offs:

ext4 – stable, good compatibility; moderate performance.

xfs – high‑performance, large‑file friendly; cannot shrink.

btrfs – snapshots, compression, checksums; still maturing.

zfs – enterprise storage, data integrity, compression; high RAM usage.

Creating Filesystems

# ext4 (general purpose)
mkfs.ext4 -L "root" /dev/vg_system/lv_root
mkfs.ext4 -L "home" /dev/vg_system/lv_home
# xfs (high‑IO)
mkfs.xfs -L "var" /dev/vg_system/lv_var
mkfs.xfs -L "data" /dev/vg_system/lv_data
# Swap
mkswap /dev/vg_system/lv_swap
# Mount with optimized options
mount -o defaults,noatime,discard /dev/vg_system/lv_root /mnt

Core Installation Tips

Network Source Configuration (recommended)

# CentOS/RHEL – Tsinghua mirror
sed -i 's|^#baseurl=.*|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' /etc/yum.repos.d/CentOS-Base.repo
# Ubuntu – Alibaba mirror
cat > /etc/apt/sources.list <<'EOF'
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb https://mirrors.aliyun.com/ubuntu/ focal universe
deb https://mirrors.aliyun.com/ubuntu/ focal-updates universe
EOF

Automation Script (auto_install.sh)

#!/bin/bash
DISK="/dev/sda"
VG_NAME="vg_system"
# Partition with GPT and EFI
parted -s $DISK mklabel gpt
parted -s $DISK mkpart ESP fat32 1MiB 513MiB
parted -s $DISK set 1 esp on
parted -s $DISK mkpart primary 513MiB 1537MiB
parted -s $DISK mkpart primary 1537MiB 100%
parted -s $DISK set 3 lvm on
# LVM setup
pvcreate ${DISK}3
vgcreate $VG_NAME ${DISK}3
lvcreate -L 50G -n lv_root $VG_NAME
lvcreate -L 16G -n lv_swap $VG_NAME
lvcreate -l 100%FREE -n lv_home $VG_NAME
# Filesystem creation
mkfs.fat -F32 ${DISK}1
mkfs.ext4 ${DISK}2
mkfs.ext4 /dev/$VG_NAME/lv_root
mkfs.ext4 /dev/$VG_NAME/lv_home
mkswap /dev/$VG_NAME/lv_swap
echo "Partitioning complete, ready to install the system..."

Performance Optimizations

fstab Tweaks

# Example /etc/fstab entries
UUID=xxx / ext4 defaults,noatime,discard 0 1
UUID=xxx /boot ext4 defaults,noatime 0 2
UUID=xxx /home ext4 defaults,noatime,discard 0 2
UUID=xxx /var xfs defaults,noatime,discard 0 2
UUID=xxx /tmp ext4 defaults,noatime,discard,nodev,nosuid,noexec 0 2
UUID=xxx none swap defaults 0 0
# Key options:
# noatime – skip access‑time updates
# discard – enable SSD TRIM
# nodev,nosuid,noexec – harden /tmp

Kernel Parameter Tuning

# /etc/sysctl.conf examples
vm.swappiness = 10            # reduce swap usage
vm.dirty_ratio = 15          # limit dirty pages
vm.dirty_background_ratio = 5
fs.file-max = 2097152        # max file handles
net.core.rmem_max = 16777216 # increase receive buffer
net.core.wmem_max = 16777216

Security Hardening

Partition‑Level Protections

# Secure /tmp
mount -o remount,nodev,nosuid,noexec /tmp
# Link /var/tmp to /tmp
rm -rf /var/tmp
ln -s /tmp /var/tmp
# Blacklist unnecessary filesystems
echo "install cramfs /bin/true" >> /etc/modprobe.d/blacklist.conf
echo "install freevxfs /bin/true" >> /etc/modprobe.d/blacklist.conf
echo "install jffs2 /bin/true" >> /etc/modprobe.d/blacklist.conf

Full‑Disk Encryption (LUKS)

# Encrypt /dev/sda3
cryptsetup luksFormat /dev/sda3
cryptsetup luksOpen /dev/sda3 encrypted_lvm
pvcreate /dev/mapper/encrypted_lvm
# Continue with LVM as usual
# Recommendation: encrypt data partitions, keep system partition unencrypted

Common Troubleshooting

Boot Failures

# Regenerate GRUB config
grub2-mkconfig -o /boot/grub2/grub.cfg
# Reinstall GRUB
grub2-install /dev/sda

Partition Recognition Issues

# Refresh partition table
partprobe /dev/sda
# Verify UUIDs
blkid /dev/sda1

LVM Activation Problems

vgchange -ay   # activate all volume groups
vgscan
pvscan

Rescue Mode

# Boot into rescue, activate LVM, mount root
vgchange -ay
mount /dev/vg_system/lv_root /mnt/sysimage
chroot /mnt/sysimage
# Fix issues, then reboot

Monitoring & Maintenance

Disk Usage Alert Script

#!/bin/bash
THRESHOLD=80
df -h | awk 'NR>1 {usage=$5; gsub(/%/,"",usage); if (usage>THRESHOLD) {print "Warning: " $6 " usage at " $5; print "Free: " $4}}' | mail -s "Disk Space Warning" [email protected]

LVM Expansion

# Add new disk
pvcreate /dev/sdb
vgextend vg_system /dev/sdb
# Extend logical volume
lvextend -L +100G /dev/vg_system/lv_var
# Resize filesystem
resize2fs /dev/vg_system/lv_var   # ext4
xfs_growfs /var                  # xfs

Advanced Tips

Kickstart Automation (CentOS/RHEL)

# Sample ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
clearpart --all --initlabel --drives=sda
part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.01 --fstype="lvmpv" --ondisk=sda --grow
volgroup vg_system --pesize=4096 pv.01
logvol / --fstype="xfs" --size=51200 --name=lv_root --vgname=vg_system
logvol /var --fstype="xfs" --size=153600 --name=lv_var --vgname=vg_system
logvol swap --fstype="swap" --size=16384 --name=lv_swap --vgname=vg_system

Container‑Node Partitioning

/          - 50GB   (system core)
/var/lib/docker - 200GB (container storage)
/var/lib/kubelet - 100GB (pod storage)
/data      - remaining (persistent data)
# Use XFS with ftype=1 for Docker compatibility
mkfs.xfs -n ftype=1 /dev/vg_system/lv_docker

Post‑Installation Checklist

# System health verification script
#!/bin/bash
echo "=== Installation Verification Report ==="
echo "Installation time: $(date)"

echo "1. Partition info:"
df -h

echo "2. LVM status:"
vgs
lvs

echo "3. Mount points:"
mount | column -t

echo "4. System load:"
uptime
free -h

echo "5. Disk I/O performance:"
dd if=/dev/zero of=/tmp/testfile bs=1G count=1 oflag=direct
rm -f /tmp/testfile

echo "6. Network connectivity:"
ping -c 3 8.8.8.8

echo "=== Verification Complete ==="

Golden Rules

Plan first : sketch a partition diagram before touching disks.

Reserve space : keep at least 20 % free in LVM for future growth.

Separate critical directories : /var, /tmp, /home should be on independent partitions.

Backup data : always back up important files before repartitioning.

Test before production : validate the chosen scheme on a test machine.

Final Advice from an Ops Veteran

Choose the right scheme : no single layout fits all; select based on workload.

Embrace automation : manual partitioning is error‑prone; use scripts or kickstart.

Continuous monitoring : partition health degrades over time; set up alerts.

Keep learning : storage technologies evolve; stay updated with new filesystems and cloud‑native storage solutions.

AutomationLinuxInstallationLVMPartitioningFilesystem
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.