- How do I safely and step-by-step increase the hard drive space of a Linux server?
- Preparations and safety tips before increasing hard drive space
- Scenario Review — LVM vs Non-LVM and Filesystems
- Step by Step: Increasing Hard Drive Space in LVM Systems
- Step-by-Step: Increasing Hard Drive Space on Non-LVM (Standard Partition) Systems
- Practical example: Expanding root in Ubuntu in the cloud
- Notes on Encrypted Filesystem (LUKS)
- Performance and security tips after disk expansion
- Common errors and solutions
- Application-specific cases — trading, gaming, AI, rendering
- Conclusion and final recommendation
- Frequently Asked Questions
How do I safely and step-by-step increase the hard drive space of a Linux server?
Extending or increasing disk space in Linux is a common task for system administrators, DevOps, and server users—especially when the size of databases, logs, or data for AI models grows. In this guide Step by step And based on the command line, we explain how to increase disk space in different environments (VM in a cloud datacenter, dedicated server, or local virtual machine).
Preparations and safety tips before increasing hard drive space
Before any changes to the partition or LVM, Full backup Or take a snapshot so you can restore the system if an error occurs.
“Always have a valid, recoverable backup before making changes to the partition table, LVM, or filesystem.”
Important instructions for initial review:
df -hlsblk -fblkidfdisk -lOrlsblk -o NAME,SIZE,TYPE,MOUNTPOINTTo identify hardware
In cloud environments, first increase the disk volume from the control panel or API, then perform the relevant operations within the operating system.
Scenario Review — LVM vs Non-LVM and Filesystems
Organizing scenarios helps you choose the right approach:
- Scenario 1: The disk has increased and LVM Used (most common in cloud servers).
- Scenario 2: Extended disk but without LVM (root partition with filesystem) ext4 Or XFS).
- Scenario 3: Increase the size of a separate partition (e.g. /var or /home).
Note: Common file systems include: ext4, XFS and btrfs They are. ext4 can be resized offline or online; XFS Only supports grow in mounted mode.
Step by Step: Increasing Hard Drive Space in LVM Systems
1. Increase disk size from panel (for VM)
In the cloud or virtualizer panel, increase the disk size (e.g. 50G -> 100G). For a local machine with QEMU, use the following command:
qemu-img resize disk.img +50G2. Identifying the new device
To see the current status of devices from lsblk Use. Example:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 100G 0 disk
└─vda1 252:1 0 40G 0 part /3. Rescan the device in Linux
For SCSI/virtio:
echo 1 | sudo tee /sys/class/block/vda/device/rescan
# یا
sudo partprobe /dev/vda4. pvresize for PV that is on whole-disk
If the PV is on whole-disk (/dev/vdb) it is enough:
sudo pvresize /dev/vdb
sudo pvs
sudo vgs5. Expand pv partition (e.g. /dev/vda1) with growpart
When the PV is inside a partition, use growpart:
sudo apt install cloud-guest-utils
sudo growpart /dev/vda 1
sudo pvresize /dev/vda1
sudo lvdisplay
sudo lvextend -l +100%FREE /dev/mapper/vg0-root
# برای ext4:
sudo resize2fs /dev/mapper/vg0-root
# برای XFS:
sudo xfs_growfs /6. Key commands for LVM management
Frequently used commands:
sudo pvs; sudo vgs; sudo lvs
sudo lvextend -r -l +100%FREE /dev/vg0/lv_root
# گزینه -r فایلسیستم را بهصورت خودکار resize میکندStep-by-Step: Increasing Hard Drive Space on Non-LVM (Standard Partition) Systems
1. Increase disk space from the panel and scan inside the system
As in LVM mode, first increase the volume from the panel and then perform a rescan.
2. Using growpart and resize2fs for ext4
For the root partition or any partition ext4:
sudo growpart /dev/vda 1
sudo resize2fs /dev/vda1Example for the second partition:
sudo growpart /dev/vda 2
sudo resize2fs /dev/vda2Note: If resize2fs needs to unmount, use single-user mode or a Live CD.
3. XFS expansion
For XFS Which is only expandable in mounted mode:
sudo growpart /dev/vda 1
sudo xfs_growfs /mountpoint
# معمولاً:
sudo xfs_growfs /4. Modify the partition table with parted/fdisk (with caution)
If you need to delete and recreate a partition with a new size, be sure to start sector Preserve and use partition table backup.
sudo parted /dev/vda
# در داخل parted:
print
rm 1
mkpart primary ext4 START 100%Practical example: Expanding root in Ubuntu in the cloud
Sample steps:
- In the panel: Increase disk from 40G to 80G.
- Run inside the VM:
sudo lsblk
sudo growpart /dev/vda 1
# اگر LVM:
sudo pvresize /dev/vda1
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-root
# یا برای non-LVM:
sudo resize2fs /dev/vda1
# تایید:
df -hNotes on Encrypted Filesystem (LUKS)
If you have an encrypted partition, first open the encrypted container and then perform the resize operation.
sudo cryptsetup status cryptroot
sudo cryptsetup luksOpen /dev/vda1 cryptroot
# سپس:
sudo pvresize /dev/mapper/cryptroot
# یا برای فایلسیستم:
sudo resize2fs /dev/mapper/cryptrootIf using LVM inside LUKS, pvresize on /dev/mapper/cryptroot Done and then lvextend.
Performance and security tips after disk expansion
Performance: For SSD/NVMe use mount options like no time and nodiratime Use and if needed discard Consider TRIM.
Sustainability: In /etc/fstab Use UUID so that changing the device name does not cause problems:
sudo blkidMonitoring and Alert: It is recommended to install and configure Prometheus node_exporter or monitoring tools to alert you to free space.
“Restricting SSH access, using SSH keys, and maintaining regular backups are best practices for security after disk changes.”
Common errors and solutions
Error: “device does not contain a recognized partition table” — Check that a rescan has been performed and that the partition table is correct (fdisk -l).
Error: resize2fs says filesystem is mounted and needs to be checked — run e2fsck -f /dev/… In unmounted or single-user mode.
XFS: Make sure to set the correct mountpoint to xfs_growfs You see; the wrong mountpoint causes an error.
Application-specific cases — trading, gaming, AI, rendering
VPS server for trading: Requires log space and backtest data; SSD and daily snapshots are recommended.
Gaming server: The space for games and temporary files is large; using NVMe is recommended to reduce I/O latency.
GPU/AI: Models and datasets can be tens or hundreds of gigabytes; it is recommended to add a separate disk and mount it to /data Or use Thin LVM.
Rendering: Keeping temp and cache on separate disks is important to prevent root from filling up.
Conclusion and final recommendation
General steps: Increase volume from panel → rescan in system → growpart/parted → pvresize or resize2fs/xfs_growfs → lvextend (in case of LVM).
Always make backups and if in doubt, seek help from company support or a technician. Using a snapshot before making changes can significantly reduce risk.









