Most of the time when using Proxmox, we encounter situations where LXC containers or virtual machines (VMs) run out of disk space, or there’s a need to reduce disk space for better resource management. It can be a bit frustrating, but don’t worry! Adjusting disk space in Proxmox VE is straightforward.
Recently, I encountered this issue on a client’s server. I had to move the data to another server, which was also using CyberPanel, because CyberPanel supports efficient server-to-server backup, making it easier to manage the temporary data transfer. To increase the boot disk size for VMs or LXC containers, the first step is always to turn off the VM or stop the container.
If you’re setting up complex storage solutions, you might also want to check out this guide on setting up a shared FC SAN with Proxmox.
What to Do Before Resizing Disk Space in Proxmox VE
Before you start resizing disk space, here are a few important steps to ensure everything goes smoothly:
- Backup Your Data: Always make sure to back up your data to avoid any potential data loss during the resizing process.
- Check Disk Usage: Use the
df -h
command to check the current disk usage and identify how much space is being used. - Clean Up Unnecessary Files: Log in to the container or VM and remove any unnecessary files to free up space.
- Identify Disk Image Path: Determine the path of the disk image to be resized. This can usually be found using the
mount
command for containers orqm config
for VMs. - Plan Downtime: Resizing operations typically require the container or VM to be turned off, so plan for a suitable time to perform these tasks to minimize downtime and impact on users.
Taking these considerations into account will help ensure a smooth and successful resizing process, minimizing potential issues and disruptions.
How to Increase Disk Space for LXC Containers in Proxmox VE
First, identify the container you want to resize. Let’s use container ID 300
as an example.
Step 1: Stop the Container
Stop the container to prevent any active processes from causing issues. Run this command on the Proxmox VE host (main node).
pct stop 300
Step 2: Resize the Container Disk
Use the pct resize
command to increase the container’s root file system size. Run this command on the Proxmox VE host.
pct resize 300 rootfs 30G
pct resize
: Command to resize the disk of a container.300
: Container ID.rootfs
: The root file system of the container.60G
: The new desired size.
You will see a confirmation that the logical volume has been resized.
Step 3: Start the Container
Start the container again. Run this command on the Proxmox VE host.
pct start 300
Step 4: Verify the New Disk Size
Log in to the container and check if the new disk size is reflected correctly. Run this command on the Proxmox VE host to enter the container.
pct enter 300
Once inside the container, run:
df -h
df -h
: Command to display filesystem disk space usage in a human-readable format. It shows the amount of disk space used and available on mounted filesystems.
How to Reduce Disk Space for LXC Containers in Proxmox VE
Reducing disk space for LXC containers involves several careful steps. Make sure to follow each step carefully.
Step 1: Backup Your Data
Back up your data to avoid any potential data loss.
Step 2: Reduce Data Usage Inside the Container
Log in to the container to clean up files and reduce usage. Run this command on the Proxmox VE host to enter the container.
pct enter 300
Once inside the container, run:
df -h
# Clean up unnecessary files
exit
Step 3: Stop the Container
Stop the container to prevent any active processes from causing issues. Run this command on the Proxmox VE host.
pct stop 300
Step 4: Determine the Disk Image Path
Use the mount
command to find the path of the root filesystem before stopping the container.
pct enter 300
mount
Expected Output:
root@Slambo-CT:~# mount
/var/lib/vz/images/300/vm-300-disk-0.raw on / type ext4 (rw,relatime)
none on /dev type tmpfs (rw,relatime,size=492k,mode=755,uid=100000,gid=100000)
...
Look for an entry that shows where the root filesystem (/
) is mounted from. In my setup, the root filesystem is mounted from /var/lib/vz/images/300/vm-300-disk-0.raw
.
Step 5: Shrink the Filesystem
Perform this step on the Proxmox VE host.
Create a temporary directory:
mkdir /mnt/tmp
Use losetup
to associate the disk image file with a loop device:
losetup -f /var/lib/vz/images/300/vm-300-disk-0.raw
Check which loop device was used:
losetup -a
Assume the loop device is /dev/loop0
(adjust if different).
Mount the loop device:
mount /dev/loop0 /mnt/tmp
Shrink the filesystem to the desired size:
resize2fs /dev/loop0 20G
Unmount the loop device and detach it:
umount /mnt/tmp
losetup -d /dev/loop0
Step 6: Reduce the Size of the Disk Image File
Resize the disk image file on the Proxmox VE host.
qemu-img resize /var/lib/vz/images/300/vm-300-disk-0.raw 20G
Step 7: Start the Container
Start the container again. Run this command on the Proxmox VE host.
pct start 300
Step 8: Verify the New Disk Size
Log in to the container and check if the new disk size is reflected correctly. Run this command on the Proxmox VE host to enter the container.
pct enter 300
Once inside the container, run:
df -h
How to Increase Disk Space for Virtual Machines (VM) in Proxmox VE
Increasing disk space for virtual machines in Proxmox VE involves resizing the virtual disk and then expanding the file system inside the VM.
Step 1: Identify the VM
Determine the VM you want to resize. We’ll use VM ID 301
for this example.
Step 2: Check the Disk Type
Check the current configuration of your VM to see the details of its disk. Run this command on the Proxmox VE host.
qm config 301
Expected Output:
boot: order=scsi0;ide2;net0
cores: 1
cpu: x86-64-v2-AES
ide2: local:iso/ubuntu-22.04.3-live-server-amd64.iso,media=cdrom,size=2083390K
memory: 2048
meta: creation-qemu=8.1.5,ctime=1718385033
name: Slambo-VM
net0: virtio=BC:24:11:55:F4:17,bridge=vmbr0,firewall=1
numa: 0
ostype: l26
scsi0: local:301/vm-301-disk-0.qcow2,iothread=1,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=9z346907-8f35-1586-5k7i-6bb12h0b7js9
sockets: 1
vmgenid: 554bc010-37b2-A721-99d5-1ww0d8955436
In this example, the disk type is scsi0
, and the disk path is local:301/vm-301-disk-0.qcow2
.
Step 3: Resize the Virtual Disk
Use the qm resize
command to increase the size of the virtual disk. Run this command on the Proxmox VE host.
qm resize 301 scsi0 +10G
qm resize
: Command to resize the disk of a VM.301
: VM ID.scsi0
: The disk identifier.+10G
: The amount of space to add.
Step 4: Start the Virtual Machine
Start the VM after resizing the disk. Run this command on the Proxmox VE host.
qm start 301
Step 5: Expand the File System Inside the VM
Log in to the VM and expand the file system to utilize the new space.
- Access the VM via the console or SSH:
- Console: Access the console through the Proxmox VE web interface. Select the VM, then click on “Console.”
- SSH: Use an SSH client (e.g., PuTTY) to log in to the VM. You’ll need the VM’s IP address and appropriate credentials.
- Resize the partition if necessary using a tool like
fdisk
orparted
.
Using fdisk
:
fdisk /dev/sda
Follow the prompts:
- Press
p
to print the partition table. - Note the partition number you want to resize (e.g.,
/dev/sda1
). - Press
d
and then the partition number to delete it. - Press
n
to create a new partition. - Select
p
for primary. - Use the same partition number as the one you deleted.
- Set the first sector to match the start of the deleted partition.
- Set the last sector to use the full available space.
- Press
w
to write the changes and exitfdisk
.
- Resize the file system:For
ext4
:
resize2fs /dev/sda1
Replace /dev/sda1
with your partition.
For xfs
:
xfs_growfs /dev/sda1
Step 6: Verify the New Disk Size
Check the disk size inside the VM to ensure the changes have been applied. Run this command inside the VM.
df -h
This command displays disk space usage in a human-readable format, confirming the successful resizing.
How to Reduce Disk Space for Virtual Machines (VM) in Proxmox VE
Reducing disk size for VMs is more complex and involves several careful steps to avoid data loss.
Step 1: Backup Your Data
Back up your data to avoid any potential data loss.
Step 2: Identify the VM
Determine the VM you want to resize. We’ll use VM ID 301
for this example.
Step 3: Reduce Data Usage Inside the VM
Log in to the VM and remove unnecessary files to reduce the used space.
ssh root@<VM-IP>
df -h
# Clean up files to reduce usage
exit
Step 4: Shrink the File System Inside the VM
Log in to the VM via console or SSH and reduce the file system size.
For ext4
:
resize2fs /dev/sda1 20G
Replace 20G
with the new desired size.
For xfs
, shrinking is not supported natively. You’ll need to back up, recreate the partition, and restore data.
Step 5: Reduce the Partition Size
Use fdisk
or parted
to delete the current partition and recreate it with the reduced size.
Using fdisk
:
fdisk /dev/sda
Follow the prompts:
- Print the partition table:
p
- Delete the partition:
d
- Create a new partition:
n
- Select primary:
p
- Use the same partition number
- Set the first sector to match the start of the deleted partition
- Set the last sector to the new size
- Write changes:
w
Step 6: Reduce the Logical Volume Size
Reduce the logical volume size using lvreduce
.
lvreduce -L 20G /dev/mapper/pve-vm--301--disk--0
Step 7: Resize the Disk in Proxmox VE
Use qm resize
to resize the VM disk. Run this command on the Proxmox VE host.
qm resize 301 scsi0 20G
Step 8: Verify the New Disk Size
Check the disk size inside the VM to ensure the changes have been applied. Run this command inside the VM.
df -h
This command displays disk space usage in a human-readable format, confirming the successful resizing.
FAQs
1. How can I ensure data integrity during the disk resizing process in Proxmox VE?
To ensure data integrity during the resizing process, perform a full backup using Proxmox VE’s built-in tools. Verify the health of your disks using tools like fsck
for file systems, and run file system checks before resizing. For example, use e2fsck -f
for ext4 file systems to ensure there are no file system issues before proceeding.
2. Can I resize the disk of a running LXC container or VM in Proxmox VE?
No, you cannot resize the disk of a running LXC container or VM. You must stop the container or VM before performing the resize operation to prevent data corruption and ensure the changes are applied correctly.
3. What should I do if I encounter errors while resizing the disk in Proxmox VE?
If you encounter errors while resizing the disk, first check the Proxmox VE logs for detailed error messages. Make sure there is enough unallocated space on the physical storage to accommodate the resize operation. If you need additional guidance, refer to the Proxmox VE documentation and community forums. If necessary, use your backup to restore the system to its previous state and investigate the issue further before retrying.
Conclusion
By following these steps, you can successfully increase or reduce the disk space for both LXC containers and virtual machines in Proxmox VE. Always ensure you have a complete backup before attempting to resize disks, especially when reducing size, to avoid data loss. If you have running services, consider moving them to a secondary server or IP address to minimize downtime.
If this guide helped you, please comment below or share your experience. Happy resizing!