1

I would like to shrink the main disk of a LXC container on a Proxmox VE 4.2, from 30GB to 20GB for instance. Shrinking seems not to be supported yet :

$ pct resize <VMID> rootfs 20G
unable to shrink disk size

Any ideas on how to accomplish this ?

8

You probably figured it out already, but that seems to be a limitation of LXC containers, at least for now. From the pct man page :

 <size> \+?\d+(\.\d+)?[KMGT]?
       The new size. With the + sign the value is added to the actual size of the volume and without it,
       the value is taken as an absolute one. Shrinking disk size is not supported.

If you truly want to shrink a container, I guess you'd have to perform a backup, then restore it with the --rootfs local:<newsize> option, like so :

pct stop <id>
vzdump <id> -storage local -compress lzo
pct destroy <id>
pct restore <id> /var/lib/lxc/vzdump-lxc-<id>-....tar.lzo --rootfs local:<newsize>

Of course, you can't perform this sort of resizing online, so I wouldn't call it a great solution, but it works if you have no other choice.

Good luck,

  • I have used zerofree to determine on many data can be saved, used it on a raw image of a stopped container... but it still miss shrinking. As virtualbox can do with: "VBoxManage modifyhd --compact disk.vdi" – ıɾuǝʞ May 5 '17 at 15:34
  • found it : you can use "fallocate -v --dig-holes /.../file.raw" – ıɾuǝʞ May 5 '17 at 16:01
  • 2
    Thank you it worked, but with Proxmox 5 I had to use this syntax to resize the image to 40G: --rootfs 40 – Emmanuel Bourg Feb 15 '18 at 0:12
  • 1
    You may as well want to append -unprivileged – Qian Chen Apr 4 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.