Merge pull request #1847 from GOLinux/master

[Translated] 20141013 Migrating LVM Partitions to New Logical Volume(Drive)--Part VI.md
This commit is contained in:
joeren 2014-10-16 09:09:14 +08:00
commit 6f23695b2d
2 changed files with 197 additions and 210 deletions

View File

@ -1,210 +0,0 @@
Translating by GOLinux!
Migrating LVM Partitions to New Logical Volume (Drive) Part VI
================================================================================
This is the 6th part of our ongoing Logical Volume Management series, in this article we will show you how to migrate existing logical volumes to other new drive without any downtime. Before moving further, I would like to explain you about LVM Migration and its features.
![LVM Storage Migration](http://www.tecmint.com/wp-content/uploads/2014/10/LVM-Migrations.png)
LVM Storage Migration
### What is LVM Migration? ###
**LVM** migration is one of the excellent feature, where we can migrate the logical volumes to a new disk without the data-loss and downtime. The purpose of this feature is it to move our data from old disk to a new disk. Usually, we do migrations from one disk to other disk storage, only when an error occur in some disks.
### Features of Migration ###
- Moving logical volumes from one disk to other disk.
- We can use any type of disk like SATA, SSD, SAS, SAN storage iSCSI or FC.
- Migrate disks without data loss and downtime.
In LVM Migration, we will swap every volumes, file-system and its data in the existing storage. For example, if we have a single Logical volume, which has been mapped to one of the physical volume, that physical volume is a physical hard-drive.
Now if we need to upgrade our server with SSD Hard-drive, what we used to think at first? reformat of disk? No! we dont have to reformat the server. The LVM has the option to migrate those old SATA Drives with new SSD Drives. The Live migration will support any kind of disks, be it local drive, SAN or Fiber channel too.
#### My Server Setup ####
Operating System : CentOS 6.5 Final
IP Address : 192.168.0.224
System Hostname : lvmmig.tecmintlocal.com
### Step 1: Check for Present Drives ###
**1.** Assume we are already having one virtual drive named “**vdb**“, which mapped to one of the logical volume “**tecmint_lv**“. Now we want to migrate this “**vdb**” logical volume drive to some other new storage. Before moving further, first verify that the virtual drive and logical volume names with the help of **fdisk** and lvs commands as shown.
# fdisk -l | grep vd
# lvs
![Check Logical Volume Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Logical-Volume-Disk.png)
Check Logical Volume Disk
### Step 2: Check for Newly added Drive ###
**2.** Once we confirm our existing drives, now its time to attach our new SSD drive to system and verify newly added drive with the help of fdisk command.
# fdisk -l | grep dev
![Check New Added Drive](http://www.tecmint.com/wp-content/uploads/2014/10/Check-New-Added-Drive.png)
Check New Added Drive
**Note**: Did you see in the above screen, that the new drive has been added successfully with name “**/dev/sda**“.
### Step 3: Check Present Logical and Physical Volume ###
**3.** Now move forward to create physical volume, volume group and logical volume for migration. Before creating volumes, make sure to check the present logical volume data under **/mnt/lvm** mount point. Use the following commands to list the mounts and check the data.
# df -h
# cd /mnt/lvm
# cat tecmint.txt
![Check Logical Volume Data](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Logical-Volume-Data.png)
Check Logical Volume Data
**Note**: For demonstration purpose, weve created two files under **/mnt/lvm** mount point, and we migrate these data to a new drive without any downtime.
**4.** Before migrating, make sure to confirm the names of logical volume and volume group for which physical volume is related to and also confirm which physical volume used to hold this volume group and logical volume.
# lvs
# vgs -o+devices | grep tecmint_vg
![Confirm Logical Volume Names](http://www.tecmint.com/wp-content/uploads/2014/10/Confirm-Logical-Volume-Names.png)
Confirm Logical Volume Names
**Note**: Did you see in the above screen, that “**vdb**” holds the volume group **tecmint_vg**.
### Step 4: Create New Physical Volume ###
**5.** Before creating Physical Volume in our new added SSD Drive, we need to define the partition using fdisk. Dont forget to change the Type to LVM(8e), while creating partitions.
# pvcreate /dev/sda1 -v
# pvs
![Create Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/10/Create-Physical-Volume.png)
Create Physical Volume
**6.** Next, add the newly created physical volume to existing volume group tecmint_vg using vgextend command
# vgextend tecmint_vg /dev/sda1
# vgs
![Add Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/10/Add-Physical-Volume.png)
Add Physical Volume
**7.** To get the full list of information about volume group use vgdisplay command.
# vgdisplay tecmint_vg -v
![List Volume Group Info](http://www.tecmint.com/wp-content/uploads/2014/10/List-Volume-Group-Info.png)
List Volume Group Info
**Note**: In the above screen, we can see at the end of result as our PV has added to the volume group.
**8.** If in-case, we need to know more information about which devices are mapped, use the **dmsetup** dependency command.
# lvs -o+devices
# dmsetup deps /dev/tecmint_vg/tecmint_lv
In the above results, there is **1** dependencies (PV) or (Drives) and here **17** were listed. If you want to confirm look into the devices, which has major and minor number of drives that are attached.
# ls -l /dev | grep vd
![List Device Information](http://www.tecmint.com/wp-content/uploads/2014/10/List-Device-Information.png)
List Device Information
**Note**: In the above command, we can see that major number with **252** and minor number **17** is related to **vdb1**. Hope you understood from above command output.
### Step 5: LVM Mirroring Method ###
**9.** Now its time to do migration using Mirroring method, use **lvconvert** command to migrate data from old logical volume to new drive.
# lvconvert -m 1 /dev/tecmint_vg/tecmint_lv /dev/sda1
- **-m** = mirror
- **1** = adding a single mirror
![Mirroring Method Migration](http://www.tecmint.com/wp-content/uploads/2014/10/Mirroring-Method-Migration.png)
Mirroring Method Migration
**Note**: The above migration process will take long time according to our volume size.
**10.** Once migration process completed, verify the converted mirror.
# lvs -o+devices
![Verify Converted Mirror](http://www.tecmint.com/wp-content/uploads/2014/10/Verify-Converted-Mirror.png)
Verify Converted Mirror
**11.** Once you sure that the converted mirror is perfect, you can remove the old virtual disk **vdb1**. The option **-m** will remove the mirror, earlier weve used **1** for adding the mirror.
# lvconvert -m 0 /dev/tecmint_vg/tecmint_lv /dev/vdb1
![Remove Virtual Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Remove-Virtual-Disk.png)
Remove Virtual Disk
**12.** Once old virtual disk is removed, you can re-check the devices for logical volumes using following command.
# lvs -o+devices
# dmsetup deps /dev/tecmint_vg/tecmint_lv
# ls -l /dev | grep sd
![Check New Mirrored Device](http://www.tecmint.com/wp-content/uploads/2014/10/Check-New-Mirrored-Device.png)
Check New Mirrored Device
In the above picture, did you see that our logical volume now depends on **8,1** and has **sda1**. This indicates that our migration process is done.
**13.** Now verify the files that weve migrated from old to new drive. If same data is present at the new drive, that means we have done every steps perfectly.
# cd /mnt/lvm/
# cat tecmin.txt
![Check Mirrored Data](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Mirrored-Data.png)
Check Mirrored Data
**14.** After everything perfectly created, now its time to delete the **vdb1** from volume group and later confirm, which devices are depends on our volume group.
# vgreduce /dev/tecmint_vg /dev/vdb1
# vgs -o+devices
**15.** After removing vdb1 from volume group **tecmint_vg**, still our logical volume is present there because we have migrated it to **sda1** from **vdb1**.
# lvs
![Delete Virtual Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Delete-Virtual-Disk.png)
Delete Virtual Disk
### Step 6: LVM pvmove Mirroring Method ###
**16.** Instead using **lvconvert** mirroring command, we use here **pvmove** command with option **-n** (logical volume name) method to mirror data between two devices.
# pvmove -n /dev/tecmint_vg/tecmint_lv /dev/vdb1 /dev/sda1
The command is one of the simplest way to mirror the data between two devices, but in real environment **Mirroring** is used more often than **pvmove**.
### Conclusion ###
In this article, we have seen how to migrate the logical volumes from one drive to other. Hope you have learnt new tricks in logical volume management. For such setup one should must know about the basic of logical volume management. For basic setups, please refer to the links provided on top of the article at requirement section.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/lvm-storage-migration/#comment-331336
作者:[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/

View File

@ -0,0 +1,197 @@
迁移LVM分区到新的逻辑卷驱动器——第六部分
================================================================================
这是我们正在开展的逻辑卷管理系列的第六部分。在本文中我们将为大家展示怎样来在线将现存的逻辑卷迁移到其它新的驱动器。在开始之前我想要先来介绍一下LVM迁移及其特性。
![LVM Storage Migration](http://www.tecmint.com/wp-content/uploads/2014/10/LVM-Migrations.png)
LVM存储迁移
### 什么是LVM迁移 ###
**LVM**迁移是LVM众多优秀特性之一通过它我们可以迁移逻辑卷到一个新的磁盘而不会丢失数据也不用关机操作。该特性的功能是将数据从旧磁盘移动到新磁盘。通常我们只是在一些磁盘发生错误时才将数据从一个磁盘迁移到另外一个磁盘存储。
### 迁移特性 ###
- 将逻辑卷从一个磁盘移动到另一个磁盘。
- 我们可以使用任何类型的磁盘如SATA、SSD、SAS、SAN storage iSCSI或者FC。
- 在线迁移磁盘,而且数据不会丢失。
在LVM迁移中我们将交换各个卷、文件系统以及位于现存存储中的数据。例如如果我们有一个单一逻辑卷它已经映射到了物理卷而该物理卷是一个物理硬盘驱动器。
现在如果我们需要升级服务器存储为SSD硬盘驱动器我们首先需要考虑什么重新格式化磁盘我们不必重新格式化服务器LVM可以选择将这些旧的SATA驱动器上的数据迁移到新的SSD驱动器上。在线迁移将会支持任何类型的磁盘不管是本地驱动器还是SAN或者光纤通道都可以。
#### 我的服务器设置 ####
操作系统: CentOS 6.5 Final
IP地址 192.168.0.224
系统主机名: lvmmig.tecmintlocal.com
### 步骤1 检查当前驱动器 ###
**1.**假设我们已经有一个名为“**vdb**”的虚拟驱动器,它已经被映射到了其中一个逻辑卷“**tecmint_lv**”。现在,我们想要迁移“**vdb**”这个逻辑卷到其它某个新的存储设备中。在开始之前,首先在下面所示的**fdisk**和lvs命令的帮助下验证该虚拟驱动器。
# fdisk -l | grep vd
# lvs
![Check Logical Volume Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Logical-Volume-Disk.png)
检查逻辑卷磁盘
### 步骤2 检查新添加的驱动器 ###
**2.**在我们确认了现存驱动器后现在是时候来将新的SSD驱动器连接到系统并在fdisk命令的帮助下验证新添加的驱动器了。
# fdisk -l | grep dev
![Check New Added Drive](http://www.tecmint.com/wp-content/uploads/2014/10/Check-New-Added-Drive.png)
检查新添加的驱动器
**注意**:你看到上面屏幕中的内容了吗?新的驱动器已经被成功添加了,其名称为“**/dev/sda**”。
### 步骤3 检查当前逻辑和物理卷 ###
**3.**现在,让我们开始创建物理卷、卷组和逻辑卷以用于迁移。在创建卷时,确保检查**/mnt/lvm**挂载点下的当前逻辑卷的数据。用以下命令来列出挂载点并检查数据。
# df -h
# cd /mnt/lvm
# cat tecmint.txt
![Check Logical Volume Data](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Logical-Volume-Data.png)
检查逻辑卷数据
**注意**:出于演示的目的,我们已经在**/mnt/lvm**挂载点下创建了两个文件,我们将在线将这些数据迁移到新的驱动器中。
**4.**在迁移之前,确保对确认与物理卷相关的逻辑卷和卷组名称,并且确认哪个物理卷用于容纳该卷组和逻辑卷。
# lvs
# vgs -o+devices | grep tecmint_vg
![Confirm Logical Volume Names](http://www.tecmint.com/wp-content/uploads/2014/10/Confirm-Logical-Volume-Names.png)
确认逻辑卷名称
**注意**:看到上面屏幕中的内容了吗?“**vdb**”容纳了卷组**tecmint_vg**。
### 步骤4 创建新物理卷 ###
**5.**在在我们新添加的SSD驱动器中创建物理卷之前我们需要使用fdisk来定义分区。在创建分区时别忘了修改分区类型为LVM8e
# pvcreate /dev/sda1 -v
# pvs
![Create Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/10/Create-Physical-Volume.png)
创建物理卷
**6.**接下来使用vgextend命令来添加新创建的物理卷到现存卷组tecmint_vg。
# vgextend tecmint_vg /dev/sda1
# vgs
![Add Physical Volume](http://www.tecmint.com/wp-content/uploads/2014/10/Add-Physical-Volume.png)
添加物理卷
**7.**要获得卷组的完整信息列表请使用vgdisplay命令。
# vgdisplay tecmint_vg -v
![List Volume Group Info](http://www.tecmint.com/wp-content/uploads/2014/10/List-Volume-Group-Info.png)
列出卷组信息
**注意**在上面屏幕中我们可以看到在输出结果的结束处我们的PV已经添加到了卷组中。
**8.**如果我们需要知道更多关于哪些设备被映射的信息,请使用‘**dmsetup**’依赖命令。
# lvs -o+devices
# dmsetup deps /dev/tecmint_vg/tecmint_lv
在上面的结果中,有个**1个**依赖PV驱动器而这里**17**被列出了。如果你想要检查设备,那些关联的有着主、次设备号的驱动器,以确认,使用下面的命令。
# ls -l /dev | grep vd
![List Device Information](http://www.tecmint.com/wp-content/uploads/2014/10/List-Device-Information.png)
列出设备信息
**注意**:在上面的命令中,我们可以看到主设备号是**252**,次设备号是**17**,它连接到了**vdb1**。希望你理解了上面命令的输出。
### 步骤5 LVM镜像法 ###
**9.**现在,该使用镜像法来进行迁移了。使用‘**lvconvert**’命令来将数据从旧逻辑卷迁移到新驱动器。
# lvconvert -m 1 /dev/tecmint_vg/tecmint_lv /dev/sda1
- **-m** = 镜像
- **1** = 添加单个镜像
![Mirroring Method Migration](http://www.tecmint.com/wp-content/uploads/2014/10/Mirroring-Method-Migration.png)
镜像法迁移
**注意**:上面的迁移过程根据卷的大小会花费一段时间。
**10.**在迁移过程完成后,验证转换的镜像。
# lvs -o+devices
![Verify Converted Mirror](http://www.tecmint.com/wp-content/uploads/2014/10/Verify-Converted-Mirror.png)
验证转换的镜像
**11.**当你确认转换的镜像没有任何问题后,你可以移除旧的虚拟磁盘**vdb1**。**-m**选项将移除镜像,先前我们使用**l**来添加镜像。
# lvconvert -m 0 /dev/tecmint_vg/tecmint_lv /dev/vdb1
![Remove Virtual Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Remove-Virtual-Disk.png)
移除虚拟磁盘
**12.**在旧虚拟磁盘移除后,你可以使用以下命令来再次检查逻辑卷设备。
# lvs -o+devices
# dmsetup deps /dev/tecmint_vg/tecmint_lv
# ls -l /dev | grep sd
![Check New Mirrored Device](http://www.tecmint.com/wp-content/uploads/2014/10/Check-New-Mirrored-Device.png)
检查新镜像的设备
在上面的图片中,你看到了吗?我们的逻辑卷现在依赖于**8,1**,名称为**sda1**。这说明我们的迁移过程已经完成了。
**13.**现在验证我们从旧驱动器上迁移过来的文件。如果在新驱动器中的数据与原数据一样,那就说明我们每一步都完成得很完美。
# cd /mnt/lvm/
# cat tecmin.txt
![Check Mirrored Data](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Mirrored-Data.png)
检查镜像的数据
# vgreduce /dev/tecmint_vg /dev/vdb1
# vgs -o+devices
**14.**在所有的都被完美创建后,现在该从卷组中删除**vdb1**并进行再次确认,哪些设备依赖于我们的卷组。
**15.**在从卷组**tecmint_vg**移除vdb1后我们的逻辑卷还在那儿因为我们已经将它从**vdb1**迁移到了**sda1**。
# lvs
![Delete Virtual Disk](http://www.tecmint.com/wp-content/uploads/2014/10/Delete-Virtual-Disk.png)
删除虚拟磁盘
### 步骤6 LVM pvmove镜像法 ###
**16.**我们可以使用带有‘**-n**’(逻辑卷名称)选项的‘**pvmove**’命令来取代‘**lvconvert**’镜像命令,在两个设备间进行数据镜像。
# pvmove -n /dev/tecmint_vg/tecmint_lv /dev/vdb1 /dev/sda1
该命令是在两个设备间镜像数据的最简单的一个,但是在真实环境中,**镜像**比**pvmove**使用得更为频繁。
### 结尾 ###
在本文中,我们介绍了怎样将逻辑卷从一个驱动器迁移到另一个驱动器。希望你已经掌握了逻辑卷管理中这一新的技巧。对于该配置,必须建立在掌握逻辑卷管理基础技能的基础上。对于基础配置,请参阅本文顶部需求章节中提供的链接。
--------------------------------------------------------------------------------
via: http://www.tecmint.com/lvm-storage-migration/#comment-331336
作者:[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/