本站使用了 Pjax 等基于 JavaScript 的开发技术,但您的浏览器已禁用 JavaScript,请开启 JavaScript 以保证网站正常显示!

逻辑卷迁移指南

适用条件:需要大规模拷贝磁盘文件的场景
实验环境说明:

  • 两台CentOS 7主机,一台为逻辑卷迁出服务器(主机名:host1),另一台为迁入目标主机(主机名:devel)

1.首先,我们看一下迁出服务器的磁盘分区结构,如下:

[root@host1 ~]# lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                   8:0    0  100G  0 disk
├─sda1                8:1    0  476M  0 part /boot
├─sda2                8:2    0 23.3G  0 part /
├─sda3                8:3    0 23.3G  0 part /APP
├─sda4                8:4    0    1K  0 part
├─sda5                8:5    0  1.9G  0 part [SWAP]
└─sda6                8:6    0  286M  0 part
sdb                   8:16   0   10G  0 disk
├─sdb1                8:17   0    1G  0 part
│ └─vg_test-lv_test 253:0    0    2G  0 lvm  /mnt/lv_mount
├─sdb2                8:18   0    1G  0 part
│ └─vg_test-lv_test 253:0    0    2G  0 lvm  /mnt/lv_mount
└─sdb3                8:19   0    1G  0 part
  └─vg_test-lv_test 253:0    0    2G  0 lvm  /mnt/lv_mount

接下来,我们看一下当前系统挂载情况,如下:

本文来源:芝麻实验室

[root@host1 ~]# df
Filesystem                  1K-blocks    Used Available Use% Mounted on
/dev/sda2                    24401264 3626304  20774960  15% /
devtmpfs                       485308       0    485308   0% /dev
tmpfs                          499980      88    499892   1% /dev/shm
tmpfs                          499980    7304    492676   2% /run
tmpfs                          499980       0    499980   0% /sys/fs/cgroup
/dev/sda3                    24401264   32944  24368320   1% /APP
/dev/sda1                      484004  163704    320300  34% /boot
tmpfs                          100000       8     99992   1% /run/user/0
/dev/mapper/vg_test-lv_test   1998672    6144   1871288   1% /mnt/lv_mount

2.通过上面的信息,我们看到当前系统内存在逻辑卷lv_test,即目标迁移逻辑卷。为了更好的体现迁移成功与否,我们向该逻辑卷写入500MB的文件f1

[root@host1 lv_mount]# dd if=/dev/zero of=f1 bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 3.02218 s, 173 MB/s
[root@host1 lv_mount]# ll
total 512016
-rw-r--r--. 1 root root 524288000 Aug 13 18:27 f1
drwx------. 2 root root     16384 Aug 13 18:11 lost+found

3.接下来,我们开始逻辑卷的迁移工作。
由于当前逻辑卷lv_test正在挂载,所以我们需要先执行卸载操作,以保证数据安全和迁移工作的顺利进行

