K
K
Kenny002022-04-08 17:27:57
linux
Kenny00, 2022-04-08 17:27:57

How to seamlessly expand the root disk on the fly in a linux virtual machine?

What is the best way to install Debian / Ubuntu OS, so that in the future there would be no problem with expanding the root partition?

The bottom line is that there is a certain software that can increase dramatically in volume and it is not possible to estimate the size of the disk in advance, and I don’t even need to think.
A virtual machine, it is not particularly important under which hypervisor it will be, the disk format is VMware image format.
Resize image without problems can be done with one command.

And here's how to expand it under a virtual machine without problems, without losing data, and most importantly without stopping the VM.

How to initially partition the disk, or how can lvm be used initially?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2022-04-08
@Kenny00

The data section that most likely needs to be expanded is done at the end of the block device. So that there is nothing behind him. And it doesn't matter if it's a root partition or something else.
When you need to expand:

  1. extend block device
  2. through parted with the resizepart command, increase the partition
  3. then expand the file system: resize2fs for ext4, xfs_growfs for xfs. If you suddenly have some other exotic - first specify the command.

Everything.
You can add lvm, the only difference is that pvresize and lvresize will be added between points 2 and 3. Or, if desired, it will be possible to create additional partitions (and / or disks) and add them to lvm.
lvm will help if you decide to make a separate partition for the OS and a separate one for the data, and then you realize that the OS partition was made too small.
PS: "Virtual machine, it doesn't really matter which hypervisor it will be under" - not all hypervisors can correctly notify the guest system about a change in the block device, some require restarting the virtual machine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question