I use the LAMP Stack as a vmware virtual machine. Is there any method to reduce the root partition size? The default virtual HDD size is 20 GB, but the 90% is free. I need only 3-4 GB.

Thanks for your help!

 

Forum: 
Jeremy Davis's picture

Whilst the default VM volume size is 20GB, it should be a "dynamic" volume. A dynamic volume should only take up the space on your host machine that the VM is actually using. So within your VM it will report a size of 20GB. But on your host machine, it should only be (roughly) the size of your data. It will almost certainly be bigger than your data because of files that have been written and since deleted. FYI deleted files aren't really deleted, just the reference to them. On a "normal" (physical) disk, they will get overwritten by new files as time goes on. Because of this delete behaviour, a dynamic virtual drive will tend to grow over time, even if the data inside doesn't significantly grow.

So there are 2 ways that you could approach this.

One is to zero out the unused space, then "shrink" the dynamic volume back to the size of the contained data. The virtual disk will still report as 20GB internally, but should only be taking up the size of your data on the host disk. Note that during that process, you write zeros to all the unused space (so it will grow to the full 20GB) then use an external tool to "shrink" the disk back to free the unused space.

The other approach would be to actually reduce the size of the disk (explicitly what you were asking). Again there are actually a few different ways to do this.

You could reduce the size of the filesystem, then reduce the size of the partition, then reduce the size of the LVM (assuming the system is installed with LVM - our VM builds are by default for as long as I can recall), then finally reduce the size of the virtual disk (TBH, I'm not 100% sure on how to do that last step, but I'm sure it's possible).

The other possibility (and the one that I'd probably use myself if I were to do this) would be to leverage LVM (again assuming that the VM is using LVM internally). LVM is a data abstraction layer that makes working with Linux disks much more flexible. You could add a new virtual disk to the machine (of the final size that you desire - say 6 GB to give your 3-4GB a little headroom). Then add this new volume to the LVM as a "mirror" volume. Mirror all your data across to the new disk, then remove the old disk from the LVM (and then the VM). FWIW I've used essentially that same method to replace the main physical harddrive (that the OS was on) on a running server with zero downtime! :)

If you'd like to share some more info on your set up (e.g. stuff like host OS, virtualisation platform and TurnKey Linux version) then I could elaborate a little more. FWIW a quick google turned up a tutorial for "shrinking" the virtual disk via the first method I noted. It's explicitly for a VirtualBox VM running on a Windows host so may not apply to you. Even if that is your scenario, the instructions will likely need some slight adjustment, but in essence they look sound.

Thank you very much, this helped a lot.

Jeremy Davis's picture

If you need any further specific guidance, or get stuck with anything, please don't hesitate to get in touch.

Add new comment