root@host1 ~]# umount /mnt/lv_mount/
[root@host1 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       24401264 3625296  20775968  15% /
devtmpfs          485308       0    485308   0% /dev
tmpfs             499980      88    499892   1% /dev/shm
tmpfs             499980    7304    492676   2% /run
tmpfs             499980       0    499980   0% /sys/fs/cgroup
/dev/sda3       24401264   32944  24368320   1% /APP
/dev/sda1         484004  163704    320300  34% /boot
tmpfs             100000      12     99988   1% /run/user/0

4.为了避免可能存在的卷名冲突,我们需要重命名逻辑卷和卷组(事实上,由于逻辑卷是附着于卷组的,相对于单个卷组来说具有唯一识别性,所以逻辑卷的名称修改并不是必须的)

[root@host1 ~]# vgrename vg_test vg_new
  Volume group "vg_test" successfully renamed to "vg_new"
[root@host1 ~]# lvrename /dev/vg_new/lv_test lv_new
  Renamed "lv_test" to "lv_new" in volume group "vg_new"
[root@host1 ~]# vgs
  VG     #PV #LV #SN Attr   VSize VFree
  vg_new   3   1   0 wz--n- 2.99g 1012.00m
[root@host1 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_new vg_new -wi-a----- 2.00g

5.接下来,设置卷组为非活动状态

[root@host1 ~]# vgchange -an vg_new
  0 logical volume(s) in volume group "vg_new" now active

6.输出卷组,使系统不再识别该卷组

[root@host1 ~]# vgexport vg_new
  Volume group "vg_new" successfully exported
[root@host1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_new
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             exported/resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               2.99 GiB
  PE Size               4.00 MiB
  Total PE              765
  Alloc PE / Size       512 / 2.00 GiB
  Free  PE / Size       253 / 1012.00 MiB
  VG UUID               MPoXHg-wUZB-LcsA-T7y2-5xyA-dDnJ-IsA7iY

7.到这里,从宿主机上迁移逻辑卷的操作就基本结束了,但别忘了删除原先的挂载信息,以免开机无法启动

[root@host1 ~]# sed -i.bak '/lv_mount/d' /etc/fstab
[root@host1 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Jul 14 11:15:48 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=afedc130-7796-4497-808c-696143748953 /                       xfs     defaults        0 0
UUID=941d3e57-d5a3-4362-8fd0-beac08d855a4 /APP                    xfs     defaults        0 0
UUID=2e3cbe4a-cc4b-483e-b4e6-35029865dfe8 /boot                   xfs     defaults        0 0
UUID=9c88c881-8c99-4df4-814f-8e47adf83fa8 swap                    swap    defaults        0 0
[root@host1 ~]# ll /etc/|grep fstab
-rw-r--r--.  1 root root      595 Aug 13 21:24 fstab
-rw-r--r--.  1 root root      669 Aug 13 18:15 fstab.bak

8.从host1主机中拆除该硬盘
9.向devel主机载入刚从host1主机拆除的硬盘,然后重启(或在终端输入 echo "- - -" >> /sys/class/scsi_host/host2/scan)
10.查看devel主机分区信息

[root@devel ~]# lsblk
NAME                        MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda                           8:0    0  100G  0 disk
├─sda1                        8:1    0  476M  0 part  /boot
├─sda2                        8:2    0  7.5G  0 part  [SWAP]
├─sda3                        8:3    0 65.2G  0 part  /
├─sda4                        8:4    0    1K  0 part
├─sda5                        8:5    0  9.3G  0 part  /mnt/lfs
├─sda6                        8:6    0    1G  0 part  /mnt/quto
├─sda7                        8:7    0    1G  0 part
│ └─md5                       9:5    0    2G  0 raid5
├─sda8                        8:8    0    1G  0 part
│ └─md1                       9:1    0 1023M  0 raid1 /backup
├─sda9                        8:9    0    1G  0 part
│ └─md1                       9:1    0 1023M  0 raid1 /backup
├─sda10                       8:10   0    1G  0 part
│ └─md5                       9:5    0    2G  0 raid5
├─sda11                       8:11   0    1G  0 part
│ └─md5                       9:5    0    2G  0 raid5
├─sda12                       8:12   0    1G  0 part
│ └─md5                       9:5    0    2G  0 raid5
└─sda13                       8:13   0    5G  0 part
sdb                           8:16   0   10G  0 disk
├─sdb1                        8:17   0    1G  0 part
│ └─vg_new-lv_new           253:0    0    2G  0 lvm
├─sdb2                        8:18   0    1G  0 part
│ └─vg_new-lv_new           253:0    0    2G  0 lvm
└─sdb3                        8:19   0    1G  0 part
  └─vg_new-lv_new           253:0    0    2G  0 lvm

11.载入卷组

请保留出处

[root@devel ~]# vgimport vg_new
  Volume group "vg_new" successfully imported

12.激活卷组(即修改为活动状态)

This article is not authorized to post. Get authorization.
[root@devel ~]# vgchange -ay vg_new
[root@devel ~]# vgdisplay vg_new
  --- Volume group ---
  VG Name               vg_new
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               2.99 GiB
  PE Size               4.00 MiB
  Total PE              765
  Alloc PE / Size       512 / 2.00 GiB
  Free  PE / Size       253 / 1012.00 MiB
  VG UUID               MPoXHg-wUZB-LcsA-T7y2-5xyA-dDnJ-IsA7iY

13.创建挂载点,并挂载

[root@devel ~]# mkdir /mnt/test_mount
[root@devel ~]# blkid /dev/vg_new/lv_new
/dev/vg_new/lv_new: UUID="dc65b428-5401-48eb-850e-b1d57a52c822" TYPE="ext4"
[root@devel ~]# echo "UUID=dc65b428-5401-48eb-850e-b1d57a52c822 /mnt/test_mount ext4 defaults 0 0" >> /etc/fstab
[root@devel test_mount]# df
Filesystem                1K-blocks     Used Available Use% Mounted on
/dev/sda3                  68325792 30208512  38117280  45% /
devtmpfs                     919064        0    919064   0% /dev
tmpfs                        933624       88    933536   1% /dev/shm
tmpfs                        933624     1132    932492   1% /run
tmpfs                        933624        0    933624   0% /sys/fs/cgroup
/dev/sda6                    999320     2572    927936   1% /mnt/quto
/dev/sda5                   9481408    36900   8939832   1% /mnt/lfs
/dev/md1                    1014680     2564    943356   1% /backup
/dev/sda1                    484004   217164    266840  45% /boot
/dev/mapper/betavg-betalv   2086912   544944   1541968  27% /mnt/mount
tmpfs                        186728       16    186712   1% /run/user/0
/dev/mapper/vg_new-lv_new   1998672   518148   1359284  28% /mnt/test_mount
[root@devel ~]# mount -a

14.查看是否迁移成功

From: 芝麻实验室

[root@devel ~]# cd /mnt/test_mount/
[root@devel test_mount]# ll -h        # 我们看到 之前创建的500MB的文件f1完整存在 迁移成功
total 501M
-rw-r--r--. 1 root root 500M Aug 13 18:27 f1
drwx------. 2 root root  16K Aug 13 18:11 lost+found

15.迁移完成。


 继续浏览关于 的文章

 本文最后更新于 2018/04/30 04:27:33,可能因经年累月而与现状有所差异

 引用转载请注明:芝麻实验室 > > 逻辑卷迁移指南

发现共鸣

如是说:难受就是难受…不要让开心变成一种负担…