Linux SysAdmin & DevOps

LXC - resize running container proxmox linux server

LXC - I was recently trying to resize a lxc container from my proxmox server (I’m running the latest proxmox version). Even though I have increased the disk space assigned to that container, for some reason I was not able to actually see the new size of the disk inside the container.

I must say that the disks are configured as LVM on the Proxmox server.

After several failed attempts, considering that the container size was not that big (initially the size was 10 Gb and I needed to increase the space up to 25 Gb) I have taken a different approach: re-creating the container (from a dump) with a larger disk.

The necessary steps are as follows:

1) Stop the container (you can do it from the proxmox web interface but considering that you will need ssh access to the server the complete the other steps, I have stopped the container using a simple command issued on the linux shell prompt):

pct stop container-id

2) Create a full container backup (to preserve the actual information within the container):

vzdump container-id -storage local -compress lzo

3) Destroy the container

pct destroy container-id

4) Restore the container from the previous created backup

pct restore container-id /var/lib/vz/dump/vzdump-lxc-container-id-2017_02_13-16_50_29.tar.lzo --rootfs local-lvm:25

Some infos about step 4:

The default backup location is /var/lib/vz/dump

When you create a backup using vzdump the file structure for the backup is: vzdump-lxc-container-id-year_month_day-hour_minutes_seconds.tar.lzo.

local-lvm represents the name (description) of the local storage volume as shown in the proxmox web interface (Storage View); depending of your configuration, the name is probably different

That would be all. I now have the exact same container but with bigger disk size (instead of the initial 10 Gb now it’s 25 Gb).

Probably there are other ways to increase the available space inside an LXC container but since my time was limited, this looked like the easiest and fastest approach. Of course, this is a good approach especially when the lxc container disk sizes are not that big (let’s say under 100G). For bigger containers, the time necessary for the vzdump could be quite big (it directly depends of your server configuration, hard disks speed/type etc).