0

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?

Jasmine Lognnes
  • 2,490
  • 8
  • 31
  • 51

3 Answers3

2

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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Their docs on this process: https://www.digitalocean.com/community/tutorials/how-to-recover-from-file-system-corruption-using-fsck-and-a-recovery-iso – Martijn Heemels Aug 18 '15 at 10:03
2

Take a look at this answer, and a variety of searching, but the short answer is what you are talking about is not possible on a live filesystem unless it is possible to unmount the partition you wish to resize. Since it does not seem like that is possible in this case rebooting to a rescue image is probably the best option.

If rebooting to a rescue image is not an option, but rebooting to a new image is and you have a good backup of the image you want there may be a novel solution. It seems like it would be possible to use Clonezilla with the clone to smaller partition options to clone your existing system onto a new instance that takes up less space. This of course assumes that there is enough free space to shrink the ext4 filesystem onto a smaller partition, but you probably would not have asked the question if there was not enough freespace to shrink the partition.

Matt
  • 2,711
  • 1
  • 13
  • 20
1

You can shrink an online root partition without any reboots: consult this answer. This answer is very well written and easy to follow. So this would work on any type of dedicated or VPS solution.

TLDR; this solution implies to pivot_root to tmpfs so you can umount safely your root partition live and fiddle with it. Once done, you'll pivot_root back on your new root partition.

This allows pretty much any manipulation on the root file system (move it, change filesystem, changing it's physical device...).

No reboot are required in the process, and this allows to bypass limitation of not being able to shrink mount ext4 partition.

I have personally used this, and it works very well on debian system also, with very few corrections. I'm very surprised not to see this in-depth solution a little more linked to the many question in stackexchange web sites that deals with the same issue.

vaab
  • 512
  • 3
  • 13