One great advantage of using LVM is that it is easy and quick to change the size of a logical volume, especially when compared with trying to do this with a physical partition that already contains a filesystem. When doing this, extents can be added or subtracted from the logical volume, and they can come from anywhere in the volume group; they need not be from physically contiguous sections of the disk.
If the volume contains a filesystem, expanding or shrinking it is an entirely different operation than changing the size of the volume. When expanding a logical volume with a filesystem, you must first expand the volume, and then expand the filesystem. When shrinking a logical volume with a filesystem, you must first shrink the filesystem, and then shrink the volume.
This is best done with lvresize, as in the following command:
$ sudo lvresize -r -L 20 GB /dev/VG/mylvm
where the -r option causes resizing of the filesystem at the same time as the volume size is changed.
To grow a logical volume with an ext4 filesystem, run the following command:
$ sudo lvresize -r -L +100M /dev/vg/mylvm
where the plus sign (+) indicates adding space. Note that you need not unmount the filesystem to grow it.
To shrink the filesystem, run the following command:
$ sudo lvresize -r -L 200M /dev/vg/mylvm
You can also reduce a volume group as in:
$ sudo pvmove /dev/sdc1
$ sudo vgreduce vg /dev/sdc1
The filesystem cannot be mounted when being shrunk. However, some filesystems permit expansion while they are mounted.
The utilities which change the filesystem size are filesystem-dependent; besides lvresize, we can also use lvextend, lvreduce with resize2fs.
No hay comentarios:
Publicar un comentario