In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to expand volume groups, logic volumes and reduce logic volumes LVM in Linux". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to expand volume groups, logic volumes and reduce logic volume LVM in Linux".
Today we will learn how to expand volume groups, expand and shrink logical volumes. Here, we can reduce or extend partitions in logical volume management (LVM), which can also be referred to as resilient volume file systems.
Pre-requirements use LVM to create elastic disk storage-part 1
When do we need to reduce the volume?
Maybe we need to create a separate partition for other purposes, or we need to extend any partition with low space. In this case, using LVM, we can easily reduce large-size partitions and expand low-space partitions by following a few simple steps.
My server settings-- operating system required-- CentOS 6.5 server with LVM installed IP-192.168.0.200
How to expand volume groups and reduce logical volumes
Extended logical Volume
Currently, we already have one PV,VG and two LV. Let's list them with the following command.
# pvs# vgs# lvs
Logical volume expansion
There is no free space available in physical volumes and volume groups, so we cannot expand the size of logical volumes now. To extend, we need to add a physical volume (PV), and then extend the volume group by extending vg, so that we have enough space to expand the logical volume size. So, first we should add a physical volume.
To add a new PV, we must use fdisk to create a LVM partition.
# fdisk-cu / dev/sda
Select n to create a new partition. Select p to create the primary partition. Select the partition number we need to create. If other disks are available, press 1. Use t to modify the partition type. Enter 8e to change the partition type to Linux LVM. Use p to print the created partition (we don't use this option here). Press w to write the modification.
Restart the system when you are finished.
Create LVM Partition
Use fdisk to list and check the partitions we created.
# fdisk-l / dev/sda
Verify LVM Partition
Next, use the following command to create a new PV (physical volume).
# pvcreate / dev/sda1
Use the following command to verify pv.
# pvs
Create a physical volume
Expand volume group
Add the pv to the vg_tecmint volume group to expand the size of the volume group to get more space to extend the lv.
# vgextend vg_tecmint / dev/sda1
Let's check the size of the volume group that is now in use.
# vgs
Expand volume group
We can even see which PV is used to create specific volume groups in use.
# pvscan
Check volume group
Here, we can see the physical volume where the volume group is located. We have added a pv, and it is completely empty. Before extending logical volumes, let's take a look at the size of each volume group we have.
Check all logical volumes
LogVol00 is used for Swap. LogVol01 is used for /. Now we have space the size of 16.50GB for / (root). There are currently 4226 physical extensions (PE) available.
Now, we are going to extend / partition LogVol01. After the expansion, we can list its size as above to confirm. We can use GB or PE to extend, as I explained in the first part of LVM, where I use PE to extend.
To get the available physical extension size, run the following command.
# vgdisplay
Check for available physical extensions
A total of 4607 free PE is available, that is, 18GB space is available. Therefore, we can extend our logical volume to the size of 18GB. Let's use the PE size to extend.
# lvextend-l + 4607 / dev/vg_tecmint/LogVol01
Use + to add more space. After the extension, we need to change the file system size, using the following command.
# resize2fs / dev/vg_tecmint/LogVol01
Extended logical Volume
Commands used to extend logical volumes using physical extensions. Here we can see that it extends from 16.51GB to 34GB. If the file system is mounted and in use, change the file system size. To extend logical volumes, we do not need to unmount the file system
Now, let's take a look at the resized logical volumes currently in use.
# lvdisplay
Change the logical volume size
LogVol01 is used for extended volumes /. After expansion, it has risen from 16.50GB to 34.50GB. C the current extension, there are 4226 before the extension, we have added 4607 extensions, so now there are 8833.
Now, if we check the available vg, the free PE will be 0.
# vgdisplay
View the results of the extension.
# pvs# vgs# lvs
Verify that the partition size changes
New physical volume added. The volume group vg_tecmint extends from 17.51GB to 35.50GB. The logical volume LogVol01 extends from 16.51GB to 34.50GB.
Here, we have completed the process of expanding volume groups and logical volumes. Let's move on to some interesting parts of logical volume management.
)
Here, we will learn how to reduce logical volumes. Everyone says it is dangerous and can lead to disaster when reducing lvm. Reducing lvm is really much more interesting in logical volume management than in other parts.
It's always right to back up your data before you start, so that if something goes wrong, you won't have a headache. To reduce logical volumes, you need to complete five steps carefully. When extending a volume, we can extend it (online) when the volume is mounted, but for shrinking, we must unmount the file system before shrinking.
Let's take a look at the following five steps.
Unmount the file system for reduction. Check the file system after unmounting. Reduce the file system. 5 reduce the current logical volume size. Check the file system again to prevent errors. Mount the file system back again.
For demonstration purposes, I have created separate volume groups and logical volumes. Here, I will reduce the logical volume tecmintreducetest. Now that it has the size of 18GB, we need to reduce it to 10GB without losing data. That is, we need to reduce 8GB from 18GB. 4GB is already in use in the volume.
18GB-> 10GB
When reducing the size, we only need to reduce the 8GB, so after the reduction, it will have a total of 10GB.
# lvs
Reduce logical Volume
Here, we can see the file system information.
# df-h
Check the file system size
The volume size is 18GB. It already uses 3.9GB. The available space is 13GB.
First, uninstall the mount point.
# umount-v / mnt/tecmint_reduce_test/
Uninstall partition
Then, use the following command to check for file system errors.
# e2fsck-ff / dev/vg_tecmint_extra/tecmint_reduce_test
Scan partition error
Note: you must pass all the 5 steps of the file system check. If not, there may be a problem with your file system.
Next, shrink the file system.
# resize2fs / dev/vg_tecmint_extra/tecmint_reduce_test 8GB
Reduce file system
Use GB to reduce logical volumes.
# lvreduce-L-8G / dev/vg_tecmint_extra/tecmint_reduce_test
Reduce logical Partition
To use PE to reduce logical volumes, we need to know the default PE size and the total PE size of the volume group to do a small calculation to work out the exact reduction size.
# lvdisplay vg_tecmint_extra
Here, we need to use the bc command to do some small calculations to get the PE size of the 10GB.
1024MB x 10GB = 10240MB or 10GB10240MB / 4PE = 2048PE
Press CTRL+D to exit BC.
Calculate the PE siz
Use PE to reduce the size.
# lvreduce-l-2048 / dev/vg_tecmint_extra/tecmint_reduce_test
Use PE to reduce the size
Resize the file system back. In this step, if any errors occur, it means that we have messed up the file system.
# resize2fs / dev/vg_tecmint_extra/tecmint_reduce_test
Mount the file system back to the same mount point.
# mount / dev/vg_tecmint_extra/tecmint_reduce_test / mnt/tecmint_reduce_test/
Mount the file system
Check the size of partitions and files.
# lvdisplay vg_tecmint_extra
Here, we can see the final result that the logic has been reduced to 10GB.
In this article, we have learned how to expand volume groups, logical volumes, and reduce logical volumes. In the next section (part 3), we will learn how to take a snapshot of a logical volume and restore it to an earlier state.
Thank you for your reading, the above is the content of "how to expand volume groups, logical volumes and reduce logical volumes LVM in Linux". After the study of this article, I believe you have a deeper understanding of how to expand volume groups, logical volumes and reduce logical volume LVM in Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.