This project provides a modular, production-ready setup to manage large, dynamically growing storage using LVM Thin Provisioning on Ubuntu. It enables you to start with minimal storage and expand on-the-fly by detecting and integrating new disks.
- Thin-provisioned logical volume (100TB virtual size by default)
- Automatically detects and adds new physical disks
- Expands thin pool without downtime
- Cron and systemd support for automation
- Optional .deb packaging and GitHub Actions CI
📁 Path: /usr/local/bin/lvm_thinpool_initial_setup.sh
🔧 One-time setup script:
- Initializes first disk (e.g.,
/dev/sdb) - Creates:
- Volume Group:
vgthin - Thin Pool:
thinpool - Metadata LV:
thinmeta - Thin-provisioned LV:
lvdata(default: 100TB)
- Volume Group:
- Formats and mounts LV to
/data - Adds to
/etc/fstab
📦 Usage:
sudo /usr/local/bin/lvm_thinpool_initial_setup.sh📁 Path: /usr/local/bin/auto_detect_and_expand_thinpool.sh
🔁 Auto-detect and integrate new raw disks:
- Partitions new unpartitioned disks
- Creates PVs
- Adds them to Volume Group
vgthin - Expands
thinpoolusing free space
📦 Usage:
sudo /usr/local/bin/auto_detect_and_expand_thinpool.sh📆 Cron Automation:
sudo crontab -e
# Add:
@hourly /usr/local/bin/auto_detect_and_expand_thinpool.sh🪵 Logs:
/var/log/lvm_auto_expand.log
| Component | Purpose |
|---|---|
/dev/vgthin/lvdata |
Thin-provisioned Logical Volume |
/data |
Mount point for LV |
/etc/fstab |
Ensures auto-mount on reboot |
/var/log/lvm_auto_expand.log |
Log of expansion events |
Check thin pool usage:
sudo lvs -aDetailed usage monitoring:
sudo lvs -o+seg_monitor,seg_size,data_percent,metadata_percent
⚠️ Watchdata_percentandmetadata_percent.
If either reaches 100%, I/O operations will fail.
| Time | Action | VG Size | Thin Pool Size |
|---|---|---|---|
| Month 0 | Initial setup (30GB disk) | 30GB | ~28GB |
| Month 6 | Add 1x 4TB disk | 4.03TB | ~2TB |
| Month 12 | Add 1x 4TB disk | 8.03TB | ~6TB |
| Month 18 | Add 1x 4TB disk | 12.03TB | ~10TB |
- Ubuntu 20.04 or newer
- Packages:
lvm2,parted,coreutils,cron - Root privileges
- Clean (unpartitioned) disks for auto-detection
- Always maintain 5–10% free space in the thin pool
- Set up alerts (email, Prometheus, etc.) for usage thresholds
- Monitor
data_percentandmetadata_percentregularly - Avoid overcommitting disk without growth planning
- Always pre-test in staging or non-critical environments
Create service unit:
sudo nano /etc/systemd/system/lvm-expand.service[Unit]
Description=Auto Expand LVM Thin Pool
After=multi-user.target
[Service]
ExecStart=/usr/local/bin/auto_detect_and_expand_thinpool.shCreate timer unit:
sudo nano /etc/systemd/system/lvm-expand.timer[Unit]
Description=Run LVM Expansion Hourly
[Timer]
OnBootSec=10min
OnUnitActiveSec=1h
[Install]
WantedBy=timers.targetEnable and start the timer:
sudo systemctl daemon-reexec
sudo systemctl enable --now lvm-expand.timerProject can be packaged for easier distribution:
my-lvm-expander/
├── DEBIAN
│ └── control
├── usr
│ └── local
│ └── bin
│ ├── lvm_thinpool_initial_setup.sh
│ └── auto_detect_and_expand_thinpool.sh
└── etc
└── systemd
└── system
├── lvm-expand.service
└── lvm-expand.timer
Build the .deb:
dpkg-deb --build my-lvm-expanderUse this to lint and validate the shell scripts:
.github/workflows/test.yml:
name: Test LVM Expansion Scripts
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Lint Shell Scripts
uses: ludeeus/action-shellcheck@master
- name: Ensure Scripts Are Executable
run: |
chmod +x ./lvm_thinpool_initial_setup.sh
chmod +x ./auto_detect_and_expand_thinpool.sh
echo "✅ Scripts are executable"MIT License — Free to use, modify, and distribute for personal and commercial use.
Built and maintained by Hacky Coder 0951
Designed for scalable, cloud-ready Linux storage automation.