Joseph Matino
  • Servers
  • Web Dev
  • Gaming
    • PC Gaming
  • Guides
  • Security
Font ResizerAa
Joseph MatinoJoseph Matino
Font ResizerAa
Search
  • Servers
  • Web Dev
  • Gaming
    • PC Gaming
  • Guides
  • Security
Best Game Development Frameworks In 2024

Top 14 Best Game Development Frameworks in 2024

Joseph Matino Joseph Matino 8 months ago
FacebookLike
InstagramFollow
YoutubeSubscribe
TiktokFollow
Follow US
  • Terms & Conditions
  • Privacy Policy
  • Contact
© Joseph Matino. All Rights Reserved.

Home – Blog – Servers

Manage Disk Space for LXC Containers and VMs in Proxmox VE

Joseph Matino
Last updated: September 9, 2024 2:17 am
By Joseph Matino
How To Increase Disk Space For Lxc Container Proxmox

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.

Article Content
What to Do Before Resizing Disk Space in Proxmox VEHow to Increase Disk Space for LXC Containers in Proxmox VEHow to Reduce Disk Space for LXC Containers in Proxmox VEHow to Increase Disk Space for Virtual Machines (VM) in Proxmox VEHow to Reduce Disk Space for Virtual Machines (VM) in Proxmox VEFAQsConclusion

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 or qm 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.

  1. 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.
  2. Resize the partition if necessary using a tool like fdisk or parted.
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 exit fdisk.
  1. 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!

Share This Article
Facebook Twitter Whatsapp Whatsapp Reddit Copy Link
Joseph Matino
By Joseph Matino
Follow:
I'm a full-stack web developer from Nairobi, Kenya, with over six years of experience. My expertise lies in WordPress development, server management, and web security, with a focus on optimizing WordPress site performance and transforming them into apps. I also write about tech topics in web development, server management, and PC gaming. Outside of work, you’ll find me immersed in gaming.
Leave a comment Leave a comment
Subscribe
Notify of
guest
guest
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

What's New

How To Set Up Shared FC-SAN With Proxmox: All Steps

Servers 8 months ago

Best Black Myth Wukong Mods in 2024

PC Gaming 6 months ago

Setting Up An Apache Reverse Proxy For cPanel And WHM – Worthy?

Security 10 months ago

You Might also Like

How To Optimize Email Delivery In Cyberpanel

How to Get 10/10 SMTP Scores in CyberPanel

When managing client servers, a common issue is emails not reaching their intended destination. They…

Joseph Matino 8 months ago
How To Configure Whm Custom Nameservers With Cloudflare And Namecheap

How To Configure WHM Custom Nameservers With Cloudflare And Namecheap

Configuring WHM with custom nameservers can be tricky when you need to keep your primary…

Joseph Matino 8 months ago
How To Customize Linux Motd Screen On Popular Distributions

How to Customize Linux MOTD on AlmaLinux, Ubuntu, Debian

When setting up a server, I always customize the Message of the Day (MOTD), which…

Joseph Matino 9 months ago
Assigning Multiple Ips In Almalinux 8 Manual Fix

Fix: How To Manually Configure Multiple IPs in AlmaLinux

Setting up a server with multiple IP addresses is a common task, often handled by…

Joseph Matino 9 months ago
joseph matino logo

As a passionate full-stack developer, I bring my A++ game to WordPress, server management, web optimization, and converting websites to apps, ensuring your sites are secure and shine online. Outside of work, I enjoy gaming, where every level beaten is a new skill learned.

Quicklinks

  • Terms & Conditions
  • Privacy Policy
  • Cookie Policy
  • Contact
  • About
Hire Me

Connect

Follow Me
wpDiscuz
Joseph Matino
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Joseph Matino
Manage your privacy

I use cookies and similar technologies to enhance your experience on this site. By consenting, you allow me to process data like your browsing behavior and unique IDs. If you choose not to consent or later withdraw your consent, some features of the site may not function properly.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}