5.2. Shrinking logical volumes
You can reduce the size of a logical volume with the lvreduce
command.
Shrinking is not supported on a GFS2 or XFS file system, so you cannot reduce the size of a logical volume that contains a GFS2 or XFS file system.
If the logical volume you are reducing contains a file system, to prevent data loss you must ensure that the file system is not using the space in the logical volume that is being reduced. For this reason, it is recommended that you use the --resizefs
option of the lvreduce
command when the logical volume contains a file system.
When you use this option, the lvreduce
command attempts to reduce the file system before shrinking the logical volume. If shrinking the file system fails, as can occur if the file system is full or the file system does not support shrinking, then the lvreduce
command will fail and not attempt to shrink the logical volume.
In most cases, the lvreduce
command warns about possible data loss and asks for a confirmation. However, you should not rely on these confirmation prompts to prevent data loss because in some cases you will not see these prompts, such as when the logical volume is inactive or the --resizefs
option is not used.
Note that using the --test
option of the lvreduce
command does not indicate where the operation is safe, as this option does not check the file system or test the file system resize.
Procédure
To shrink the mylv logical volume in myvg volume group to 64 megabytes, use the following command:
# lvreduce --resizefs -L 64M myvg/mylv fsck from util-linux 2.37.2 /dev/mapper/myvg-mylv: clean, 11/25688 files, 4800/102400 blocks resize2fs 1.46.2 (28-Feb-2021) Resizing the filesystem on /dev/mapper/myvg-mylv to 65536 (1k) blocks. The filesystem on /dev/mapper/myvg-mylv is now 65536 (1k) blocks long. Size of logical volume myvg/mylv changed from 100.00 MiB (25 extents) to 64.00 MiB (16 extents). Logical volume myvg/mylv successfully resized.
In this example, mylv contains a file system, which this command resizes together with the logical volume.
Specifying the
-
sign before the resize value indicates that the value will be subtracted from the logical volume’s actual size. To shrink a logical volume to an absolute size of 64 megabytes, use the following command:# lvreduce --resizefs -L -64M myvg/mylv
Ressources supplémentaires
-
lvreduce(8)
man page