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

LVM簡易メモ

Linux LVM

今まであまり手を出してこなかったので、LVMを少し触ってみる事にしました。
自分自身の備忘録としてまとめておきます。

LVM

なんだかんだでWikipediaの記述をメモ
wikipedia:論理ボリュームマネージャ

触りだす


まずはディスクの状況。

# df -k
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       5713496   1069312   4349272  20% /
/dev/sda1               101086     12181     83686  13% /boot
tmpfs                   127708         0    127708   0% /dev/shm
# fdisk /dev/sda

コマンド (m でヘルプ): p

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         783     6185025   8e  Linux LVM

コマンド (m でヘルプ): q

# fdisk /dev/sdb

コマンド (m でヘルプ): p

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot      Start         End      Blocks   Id  System

コマンド (m でヘルプ): q


今の状態を「pvdisplay」「vgdisplay」「lvdisplay」コマンドで確認

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               5.90 GB / not usable 24.06 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              188
  Free PE               0
  Allocated PE          188
  PV UUID               5imoca-Vjqo-o0T7-nps3-FSFg-bq5W-fRDAMO
   
# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               5.88 GB
  PE Size               32.00 MB
  Total PE              188
  Alloc PE / Size       188 / 5.88 GB
  Free  PE / Size       0 / 0   
  VG UUID               YosyTo-mMb5-EuRk-QmrS-zaxA-vPKw-0pyUdQ
   
# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                2kFcxN-1XnZ-CAe3-hCSM-ocbA-3H2i-s8zISL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.62 GB
  Current LE             180
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                qZpPrE-SBGQ-NU4W-rVQ0-H2KI-Iy1A-crh112
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                256.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

PVを作成しておく


準備という事で、「/dev/sdb」を利用。

# fdisk -l /dev/sdb

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         400     3212968+  83  Linux
/dev/sdb2             401         783     3076447+  83  Linux

# pvcreate -v /dev/sdb1 /dev/sdb2
    Wiping cache of LVM-capable devices
    Set up physical volume for "/dev/sdb1" with 6425937 available sectors
    Zeroing start of device /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
    Set up physical volume for "/dev/sdb2" with 6152895 available sectors
    Zeroing start of device /dev/sdb2
  Physical volume "/dev/sdb2" successfully created

VGにパーティションを追加する


すでに存在するVG「VolGroup00」に「/dev/sdb1」を追加してみます。
「vgextend」コマンドで対象を指定すればOKです。

# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               5.88 GB
  PE Size               32.00 MB
  Total PE              188
  Alloc PE / Size       188 / 5.88 GB
  Free  PE / Size       0 / 0   
  VG UUID               YosyTo-mMb5-EuRk-QmrS-zaxA-vPKw-0pyUdQ
   
# vgextend VolGroup00 /dev/sdb1
  Volume group "VolGroup00" successfully extended

# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               8.94 GB
  PE Size               32.00 MB
  Total PE              286
  Alloc PE / Size       188 / 5.88 GB
  Free  PE / Size       98 / 3.06 GB
  VG UUID               YosyTo-mMb5-EuRk-QmrS-zaxA-vPKw-0pyUdQ

LVを拡張する


ということで拡張します。「lvextend」コマンドで容量を指定して、
「resize2fs」コマンドで領域を拡張します。

# df -k
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       5713496   1069404   4349180  20% /
/dev/sda1               101086     12181     83686  13% /boot
tmpfs                   127708         0    127708   0% /dev/shm
   
# lvextend -l+50 /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 7.19 GB
  Logical volume LogVol00 successfully resized

# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 1884160 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 1884160 blocks long.

# df -k
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       7298536   1070844   5850880  16% /
/dev/sda1               101086     12181     83686  13% /boot
tmpfs                   127708         0    127708   0% /dev/shm


無事拡張できました。

PV移動とVGの取り外し


一旦先ほど作っておいた「/dev/sdb2」をVGに追加します。
今度は「/dev/sdb1」を取り外します。

