Merge pull request #1521 from GOLinux/master

Translated:20140813 How to Extend or Reduce LVM's (Logical Volume Management) in Linux--Part II.md
This commit is contained in:
joeren 2014-08-22 09:14:11 +08:00
commit 07a4d1fb0f
2 changed files with 292 additions and 284 deletions

View File

@ -1,284 +0,0 @@
translating by cvsher
How to Extend/Reduce LVMs (Logical Volume Management) in Linux Part II
================================================================================
Previously we have seen how to create a flexible disk storage using LVM. Here, we are going to see how to extend volume group, extend and reduce a logical volume. Here we can reduce or extend the partitions in Logical volume management (LVM) also called as flexible volume file-system.
![Extend/Reduce LVMs in Linux](http://www.tecmint.com/wp-content/uploads/2014/08/LVM_extend.jpg)
### Requirements ###
- [Create Flexible Disk Storage with LVM Part I][1]
注:两篇都翻译完了的话,发布的时候将这个链接做成发布的中文的文章地址
#### When do we need to reduce volume? ####
May be we need to create a separate partition for any other use or we need to expand the size of any low space partition, if so we can reduce the large size partition and we can expand the low space partition very easily by the following simple easy steps.
#### My Server Setup Requirements ####
- Operating System CentOS 6.5 with LVM Installation
- Server IP 192.168.0.200
### How to Extend Volume Group and Reduce Logical Volume ###
#### Logical Volume Extending ####
Currently, we have One PV, VG and 2 LV. Lets list them one by one using following commands.
# pvs
# vgs
# lvs
![Logical Volume Extending](http://www.tecmint.com/wp-content/uploads/2014/08/Logical-Volume-Extending.jpg)
Logical Volume Extending
There are no free space available in Physical Volume and Volume group. So, now we cant extend the lvm size, for extending we need to add one physical volume (**PV**), and then we have to extend the volume group by extending the **vg**. We will get enough space to extend the Logical volume size. So first we are going to add one physical volume.
For adding a new **PV** we have to use fdisk to create the LVM partition.
# fdisk -cu /dev/sda
- To Create new partition Press **n**.
- Choose primary partition use **p**.
- Choose which number of partition to be selected to create the primary partition.
- Press **1** if any other disk available.
- Change the type using **t**.
- Type **8e** to change the partition type to Linux LVM.
- Use **p** to print the create partition ( here we have not used the option).
- Press **w** to write the changes.
Restart the system once completed.
![Create LVM Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Create-LVM-Partition.jpg)
Create LVM Partition
List and check the partition we have created using fdisk.
# fdisk -l /dev/sda
![Verify LVM Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-LVM-Partition.jpg)
Verify LVM Partition
Next, create new **PV** (Physical Volume) using following command.
# pvcreate /dev/sda1
Verify the pv using below command.
# pvs
![Create Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Create-Physical-Volume.jpg)
Create Physical Volume
#### Extending Volume Group ####
Add this pv to **vg_tecmint** vg to extend the size of a volume group to get more space for expanding **lv**.
# vgextend vg_tecmint /dev/sda1
Let us check the size of a Volume Group now using.
# vgs
![Extend Volume Group](http://www.tecmint.com/wp-content/uploads/2014/08/Extend-Volume-Group.jpg)
Extend Volume Group
We can even see which **PV** are used to create particular Volume group using.
# pvscan
![Check Volume Group](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Volume-Group.jpg)
Check Volume Group
Here, we can see which Volume groups are under Which Physical Volumes. We have just added one pv and its totally free. Let us see the size of each logical volume we have currently before expanding it.
![Check All Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Each-Logical-Volume.jpg)
Check All Logical Volume
- LogVol00 defined for Swap.
- LogVol01 defined for /.
- Now we have 16.50 GB size for / (root).
- Currently there are 4226 Physical Extend (PE) available.
Now we are going to expand the / partition **LogVol01**. After expanding we can list out the size as above for confirmation. We can extend using GB or PE as I have explained it in LVM PART-I, here Im using PE to extend.
For getting the available Physical Extend size run.
# vgdisplay
![Check Available Physical Size](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Available-Physical-Extend.jpg)
Check Available Physical Size
There are **4607** free PE available = **18GB** Free space available. So we can expand our logical volume up-to **18GB** more. Let us use the PE size to extend.
# lvextend -l +4607 /dev/vg_tecmint/LogVol01
Use **+** to add the more space. After Extending, we need to re-size the file-system using.
# resize2fs /dev/vg_tecmint/LogVol01
![Expand Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Expand-Logical-Volume.jpg)
Expand Logical Volume
- Command used to extend the logical volume using Physical extends.
- Here we can see it is extended to 34GB from 16.51GB.
- Re-size the file system, If the file-system is mounted and currently under use.
- For extending Logical volumes we dont need to unmount the file-system.
Now lets see the size of re-sized logical volume using.
# lvdisplay
![Resize Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Resize-Logical-Volume.jpg)
Resize Logical Volume
- LogVol01 defined for / extended volume.
- After extending there is 34.50GB from 16.50GB.
- Current extends, Before extending there was 4226, we have added 4607 extends to expand so totally there are 8833.
Now if we check the vg available Free PE it will be 0.
# vgdisplay
See the result of extending.
# pvs
# vgs
# lvs
![Verify Resize Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-Resize-Partition.jpg)
Verify Resize Partition
- New Physical Volume added.
- Volume group vg_tecmint extended from 17.51GB to 35.50GB.
- Logical volume LogVol01 extended from 16.51GB to 34.50GB.
Here we have completed the process of extending volume group and logical volumes. Let us move towards some interesting part in Logical volume management.
#### Reducing Logical Volume (LVM) ####
Here we are going to see how to reduce the Logical Volumes. Everyone say its critical and may end up with disaster while we reduce the lvm. Reducing lvm is really interesting than any other part in Logical volume management.
- Before starting, it is always good to backup the data, so that it will not be a headache if something goes wrong.
- To Reduce a logical volume there are 5 steps needed to be done very carefully.
- While extending a volume we can extend it while the volume under mount status (online), but for reduce we must need to unmount the file system before reducing.
Lets wee what are the 5 steps below.
- unmount the file system for reducing.
- Check the file system after unmount.
- Reduce the file system.
- Reduce the Logical Volume size than Current size.
- Recheck the file system for error.
- Remount the file-system back to stage.
For demonstration, I have created separate volume group and logical volume. Here, Im going to reduce the logical volume **tecmint_reduce_test**. Now its 18GB in size. We need to reduce it to **10GB** without data-loss. That means we need to reduce **8GB** out of **18GB**. Already there is **4GB** data in the volume.
18GB ---> 10GB
While reducing size, we need to reduce only 8GB so it will roundup to 10GB after the reduce.
# lvs
![Reduce Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Logical-Volume.jpg)
Reduce Logical Volume
Here we can see the file-system information.
# df -h
![Check File System Size](http://www.tecmint.com/wp-content/uploads/2014/08/Check-File-System-Size.jpg)
Check File System Size
- The size of the Volume is 18GB.
- Already it used upto 3.9GB.
- Available Space is 13GB.
First unmount the mount point.
# umount -v /mnt/tecmint_reduce_test/
![Unmount Parition](http://www.tecmint.com/wp-content/uploads/2014/08/Unmount-Parition.jpg)
Unmount Parition
Then check for the file-system error using following command.
# e2fsck -ff /dev/vg_tecmint_extra/tecmint_reduce_test
![Scan Parition for Errors](http://www.tecmint.com/wp-content/uploads/2014/08/Scan-Parition-for-Errors.jpg)
Scan Parition for Errors
**Note**: Must pass in every 5 steps of file-system check if not there might be some issue with your file-system.
Next, reduce the file-system.
# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test 8GB
![Reduce File System](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-File-System.jpg)
Reduce File System
Reduce the Logical volume using GB size.
# lvreduce -L -8G /dev/vg_tecmint_extra/tecmint_reduce_test
![Reduce Logical Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Logical-Volume-Partition.jpg)
Reduce Logical Partition
To Reduce Logical volume using PE Size we need to Know the size of default PE size and total PE size of a Volume Group to put a small calculation for accurate Reduce size.
# lvdisplay vg_tecmint_extra
Here we need to do a little calculation to get the PE size of 10GB using bc command.
1024MB x 10GB = 10240MB or 10GB
10240MB / 4PE = 2048PE
Press **CRTL+D** to exit from BC.
![Calculate PE Size](http://www.tecmint.com/wp-content/uploads/2014/08/bc-command.jpg)
Calculate PE Size
Reduce the size using PE.
# lvreduce -l -2048 /dev/vg_tecmint_extra/tecmint_reduce_test
![Reduce Size Using PE](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Size-Using-PE.jpg)
Reduce Size Using PE
Re-size the file-system back, In this step if there is any error that means we have messed-up our file-system.
# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test
![Resize File System](http://www.tecmint.com/wp-content/uploads/2014/08/Resize-File-System.jpg)
Mount the file-system back to same point.
# mount /dev/vg_tecmint_extra/tecmint_reduce_test /mnt/tecmint_reduce_test/
![Mount File System](http://www.tecmint.com/wp-content/uploads/2014/08/Mount-File-System.jpg)
Mount File System
Check the size of partition and files.
# lvdisplay vg_tecmint_extra
Here we can see the final result as the logical volume was reduced to 10GB size.
![Verify Logical Volume Size](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-Logical-Volume-Size.jpg)
In this article, we have seen how to extend the volume group, logical volume and reduce the logical volume. In the next part (Part III), we will see how to take a Snapshot of logical volume and restore it to earlier stage.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/extend-and-reduce-lvms-in-linux/
作者:[Babin Lonston][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/babinlonston/
[1]:http://www.tecmint.com/create-lvm-storage-in-linux/

View File

@ -0,0 +1,292 @@
在Linux中扩展/缩减LVM逻辑卷管理—— 第二部分
================================================================================
前面我们已经了解了怎样使用LVM创建弹性的磁盘存储。这里我们将了解怎样来扩展卷组扩展和缩减逻辑卷。在这里我们可以缩减或者扩展逻辑卷管理LVM中的分区LVM也可称之为弹性卷文件系统。
![Extend/Reduce LVMs in Linux](http://www.tecmint.com/wp-content/uploads/2014/08/LVM_extend.jpg)
### 需求 ###
- [使用LVM创建弹性磁盘存储——第一部分][1]
注:两篇都翻译完了的话,发布的时候将这个链接做成发布的中文的文章地址
#### 什么时候我们需要缩减卷? ####
或许我们需要创建一个独立的分区用于其它用途,或者我们需要扩展任何空间低的分区。真是这样的话,我们可以很容易地缩减大尺寸的分区,并且扩展空间低的分区,只要按下面几个简易的步骤来即可。
#### 我的服务器设置 —— 需求 ####
- 操作系统 安装有LVM的CentOS 6.5
- 服务器IP 192.168.0.200
### 如何扩展卷组以及缩减逻辑卷 ###
#### 逻辑卷扩展 ####
目前我们已经有一个PVVG和2个LV。让我们用下面的命令来列出它们。
# pvs
# vgs
# lvs
![Logical Volume Extending](http://www.tecmint.com/wp-content/uploads/2014/08/Logical-Volume-Extending.jpg)
逻辑卷扩展
在物理卷和卷组中没有空闲空间可用了,所以,现在我们不能扩展逻辑卷的大小。要扩展,我们需要添加一个物理卷(**PV**),然后通过扩展**vg**来扩展卷组,这样我们就会得到足够大的空间来扩展逻辑卷大小了。所以,首先我们应该去添加一个物理卷。
要添加一个新**PV**我们必须使用fdisk来创建一个LVM分区。
# fdisk -cu /dev/sda
- 选择**n**来创建新分区。
- 选择**p**来创建主分区。
- 选择我们需要创建的分区号。
- 如果有其它可用磁盘,请按**1**。
- 使用**t**来修改分区类型。
- 输入**8e**来将分区类型修改为Linux LVM。
- 使用**p**来打印创建的分区(这里我们没有使用该选项)。
- 按**w**写入修改。
完成后重启系统。
![Create LVM Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Create-LVM-Partition.jpg)
创建LVM分区
使用fdisk列出并检查我们创建的分区。
# fdisk -l /dev/sda
![Verify LVM Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-LVM-Partition.jpg)
验证LVM分区
接下来,使用下列命令来创建新**PV**(物理卷)。
# pvcreate /dev/sda1
使用下面的命令来验证pv。
# pvs
![Create Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Create-Physical-Volume.jpg)
创建物理卷
#### 扩展卷组 ####
添加该pv到**vg_tecmint**卷组来扩展卷组的大小,以获取更多空间来扩展**lv**。
# vgextend vg_tecmint /dev/sda1
让我们检查现在正在使用的卷组的大小。
# vgs
![Extend Volume Group](http://www.tecmint.com/wp-content/uploads/2014/08/Extend-Volume-Group.jpg)
扩展卷组
我们甚至可以看到哪个**PV**用于创建使用中的特定卷组。
# pvscan
![Check Volume Group](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Volume-Group.jpg)
检查卷组
这里我们可以看到卷组所处的物理卷。我们已经添加了一个pv而且它完全空着。在扩展逻辑卷之前让我们先看看我们所拥有的各个卷组的大小。
![Check All Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Each-Logical-Volume.jpg)
检查所有逻辑卷
- LogVol00用于Swap。
- LogVol01用于/。
- 现在我们有16.50GB大小的空间用于/root
- 当前有4226物理扩展PE可用。
现在,我们打算去扩展/分区**LogVol01**。在扩展后我们可以像上面那样列出它的大小以确认。我们能可以使用GB或PE来扩展这一点我已经在LVM第一部分解释过了这里我使用PE来扩展。
要获取可用的物理扩展大小,运行以下命令。
# vgdisplay
![Check Available Physical Size](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Available-Physical-Extend.jpg)
检查可用的物理扩展
总共有**4607**空闲PE可用亦即有**18GB**空间空间可用。因此,我们可以将我们的逻辑卷扩展到**18GB**这么大。让我们使用PE大小来扩展。
# lvextend -l +4607 /dev/vg_tecmint/LogVol01
使用**+**来添加更多空间。在扩展后,我们需要改变文件系统大小,使用以下命令。
# resize2fs /dev/vg_tecmint/LogVol01
![Expand Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Expand-Logical-Volume.jpg)
扩展逻辑卷
- 用来使用物理扩展扩展逻辑卷的命令。
- 这里我们可以看到它从16.51GB扩展到了34GB。
- 如果文件系统已被挂载并处于使用中,改变文件系统大小。
- 要扩展逻辑卷,我们不需要卸载文件系统
现在,让我们看看当前使用的改变大小后的逻辑卷。
# lvdisplay
![Resize Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Resize-Logical-Volume.jpg)
改变逻辑卷大小
- LogVol01用于扩展的卷 /。
- 扩展后从16.50GB上升到了34.50GB。
- C当前扩展在扩展前有4226我们已经添加了4607个扩展因此现在有8833。
现在如果我们检查可用的vg的话空闲PE将会是0。
# vgdisplay
查看扩展的结果。
# pvs
# vgs
# lvs
![Verify Resize Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-Resize-Partition.jpg)
验证分区大小改变
- 添加的新物理卷。
- 卷组vg_tecmint从17.51GB扩展到了35.50GB。
- 逻辑卷LogVol01从16.51GB扩展到了34.50GB。
这里,我们已经完成扩展卷组和逻辑卷的过程。让我们一起迈向逻辑卷管理中一些有趣的部分。
#### 缩减逻辑卷LVM ####
这里我们将了解如何缩减逻辑卷。人人都说它很危险在缩减lvm的时候可能会导致灾难。缩减lvm在逻辑卷管理中比其它部分要来得确实有趣得多。
- 在开始之前,备份好数据总是对的,这样如果出错,就不会头痛了。
- 要缩减逻辑卷需要小心翼翼地完成5个步骤。
- 在扩展一个卷的时候,我们可以在该卷挂载时扩展它(在线),但对于缩减,我们必须在缩减前卸载文件系统。
让我们来了解一下下面这5个步骤。
- 卸载文件系统以便缩减。
- 在卸载后检查文件系统。
- 缩减文件系统。
- 5减少当前逻辑卷大小。
- 再检查文件系统以防出错。
- 将文件系统再次挂载回去。
为了演示,我已经创建了独立的卷组和逻辑卷。这里,我将缩减逻辑卷**tecmint_reduce_test**。现在它有18GB大小我们需要将它缩减到**10GB**而不丢失数据。也就是说,我们需要从**18GB**中减少**8GB**。卷中已经有**4GB**被使用。
18GB ---> 10GB
在缩减大小的时候我们只需要缩减8GB所以在缩减后它总计会有10GB。
# lvs
![Reduce Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Logical-Volume.jpg)
缩减逻辑卷
这里,我们可以看到文件系统信息。
# df -h
![Check File System Size](http://www.tecmint.com/wp-content/uploads/2014/08/Check-File-System-Size.jpg)
检查文件系统大小
- 卷大小是18GB。
- 它已经使用了3.9GB。
- 可用空间是13GB。
首先,卸载挂载点。
# umount -v /mnt/tecmint_reduce_test/
![Unmount Parition](http://www.tecmint.com/wp-content/uploads/2014/08/Unmount-Parition.jpg)
卸载分区
然后,使用以下命令来检查文件系统错误。
# e2fsck -ff /dev/vg_tecmint_extra/tecmint_reduce_test
![Scan Parition for Errors](http://www.tecmint.com/wp-content/uploads/2014/08/Scan-Parition-for-Errors.jpg)
扫描分区错误
**注意**必须通过所有文件系统检查的5个步骤若未完全通过则你的文件系统可能存在问题。
接下来,缩减文件系统。
# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test 8GB
![Reduce File System](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-File-System.jpg)
缩减文件系统
使用GB来缩减逻辑卷。
# lvreduce -L -8G /dev/vg_tecmint_extra/tecmint_reduce_test
![Reduce Logical Partition](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Logical-Volume-Partition.jpg)
缩减逻辑分区
要使用PE来缩减逻辑卷我们需要知道默认PE大小和卷组的总PE大小以进行一次小小的计算来得出准确的缩减大小。
# lvdisplay vg_tecmint_extra
这里我们需要使用bc命令来做一些小计算来获得10GB的PE大小。
1024MB x 10GB = 10240MB or 10GB
10240MB / 4PE = 2048PE
按**CTRL+D**来退出BC。
![Calculate PE Size](http://www.tecmint.com/wp-content/uploads/2014/08/bc-command.jpg)
计算PE大小
使用PE来缩减大小。
# lvreduce -l -2048 /dev/vg_tecmint_extra/tecmint_reduce_test
![Reduce Size Using PE](http://www.tecmint.com/wp-content/uploads/2014/08/Reduce-Size-Using-PE.jpg)
使用PE来缩减大小
将文件系统大小调整回去。在这一步中,如果发生任何错误,这就意味着我们已经将文件系统搞乱了。
# resize2fs /dev/vg_tecmint_extra/tecmint_reduce_test
![Resize File System](http://www.tecmint.com/wp-content/uploads/2014/08/Resize-File-System.jpg)
将文件系统挂载回同样的挂载点。
# mount /dev/vg_tecmint_extra/tecmint_reduce_test /mnt/tecmint_reduce_test/
![Mount File System](http://www.tecmint.com/wp-content/uploads/2014/08/Mount-File-System.jpg)
挂载文件系统
检查分区和文件的大小。
# lvdisplay vg_tecmint_extra
这里我们可以看到最后的结果逻辑已经被缩减到10GB。
![Verify Logical Volume Size](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-Logical-Volume-Size.jpg)
在本文中,我们已经了解了如何来扩增卷组、逻辑卷以及缩减逻辑卷。在下一部分(第三部分)中,我们将了解如何为逻辑卷做快照并将它恢复到更早的状态。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/extend-and-reduce-lvms-in-linux/
作者:[Babin Lonston][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/babinlonston/
[1]:http://www.tecmint.com/create-lvm-storage-in-linux/