Operations 15 min read

Master Linux Installation: Zero‑Error Partitioning Strategies

This guide walks you through why careful partition planning is critical, presents production, desktop, development, and cloud server layouts, details hardware checks, BIOS settings, command‑line and LVM partitioning steps, compares filesystems, and offers security hardening, automation scripts, and monitoring tips for a flawless Linux installation.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Installation: Zero‑Error Partitioning Strategies

Why Partition Strategy Matters

Incorrect partitioning is like faulty wiring in a house – fixing it later is costly. A well‑designed layout prevents data loss, improves performance, and simplifies maintenance.

Recommended Partition Layouts

Production Server (500 GB example)

# Standard server partition layout (500 GB disk)
/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 (business data)

Desktop User

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

Development Environment

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

Cloud Server

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

Pre‑Installation Hardware Checklist

BIOS/UEFI Settings

# Check boot mode
[ -d /sys/firmware/efi ] && echo "UEFI mode" || echo "Legacy mode"
# Key BIOS options
✅ Secure Boot: disable
✅ SATA Mode: AHCI
✅ Virtualization: enable
✅ UEFI Boot: enable

Disk Health Checks

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

Partitioning in Practice

Command‑Line Partitioning (recommended)

# 1. View disks
lsblk
fdisk -l
# 2. Start fdisk
fdisk /dev/sda
# 3. Create GPT
g
# 4. EFI partition (512M)
n
1

+512M
t
1
EFI System
# 5. /boot (1G)
n
2

+1G
t
2
20   # Linux filesystem
# 6. LVM partition (rest of disk)
n
3


t
3
30   # Linux LVM
w   # write changes

LVM Dynamic Partitioning (enterprise)

# 1. Physical volume
pvcreate /dev/sda3
# 2. Volume group
vgcreate vg_system /dev/sda3
# 3. Logical volumes
lvcreate -L 50G -n lv_root vg_system   # /
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. Resize example
lvextend -L +50G /dev/vg_system/lv_var
resize2fs /dev/vg_system/lv_var

Filesystem Selection

Common Filesystems

ext4 – general purpose, stable, good compatibility, moderate performance.

xfs – high‑performance, handles large files well, cannot shrink.

btrfs – snapshots, compression, checksums, newer.

zfs – enterprise‑grade data integrity and compression, high RAM usage.

Creating Filesystems

# ext4 (default)
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

System Installation Core Tips

Network Repository Configuration (speed up install)

# CentOS/RHEL – Tsinghua mirror
sed -i 's|^#baseurl.*|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

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
# Filesystems
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 Example

# /etc/fstab optimized
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

Kernel Parameters (sysctl.conf)

vm.swappiness = 10            # reduce swap usage
vm.dirty_ratio = 15           # % of memory before flushing
vm.dirty_background_ratio = 5
fs.file-max = 2097152        # max file handles
net.core.rmem_max = 16777216 # network buffers
net.core.wmem_max = 16777216

Security Hardening

Partition Security Settings

# 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

Troubleshooting

Boot Failure

# 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

vgchange -ay   # activate all volume groups
vgscan
pvscan

Rescue Mode

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

Monitoring & Maintenance

Disk Usage Monitoring Script

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

LVM Online 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

Container‑Oriented Partitioning

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

Post‑Installation Checklist

# System 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 test:"
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 ==="

Summary & Best Practices

Plan First – sketch the partition diagram before touching disks.

Reserve Space – keep at least 20 % free in LVM for future growth.

Separate Critical Directories – /var, /tmp, /home on independent partitions.

Backup Important Data – always back up before repartitioning.

Test in Staging – validate production layouts on a test machine first.

Key Takeaways from an Experienced Ops Engineer

Choose the Right Scheme – no universal best; pick what fits your workload.

Automation Is the Future – scripted partitioning saves time and reduces errors.

Monitoring Is Essential – partitions need ongoing health checks.

Keep Learning – storage technologies evolve, stay updated.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxLVMPartitioningFilesystem
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.