Back to articles
DevOps & Systems

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.

DPTCloud Engineering4 min read
Effective VPS Disk Partitioning and Storage Management Guide for Beginners

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 lsof to check open files: lsof +D /mnt/data.
  • Run smartctl to check disk health: sudo smartctl -a /dev/sda.
  • Regularly run df -h to monitor storage usage.

7. Optimization and Maintenance

To enhance performance, consider the following:

  • Run fsck periodically to check for filesystem errors: sudo fsck /dev/sda1.
  • Use resize2fs to expand partitions if needed.
  • Set up storage alerts using cron or tools like logwatch.

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 testdisk to recover.
  • Permission issues: Check root access, use sudo.

10. References

For further reading, refer to these official resources:

Partitioning and storage management are essential DevOps skills. Apply these steps to ensure your VPS runs stably and efficiently.

DPTCloud Tier III Infrastructure

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.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478