Zero‑Failure Linux Installation: Master Partitioning Strategies from a Veteran Ops Engineer
Drawing on a decade of operations experience, this guide walks you through zero‑incident Linux system installation and optimal partitioning, covering hardware checks, BIOS settings, multiple partition schemes for servers, desktops, cloud, LVM automation, filesystem choices, security hardening, performance tuning, troubleshooting, and post‑install monitoring.
From Zero: Linux System Installation and Partition Best Practices
Ops veteran's heartfelt advice: Partitioning a system is like wiring a house; a mistake can cost huge rework later. This article shares a decade‑long ops experience on partition strategies and installation tips.
Why Partition Strategy Matters
Remember the nervousness of your first Linux install? Facing the fdisk CLI without a clue? After countless reinstallations and data losses, I’ve distilled a "zero‑incident" partition plan.
Real case: A company's database server ran out of space because logs filled the root partition, causing a system crash and a loss of 2 million CNY—avoidable with proper partitioning.
Partition Strategy Overview
Production Environment Recommended Layout
# Standard server partition layout (example for a 500GB disk)
/boot - 1GB (boot partition, ensures system can start)
/ - 50GB (root partition, core system files)
/home - 100GB (user data, easy migration and backup)
/var - 150GB (logs and cache, prevents system fill‑up)
/tmp - 20GB (temporary files, regular cleanup)
/opt - 100GB (third‑party software)
swap - 16GB (virtual memory, 1‑2× RAM size)
/data - remaining (business data)Different Scenarios
🖥️ Desktop User Scheme
/ - 100GB (system + software)
/home - remaining (personal files)
swap - 8GB (if RAM <16GB)🛠️ Development Environment Scheme
/ - 80GB (system core)
/home - 200GB (development projects)
/var - 50GB (build cache)
/opt - 100GB (development tools)
swap - 16GB
/workspace - remaining (project code)☁️ Cloud Server Scheme
/ - 40GB (minimal system)
/var - 60GB (log monitoring)
/data - remaining (application data)
swap - file‑based (flexible)Hardware Check List Before Installation
BIOS/UEFI Configuration Tips
# Check boot mode
[ -d /sys/firmware/efi ] && echo "UEFI mode" || echo "Legacy mode"
# Key BIOS settings:
✅ Secure Boot: disable (avoids driver issues)
✅ SATA Mode: AHCI (best performance)
✅ Virtualization: enable (supports containers/VMs)
✅ UEFI Boot: enable (supports large disks)Disk Health Check
# Essential disk tests before install
smartctl -a /dev/sda # view health status
badblocks -v /dev/sda # bad block detection
hdparm -tT /dev/sda # performance test
# Critical metrics interpretation:
# Reallocated_Sector_Ct >0 → caution
# Current_Pending_Sector >0 → replace immediately
# UDMA_CRC_Error_Count >1000 → check data cablePartition Practice
Option 1: Professional CLI Partitioning (Recommended)
# 1. View disk info
lsblk
fdisk -l
# 2. Enter partition tool
fdisk /dev/sda
# 3. Create GPT partition table (supports large disks)
g # create GPT
# 4. Create EFI partition (UEFI required)
n # new partition
1 # partition number
+512M # size
t # change type
1 # EFI System
# 5. Create boot partition
n
2
+1G
t
2
20 # Linux filesystem
# 6. Create LVM partition (flexible management)
n
3
t
3
30 # Linux LVM
w # write partition tableOption 2: LVM Dynamic Partition (Enterprise Choice)
# 1. Create physical volume
pvcreate /dev/sda3
# 2. Create volume group
vgcreate vg_system /dev/sda3
# 3. Create 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
# 4. LVM advantage: resize later!
lvextend -L +50G /dev/vg_system/lv_var # expand var
resize2fs /dev/vg_system/lv_var # resize filesystemFilesystem Selection Strategy
Common Filesystem Comparison
ext4 : General use, stable, moderate performance.
xfs : Large files, high I/O, excellent performance.
btrfs : Snapshots, compression, checksumming; newer.
zfs : Enterprise storage, data integrity, compression; high memory usage.
Practical Filesystem Creation
# ext4 – general recommendation
mkfs.ext4 -L "root" /dev/vg_system/lv_root
mkfs.ext4 -L "home" /dev/vg_system/lv_home
# xfs – high‑performance scenario
mkfs.xfs -L "var" /dev/vg_system/lv_var
mkfs.xfs -L "data" /dev/vg_system/lv_data
# Setup swap
mkswap /dev/vg_system/lv_swap
# Optimized mount options
mount -o defaults,noatime,discard /dev/vg_system/lv_root /mntCore Installation Tips
Network Installation (Recommended)
# 1. Configure network mirrors for faster install
# CentOS/RHEL Tsinghua mirror
sed -i 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' /etc/yum.repos.d/CentOS-Base.repo
# Ubuntu Aliyun 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
# 2. Minimal install + later customization
# Install only Base System to avoid unnecessary packagesAutomation Installation Script
#!/bin/bash
# auto_install.sh – automated partition script
DISK="/dev/sda"
VG_NAME="vg_system"
# Automated partitioning
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 automation
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 system..."Performance Optimization
fstab Optimization
# /etc/fstab example
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 – no access‑time updates, improves performance
# discard – SSD TRIM support
# nodev,nosuid,noexec – harden /tmpKernel Parameter Tuning
# /etc/sysctl.conf production tweaks
vm.swappiness = 10 # reduce swapping
vm.dirty_ratio = 15 # limit dirty page percentage
vm.dirty_background_ratio = 5
fs.file-max = 2097152 # max file handles
net.core.rmem_max = 16777216 # network buffer sizes
net.core.wmem_max = 16777216Security Hardening
Partition Security Settings
# 1. Secure /tmp mount
mount -o remount,nodev,nosuid,noexec /tmp
# 2. Link /var/tmp to /tmp
rm -rf /var/tmp
ln -s /tmp /var/tmp
# 3. Disable 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.confDisk Encryption
# Full‑disk LUKS encryption (high security)
cryptsetup luksFormat /dev/sda3
cryptsetup luksOpen /dev/sda3 encrypted_lvm
pvcreate /dev/mapper/encrypted_lvm
# Subsequent LVM steps remain the same
# Recommendation: encrypt sensitive data partitions, keep system partition unencryptedCommon Issues & Troubleshooting
Installation Problems
# 1. Boot failure
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-install /dev/sda
# 2. Partition recognition
partprobe /dev/sda
blkid /dev/sda1
# 3. LVM activation
vgchange -ay
vgscan
pvscanRescue Mode Operations
# When system won’t boot
# 1. Boot into rescue mode
# 2. Activate LVM
vgchange -ay
# 3. Mount root
mount /dev/vg_system/lv_root /mnt/sysimage
# 4. chroot into environment
chroot /mnt/sysimage
# 5. Fix issues and rebootMonitoring & Maintenance
Partition Usage Monitoring
#!/bin/bash
THRESHOLD=80
df -h | awk 'NR>1 { usage=$5; gsub(/%/,"",usage); if (usage>THRESHOLD) { print "Warning: " $6 " usage at " $5; print "Available: " $4 } }' | mail -s "Disk Space Warning" [email protected]LVM Expansion
# Online expansion steps (production verified)
# 1. Add new disk
pvcreate /dev/sdb
vgextend vg_system /dev/sdb
# 2. Expand logical volume
lvextend -L +100G /dev/vg_system/lv_var
# 3. Grow filesystem
resize2fs /dev/vg_system/lv_var # ext4
xfs_growfs /var # xfsAdvanced Tips
Automated Deployment Integration
# Kickstart example (CentOS/RHEL)
cat > /var/www/html/ks.cfg <<'EOF'
#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
EOFContainer‑Oriented Partitioning
# Docker/Kubernetes node layout suggestion
/ - 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_dockerSummary and Best Practices
Golden Rules
Plan first : Never partition in a hurry; draw a diagram.
Reserve space : Keep at least 20% free in LVM for future growth.
Separate critical directories : /var, /tmp, /home on independent partitions.
Backup important data before partitioning.
Test and verify : Validate production schemes on a test machine first.
Veteran Ops Advice
Choose the right scheme : No single best partition plan, only the most suitable one.
Automation is the future : Manual partitioning is inefficient; adopt automation tools.
Monitoring is essential : Partitioning isn’t set‑and‑forget; continuous monitoring is required.
Keep learning : Storage technologies evolve; update your partition strategies accordingly.
Advanced Learning Path
Container storage : Learn Docker and Kubernetes storage solutions.
Software‑defined storage : Explore Ceph, GlusterFS, etc.
Cloud‑native storage : Understand CSI, StorageClass in Kubernetes.
Storage performance optimization : NVMe, tiered storage, and related technologies.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
