在 mdadm 降级的 RAID 阵列之上缩小 LVM 物理卷,添加备用并重建它

Neu*_*ter 8 debian mdadm lvm

我有一个Debian Wheezy与RAID-1(一对夫妇500个GB HDD的系统mdadm镜),在其顶部坐落LVM逻辑卷用5个分区(bootrootusrvartmp),47.15吉布的总大小。物理卷中的 418.38 GiB 是免费的。GRUB安装在两个驱动器上。

其中一个 HDD 出现故障,现在阵列降级,但数据完好无损。

我想要的是将所有这 2 个 HDD 全部更换为 80 GB SSD,而无需从头开始重新安装系统。这里的微妙之处是我需要缩小 LVM 物理卷以匹配 SSD 的大小,但逻辑卷不是连续的(一开始有很多可用空间),所以我必须以某种方式移动物理卷中的逻辑卷. 并且lvmove在 Debian 中没有命令。

我如何实现这一目标?

一些控制台输出:

版本:

root@wheezy:~# uname -a && mdadm --version && lvm version
Linux wheezy 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2+deb7u1 x86_64 GNU/Linux
mdadm - v3.2.5 - 18th May 2012
  LVM version:     2.02.95(2) (2012-03-06)
  Library version: 1.02.74 (2012-03-06)
  Driver version:  4.22.0
Run Code Online (Sandbox Code Playgroud)

数组详细信息:

root@wheezy:~# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Dec  4 12:20:22 2014
     Raid Level : raid1
     Array Size : 488148544 (465.53 GiB 499.86 GB)
  Used Dev Size : 488148544 (465.53 GiB 499.86 GB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Thu Dec  4 13:08:59 2014
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : wheezy:0  (local to host wheezy)
           UUID : 44ea4079:b3b837d3:b9bb2ca1:1b95272a
         Events : 26

Number   Major   Minor   RaidDevice State
   0       8       16        0      active sync   /dev/sdb
   1       0        0        1      removed
Run Code Online (Sandbox Code Playgroud)

LVM 简要细节:

root@wheezy:~# pvs && vgs && lvs                                                                                               
  PV         VG     Fmt  Attr PSize   PFree                                                                                          
  /dev/md0   system lvm2 a--  465.53g 418.38g                                                                                        
  VG     #PV #LV #SN Attr   VSize   VFree                                                                                            
  system   1   5   0 wz--n- 465.53g 418.38g                                                                                          
  LV   VG     Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert                                                            
  boot system -wi----- 152.00m                                                                                                       
  root system -wi-----   2.00g                                                                                                       
  tmp  system -wi-----  10.00g                                                                                                       
  usr  system -wi-----  20.00g                                                                                                       
  var  system -wi-----  15.00g
Run Code Online (Sandbox Code Playgroud)

PV的分割:

root@wheezy:~# pvs -v --segments /dev/md0
    Using physical volume(s) on command line
    PV         VG     Fmt  Attr PSize   PFree   Start  SSize LV   Start Type   PE Ranges             
    /dev/md0   system lvm2 a--  465.53g 418.38g      0 89600          0 free                         
    /dev/md0   system lvm2 a--  465.53g 418.38g  89600    38 boot     0 linear /dev/md0:89600-89637  
    /dev/md0   system lvm2 a--  465.53g 418.38g  89638   512 root     0 linear /dev/md0:89638-90149  
    /dev/md0   system lvm2 a--  465.53g 418.38g  90150  5120 usr      0 linear /dev/md0:90150-95269  
    /dev/md0   system lvm2 a--  465.53g 418.38g  95270  3840 var      0 linear /dev/md0:95270-99109  
    /dev/md0   system lvm2 a--  465.53g 418.38g  99110  1280          0 free                         
    /dev/md0   system lvm2 a--  465.53g 418.38g 100390  2560 tmp      0 linear /dev/md0:100390-102949
    /dev/md0   system lvm2 a--  465.53g 418.38g 102950 16226          0 free  
Run Code Online (Sandbox Code Playgroud)

psu*_*usi 5

您不需要缩小 pv 或重建阵列。您只需要从新驱动器中创建一个新阵列并将其添加为新 pv ( pvcreate+ vgextend),然后将pvmove所有现有 lvs 从旧 pv 中删除,然后删除旧 pv ( vgreduce) 并使该驱动器停止服务。