Effective VPS Disk Partitioning and Storage Management Guide for Beginners
A detailed guide on partitioning hard drives and managing storage effectively on VPS for beginners, including CLI commands, tools, and best practices.
Image credit: padrinan · Pixabay Content License
Partitioning Hard Drives on VPS: Basic Guide for Beginners
Partitioning the hard drive on your VPS is a crucial first step to optimize performance and manage data efficiently. Most Linux-based VPS instances come with an unpartitioned raw disk. Below is a detailed guide to help you partition and manage storage effectively.
1. Check Current Disk Configuration
Before partitioning, verify which storage devices are attached to your VPS:
lsblk
The output will display storage devices. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 20G 0 part /
In this case, the disk `sda` is unpartitioned. You’ll need to create new partitions.
2. Use fdisk to Partition the Disk
Start partitioning with the following command:
sudo fdisk /dev/sda
Inside the fdisk interface, enter the following commands in order:
m– Display help menu.n– Create a new partition.p– Create a primary partition.1– Create partition 1.Enter– Use default size (from start to end).w– Write changes and exit.
3. Create a Filesystem
After partitioning, create a filesystem (e.g., ext4) on the new partition:
sudo mkfs.ext4 /dev/sda1
For larger or high-performance partitions, consider using xfs or ext4.
4. Mount the Partition
Create a mount directory and attach the partition:
sudo mkdir /mnt/data
sudo mount /dev/sda1 /mnt/data
To ensure the partition mounts automatically after reboot, add it to /etc/fstab:
/dev/sda1 /mnt/data ext4 defaults 0 2
5. Monitor Storage Usage and Performance
To track used storage, use the following command:
df -h
To check available space:
du -sh /mnt/data
6. Best Practices for Effective Storage Management
- Separate partitions for critical directories like
/var,/home, or/data. - Use
lsofto check open files:lsof +D /mnt/data. - Run
smartctlto check disk health:sudo smartctl -a /dev/sda. - Regularly run
df -hto monitor storage usage.
7. Optimization and Maintenance
To enhance performance, consider the following:
- Run
fsckperiodically to check for filesystem errors:sudo fsck /dev/sda1. - Use
resize2fsto expand partitions if needed. - Set up storage alerts using
cronor tools likelogwatch.
8. Verification and Validation
To confirm successful partitioning:
sudo blkid
sudo mount | grep sda1
Ensure the partition is mounted and accessible.
9. Troubleshooting
- Mount failure: Verify filesystem format, run
fsck. - Lost partition: Use
testdiskto recover. - Permission issues: Check root access, use
sudo.
10. References
For further reading, refer to these official resources:
- Practical Guide to Building PostgreSQL High Availability Cluster with Patroni, etcd, and PgBouncer on 3 Low-Cost VPS
- NVMe Cloud VPS for Docker, Nginx & Databases
Partitioning and storage management are essential DevOps skills. Apply these steps to ensure your VPS runs stably and efficiently.
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
