読者です 読者をやめる 読者になる 読者になる

としたにあんの左脳

備忘録です.

LVMに入れたディスクを抜く

60GBのSSDを3枚ぶっこんで180GBのLVMを作った。 最近、その中の1枚が調子悪くて、LVM全体がRead-Only FileSystemになるようになった。 /dev/sdbが調子わるいみたいなので、抜くことにしたが、一苦労だったのでメモ。

[root@openstack-03 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               55.21 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              14134
  Free PE               0
  Allocated PE          14134
  PV UUID               QV224J-DJhF-uCJT-hNLZ-2r3w-poke-ocOOjp

  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               centos
  PV Size               55.90 GiB / not usable 4.90 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              14309
  Free PE               0
  Allocated PE          14309
  PV UUID               ggEsVq-g8Ho-3hSY-h8Sv-GxGK-bG5c-14h14A

  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               centos
  PV Size               55.90 GiB / not usable 4.90 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              14309
  Free PE               0
  Allocated PE          14309
  PV UUID               1W3kxH-lapr-4Of1-tFTn-iRTN-08KF-RCNAXK

  "/dev/loop0" is a new physical volume of "20.60 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/loop0
  VG Name
  PV Size               20.60 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               PPATKZ-qISr-klKl-7uQT-qtal-fiG0-BCZMrJ

[root@openstack-03 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               167.00 GiB
  PE Size               4.00 MiB
  Total PE              42752
  Alloc PE / Size       42752 / 167.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               9hDy0r-CzyH-cf7T-79X4-58e8-DHTY-rSnWRw

[root@openstack-03 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                Olznpo-lnKi-eBbF-Yy6o-suEQ-vxzF-4dM4gy
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-05-05 22:04:44 +0900
  LV Status              available
  # open                 2
  LV Size                5.59 GiB
  Current LE             1431
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                5E0sB7-SC4Y-zgpg-gxs4-7eLn-yfND-z9mUnF
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-05-05 22:04:44 +0900
  LV Status              available
  # open                 1
  LV Size                161.41 GiB
  Current LE             41321
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

5.4. Removing a Disk from a Logical Volumeとかをみると、pvmove して、他の物理ボリュームに移したらOK的な事がかいてあるので、さっそく

[root@openstack-03 ~]# pvmove /dev/sdb1
  No extents available for allocation

他に空き容量が無いからダメっぽい。 最初にロジカルボリュームに全ての容量を割り当てたのが、ダメだったっぽい。

http://tldp.org/HOWTO/LVM-HOWTO/reducelv.htmlをみると、ロジカルボリュームを縮小してからやるとOKらしい。

[root@openstack-03 ~]# lvreduce -L-70G /dev/centos/root
  WARNING: Reducing active and open logical volume to 91.41 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]: y
  Size of logical volume centos/root changed from 161.41 GiB (41321 extents) to 91.41 GiB (23401 extents).
  Logical volume root successfully resized

でも、”データ壊れるかもよ”って言ってる。

あとはこれに従って進める。

とりあえず、pvmoveで動かせるだけのextentsは確保できたっぽい

  PV         VG     Fmt  Attr PSize  PFree  Used
  /dev/loop0        lvm2 ---  20.60g 20.60g     0
  /dev/sda3  centos lvm2 a--  55.21g     0  55.21g
  /dev/sdb1  centos lvm2 a--  55.89g 14.11g 41.79g
  /dev/sdc1  centos lvm2 a--  55.89g 14.11g 41.79g

動かしてみる。動いた。

[root@openstack-03 ~]# pvmove /dev/sdb1
  Detected pvmove in progress for /dev/sdb1
  /dev/sdb1: Moved: 41.4%
  /dev/sdb1: Moved: 45.4%
  /dev/sdb1: Moved: 49.0%
  /dev/sdb1: Moved: 52.6%
  /dev/sdb1: Moved: 56.5%
  /dev/sdb1: Moved: 60.6%
  /dev/sdb1: Moved: 64.8%
  /dev/sdb1: Moved: 68.9%
  /dev/sdb1: Moved: 73.1%
  /dev/sdb1: Moved: 77.2%
  /dev/sdb1: Moved: 81.3%
  /dev/sdb1: Moved: 85.5%
  /dev/sdb1: Moved: 89.6%
  /dev/sdb1: Moved: 93.8%
  /dev/sdb1: Moved: 97.9%
  /dev/sdb1: Moved: 100.0%

/dev/sdb1が空いたっぽい。

[root@openstack-03 ~]# pvs -o+pv_used
  PV         VG     Fmt  Attr PSize  PFree  Used
  /dev/loop0        lvm2 ---  20.60g 20.60g     0
  /dev/sda3  centos lvm2 a--  55.21g     0  55.21g
  /dev/sdb1  centos lvm2 a--  55.89g 55.89g     0
  /dev/sdc1  centos lvm2 a--  55.89g 14.11g 41.79g
[root@openstack-03 ~]# vgreduce centos /dev/sdb1
  Removed "/dev/sdb1" from volume group "centos"

これで、/dev/sdb1がボリュームグループから剥がれたっぽい!

(追記) マシンを再起動したら、OSが動かなくなったので、失敗したっぽい