Creative way to shrink a live ext4 filesystem from cloud provider?

Jasmine Lognnes asked:

When buying droplets, as DigitalOcean calls their cloud VM’s, they are always configured with one large ext4 partition.

I have an app that needs an LVM partition, so I need a creative way to shrink the root partition to e.g. 25%, and use the rest for LVM. I can do it on a fresh instance, where I can reboot all I want.

For performance reasons I really would like to avoid a loop device, where I create an LVM partition in a file on top of ext4.

Question

Can someone come up with a creative way to shrink a live ext4 filesystem, where reboots are fine?

My answer:


For Digital Ocean in particular, you can boot the droplet into a rescue image.

For older distributions that boot from an external kernel, you can select to boot it into a rescue image yourself.

For newer distributions that boot from a kernel inside the droplet, you can file a support ticket to have the rescue image mounted as an ISO. Once you are done with your operations, update the support ticket to have the rescue image removed, and reboot.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.