# pvmove -v /dev/sdb1    Finding volume group "VolGroup00"
    Archiving volume group "VolGroup00" metadata (seqno 12).
    Creating logical volume pvmove0
    Moving 50 extents of logical volume VolGroup00/LogVol00
    Found volume group "VolGroup00"
    activation/volume_list configuration setting not defined, checking only host tags for VolGroup00/LogVol00
    Updating volume group metadata
    Found volume group "VolGroup00"
    Found volume group "VolGroup00"
    Suspending VolGroup00-LogVol00 (253:0) with device flush
    Found volume group "VolGroup00"
    activation/volume_list configuration setting not defined, checking only host tags for VolGroup00/pvmove0
    Creating VolGroup00-pvmove0
    Loading VolGroup00-pvmove0 table (253:2)
    Resuming VolGroup00-pvmove0 (253:2)
    Found volume group "VolGroup00"
    Loading VolGroup00-pvmove0 table (253:2)
    Suppressed VolGroup00-pvmove0 identical table reload.
    Loading VolGroup00-LogVol00 table (253:0)
    Resuming VolGroup00-LogVol00 (253:0)
    Creating volume group backup "/etc/lvm/backup/VolGroup00" (seqno 13).
    Checking progress before waiting every 15 seconds
  /dev/sdb1: Moved: 0.0%
  /dev/sdb1: Moved: 12.0%
  /dev/sdb1: Moved: 24.0%
  /dev/sdb1: Moved: 30.0%
  /dev/sdb1: Moved: 38.0%
  /dev/sdb1: Moved: 52.0%
  /dev/sdb1: Moved: 74.0%
  /dev/sdb1: Moved: 100.0%
    Found volume group "VolGroup00"
    Found volume group "VolGroup00"
    Loading VolGroup00-LogVol00 table (253:0)
    Suspending VolGroup00-LogVol00 (253:0) with device flush
    Suspending VolGroup00-pvmove0 (253:2) with device flush
    Found volume group "VolGroup00"
    Found volume group "VolGroup00"
    Found volume group "VolGroup00"
    Resuming VolGroup00-pvmove0 (253:2)
    Found volume group "VolGroup00"
    Resuming VolGroup00-LogVol00 (253:0)
    Found volume group "VolGroup00"
    Removing VolGroup00-pvmove0 (253:2)
    Found volume group "VolGroup00"
    Removing temporary pvmove LV
    Writing out final volume group after pvmove
    Creating volume group backup "/etc/lvm/backup/VolGroup00" (seqno 15).
   
# vgdisplay -v
    Finding all volume groups
    Finding volume group "VolGroup00"
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  15
  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               11.84 GB
  PE Size               32.00 MB
  Total PE              379
  Alloc PE / Size       238 / 7.44 GB
  Free  PE / Size       141 / 4.41 GB
  VG UUID               YosyTo-mMb5-EuRk-QmrS-zaxA-vPKw-0pyUdQ
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                2kFcxN-1XnZ-CAe3-hCSM-ocbA-3H2i-s8zISL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.19 GB
  Current LE             230
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                qZpPrE-SBGQ-NU4W-rVQ0-H2KI-Iy1A-crh112
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                256.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               5imoca-Vjqo-o0T7-nps3-FSFg-bq5W-fRDAMO
  PV Status             allocatable
  Total PE / Free PE    188 / 0
   
  PV Name               /dev/sdb1     
  PV UUID               bj7HVH-0JIb-zp9t-7IKH-H22C-RXDl-9nV6HS
  PV Status             allocatable
  Total PE / Free PE    98 / 98
   
  PV Name               /dev/sdb2     
  PV UUID               ARSOIX-7g90-OJpK-wyy8-rKEP-y0yH-oZWpn7
  PV Status             allocatable
  Total PE / Free PE    93 / 43

# vgreduce -v VolGroup00 /dev/sdb1    Finding volume group "VolGroup00"
    Using physical volume(s) on command line
    Archiving volume group "VolGroup00" metadata (seqno 15).
    Removing "/dev/sdb1" from volume group "VolGroup00"
    Creating volume group backup "/etc/lvm/backup/VolGroup00" (seqno 16).
  Removed "/dev/sdb1" from volume group "VolGroup00"


練習という事で、いくつかやってみました。
まだ分かっていない事が多いから、実践を意識したケースを想定してまた色々やってみたいと思います。


今日はこんな所で。