Reducing LVM logical volumes requires careful operation to avoid data loss. The key steps are as follows: 1. Ensure that the file system supports shrinking (such as ext4, xfs), and that the logical volume has enough free space; 2. Back up data in advance or create snapshots, and unmount the mount point; 3. After using e2fsck to check file system errors, use resize2fs to reduce the file system to the target size; 4. Use the lvreduce command to reduce the logical volume, and it is recommended to operate manually instead of automatic adjustment; 5. Remount the logical volume and verify that the capacity and data access are normal. Each step requires careful confirmation to ensure safe completion of the operation.
Reducing the LVM logical volume is actually not particularly difficult, but a little carelessness during the operation may lead to data loss, so the key is to clear steps and backup in place. If you have confirmed that you want to narrow down a logical volume and understand the risks, then we'll start.
Preparations before shrinking
Before starting a move, there are several prerequisites that must be met:
- File system supports minification : For example, ext4 and xfs support, but xfs can only be minified in the uninstall state and cannot be adjusted online.
- There is enough free space on the logical volume : You need to make sure that the reduced capacity is enough to accommodate existing data.
- Back up important data in advance : Even if you just take a snapshot, it is better than regretting after a problem occurs.
A common practice is to uninstall the mount point first, or enter single-user mode to operate to avoid file system occupation and adjustment.
Resize the file system
This step is the first step to narrowing the logical volume and is also the most prone to errors. Taking the ext4 file system as an example, you can use the resize2fs
command to reduce the size of the file system.
The operation process is roughly as follows:
-
Uninstall logical volume mount point:
umount /dev/vg_name/lv_name
Check the file system for errors (optional but recommended):
e2fsck -f /dev/vg_name/lv_name
Reduce the file system to the target size (such as shrink to 10G):
resize2fs /dev/vg_name/lv_name 10G
Note: This size must be less than or equal to the logical volume size you want to set later, otherwise the data will be corrupted.
Reduce the logical volume itself
After you complete the file system shrinking, you can truly shrink the logical volume. Use the lvreduce
command to complete this operation.
The command example is as follows:
lvreduce -L 10G /dev/vg_name/lv_name
You can also specify to shrink to a specific size, or reduce it by a certain amount, such as -L -5G
means the current size minus 5G.
?? Special reminder: If you are using a newer version of LVM, you will be prompted to add the -r
parameter to automatically adjust the file system. However, for safety reasons, it is recommended to operate manually and do not rely on automatic processing.
Remount and verify
After doing the above operations, remount the logical volume and check whether everything is normal:
mount /dev/vg_name/lv_name/mnt/point df -h | grep lv_name
Check whether the actual capacity meets expectations and confirm that the file access is fine. If everything goes well, it means your zoom-down operation has been successful.
Basically that's it. The whole process is not complicated, but every step cannot be skipped for inspection and confirmation.
The above is the detailed content of How to reduce LVM logical volume. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

LVM, LogicalVolumeManger, is a logical volume management function provided by the Linux kernel. It is composed of kernel drivers and application layer tools. It creates a logical layer based on the hard disk partitions, which can be very flexible and very convenient to manage storage devices. . LVM uses the device-mapper function of the Linux kernel to virtualize the storage system (system partitions are independent of the underlying hardware). Through LVM, the storage space can be abstracted and virtual partitions can be established on it. Partitions can be expanded and reduced more easily. When adding or deleting partitions, there is no need to worry about not having enough contiguous space on a certain hard disk to avoid losing space for the one being used. disk

1. Introduction to LinuxLVM LinuxLogicalVolumeManager (LVM) is a tool for managing disks and storage space. It provides flexible storage management through volume groups and logical volumes. The core concepts of LVM include physical volumes, volume groups and logical volumes. Physical volume (PhysicalVolume, PV): A physical volume is a physical hard disk or partition, which is used by LVM to store data. LVM combines one or more physical volumes into volume groups. Volume Group (VG): A volume group is a logical storage unit composed of one or more physical volumes. Logical volumes are created on volume groups, and they can dynamically allocate and reclaim storage space. A system can contain multiple volume groups. logical volume (

Linux uses lvm. LVM refers to logical volume management, which is a mechanism for managing disk partitions in the Linux environment. LVM is a logical layer built on the hard disk and partitions to improve the flexibility of disk partition management. The biggest feature of LVM is that it can dynamically manage disks. Because the size of the logical volume can be dynamically adjusted without losing existing data; if a new hard disk is added, it will not change the existing upper logical volume. As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk management.

The lvm partition of Linux refers to "logical volume management". The full English name of lvm is "Logical Volume Manager", which is a mechanism for managing disk partitions in the Linux environment; LVM is a logic built on the hard disk and partitions. layer to improve the flexibility of disk partition management.

Linux uses lvm. LVM refers to logical volume management, which is a mechanism for managing disk partitions in the Linux environment. LVM is a logical layer built on the hard disk and partitions to improve the flexibility of disk partition management. The biggest feature of LVM is that it can dynamically manage disks. Because the size of the logical volume can be dynamically adjusted without losing existing data; if a new hard disk is added, it will not change the existing upper logical volume. As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk management. Introduction to LVM LVM is the abbreviation of Logical Volume Manager (LogicalVolumeManager). It is a method for managing disk partitions in the Linux environment.

LVM is the abbreviation of LogicalVolumeManager (Logical Volume Management), which is a mechanism for managing disk partitions in the Linux environment. LVM virtualizes one or more disk partitions (PV) into a volume group (VG), which is equivalent to a large hard disk, on which we can divide some logical volumes (LV). When the space in the volume group is insufficient, new disk partitions can be added. We can also allocate some space from the remaining space of the volume group for use by logical volumes that do not have enough space. The LVM model is as shown below: There is no need to restart to refresh the new hard disk file. First, use the cat command cat/proc/scsi/scsi to browse the Id:??What is the largest one? Then echo "scsiadd-

LVM (LogicalVolumeManagement) is a flexible storage management tool in Linux, which is easier to scale and manage than traditional partitions. It allows multiple physical disks to be combined into a volume group and create dynamically resized logical volumes from it, suitable for variable storage needs. For example, when a directory is insufficient, its capacity can be expanded directly from the volume group without repartitioning or restarting the system. In addition, LVM supports snapshot functionality, which can create instant copies of logical volumes for backup without interrupting service operation. Snapshots are thinly configured to take up extra space only when data changes, making them suitable for frequently updated databases or file systems. Finally, LVM also supports online resizing logical volume sizes, in conjunction with ext4 or

The key steps for expanding LVM logical volumes are as follows: 1. First use vgdisplay to check whether there is any remaining space in the volume group; 2. Use lvextend to expand the logical volume, and you can specify the size or use all remaining space; 3. Execute resize2fs or xfs_growfs according to the file system type to update the file system capacity; 4. Finally, verify the expansion results through df-h and lvdisplay. The entire process does not require uninstalling the file system, but it must be operated strictly in sequence, especially the XFS file system is irreversible.
