Rotten mud: learning the logical volume of LVM and reducing the size of the volume group

Source: Internet
Author: User

This article was sponsored by Xiuyi linfeng and first launched in the dark world.

In the previous article, we learned how to resize the logical volume and volume group of LVM. In this article, we will learn how to reduce the logical volume and volume group space of LVM.

Note that the logical volume must be reduced offline, but not online. Otherwise, the logical volume may be damaged, resulting in data loss.

To narrow the logical volume, follow these steps:

    1. 1. Detach a mounted logical volume
    2. 2. Zoom out the file system and use the resize2fs command
    3. 3. narrow down the logical volume
    4. 4. view the reduced logical volume
    5. 5. Mount the logical volume

First, check the space size of the logical volume. Run the LVS or lvdisplay command as follows:

We can see that the current size of the logical volume/dev/vg1/data is 800 mb and has been mounted to the/testlvm directory, and the/testlvmdirectory already has a file test.txt.

Unmount the logical volume first, as shown below:

Umount/testlvm/

After the logical volume is mounted and detached, the file system uses the resize2fs command. Now we want to reduce the logical volume/dev/vg1/data from the original 300 m to M. The command is as follows:

Resize2fs/dev/vg1/Data 300 m

For how to use the resize2fs command, you can view the help document of resize2fs, as follows:

Then the system will prompt you to run the e2fsck command first. This command is used to check whether there is a problem with the logical volume. If the parameter-F is an error, the system will fix the problem without prompting you. As follows:

E2fsck-F/dev/vg1/Data

After running e2fsck, run resize2fs/dev/vg1/Data 300 m, as shown below:

We can see that no error is reported, and the file system size is compressed to 300 MB.

The following describes how to narrow down the logical Volume LV. We can use the lvreduce command. As follows:

Lvreduce-l 300/dev/vg1/Data

For how to use the lvreduce command, see help. As follows:

After the logical volume space is reduced, we can use the LVS and lvdisplay commands again to view details, as shown below:

We can see that the logical volume/dev/vg1/data space has been reduced to 300 MB. Now, mount the logical volume to the/testlvm directory and check whether the contents of the Directory are the same as those before the logical volume partition is reduced, as shown below:

Mount/dev/vg1/data/testlvm/

We can see that the size of the/testlvm directory has been reduced to 300 MB. The test.txt file in the/testlvmdirectory still exists, indicating that we have successfully reduced the logical volume.

The preceding section describes how to narrow down the logical volume.

In fact, the shrinking of the volume group space is to delete the physical volumes that have already been added to the volume group. First, check the current physical volumes in the volume group, as shown below:

We can see that two physical volumes/dev/sda5/AND/dev/sda6 in the system are added to the volume group vg1.

This is known through the yellow part marked in the figure. At the same time, we also know that the size of the two physical volumes is 1000 m, and the size of the volume group vg1 is 2000 m.

Now we want to delete the physical volume/dev/sda6, which is equivalent to reducing the size of the volume group vg1. We can use the vgreduce Command, as shown below:

Vgreduce vg1/dev/sda6

For vgreduce usage, you can view the help documentation as follows:

Now let's check the volume group vg1 size as follows:

We can see that the current size of the volume group vg1 is 1000 MB. The physical volume/dev/sda6 does not belong to any volume group currently.

Note: To reduce the volume group space, make sure that the free space of the volume group is larger than the size of the deleted physical volume.

By now, the space of the LVM logical volume and volume group has been reduced to this end. The next article will introduce how to delete logical volume and volume group.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.