LVMの操作

更新日 2012-01-28 (土) 23:08:13
    Disk2           Disk3          Disk4
  ----------      -----------    ----------
  |        |      |         |    |        |
  |  XXGB  |      |   YYG   |    |  ZZGB  |   物理Disk
  |        |      |         |    |        |
  ----------      -----------    ----------
      |                |              |
      V                V              V
  ----------      -----------    ----------
  |        |      |         |    |        |
  |  sdb1  |      |  sdc1   |    |  sdd1  |   物理ボリューム(PV)
  |        |      |         |    |        |
  ----------      -----------    ----------
      |                |              |
      V                V              V
  -----------------------------------------
  |                                       |   論理ボリュームグループ(VG)
  |     Volume 00                         |
  -----------------------------------------
              |              |
              V              V
  ----------------        -----------------
  |              |        |               |   論理ボリューム(LV)
  |  Log Vol 01  |        | Log Vol 02    |
  ----------------        -----------------
              |              |
              V              V
            /mnt1           /mnt2             マウントポイント

物理ボリュームの作成

# /sbin/fdisk /dev/sdb1

/dev/sdb1               1         783     6289416   8e  Linux LVM
# /sbin/fdisk -l


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

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         783     6289416   8e  Linux LVM

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1044     8385898+  8e  Linux LVM

Disk /dev/sde: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        1305    10482381   8e  Linux LVM

物理ボリュームの作成

パーティションを物理ボリュームとして初期化

# /usr/sbin/pvcreate  /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
# /usr/sbin/pvcreate  /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
# /usr/sbin/pvcreate  /dev/sde1
  Physical volume "/dev/sde1" successfully created

LVMの領域として利用するすべての物理ボリュームに対して、初期化が完了した物理ボリュームは、/sbin/pvscanで確認

# /sbin/pvscan
  PV /dev/sda2   VG VolGroup00      lvm2 [15.88 GB / 0    free]
  PV /dev/sdb1                      lvm2 [6.00 GB]
  PV /dev/sdc1                      lvm2 [8.00 GB]
  PV /dev/sde1                      lvm2 [10.00 GB]
  Total: 4 [39.87 GB] / in use: 1 [15.88 GB] / in no VG: 3 [23.99 GB]

ボリュームグループの作成

# /usr/sbin/vgcreate VolGroup01 /dev/sdb1 /dev/sdc1 /dev/sde1
  Volume group "VolGroup01" successfully created

ボリュームグループの確認

# /sbin/vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup01" using metadata type lvm2
  Found volume group "VolGroup00" using metadata type lvm2

ボリュームグループの削除

# /usr/sbin/vgremove Volume00
  Volume group "Volume00" successfully removed

PE(Physical Extent)

ボリュームグループはPEという単位の集まり、PEの大きさはデフォルトでは4MB、つのボリュームグループは最大64K個までのPE、デフォルトでは1つのボリュームグループの大きさは最大で256GB(4MB X 64k) vgcreateコマンドの -s オプションでPEのサイズを変更可能。

論理ボリュームの作成

7GBの論理ボリューム(LogVol01)をボリュームグループ(VolGroup01)から作成

# /usr/sbin/lvcreate -L 7G -n LogVol01 VolGroup01
   Logical volume "LogVol01" created

論理ボリュームの確認

# /usr/sbin/lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup01/LogVol01
  VG Name                VolGroup01
  LV UUID                8vxvb9-1O1c-EwyS-W5N9-Fpsv-g8xO-MH0efZ
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                7.00 GB
  Current LE             1792
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

論理ボリュームの削除

# /usr/sbin/lvremove /dev/VolGroup01/LogVol01
Do you really want to remove active logical volume LogVol01? [y/n]: y
  Logical volume "LogVol01" successfully removed

「/dev/ボリュームグループ名/論理ボリューム名」となる

論理ボリュームのフォーマット

# /sbin/mkfs -t ext3 /dev/VolGroup01/LogVol11
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux 
(略)
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

マウント

# mount /dev/VolGroup01/LogVol11 /mnt1
# mount

/dev/mapper/VolGroup01-LogVol11 on /mnt1 type ext3 (rw)

LVの拡大/縮小

LVのサイズ拡大

# /usr/sbin/lvextend -L +1024M /dev/VolGroup01/LogVol11
  Extending logical volume LogVol11 to 8.00 GB
  Logical volume LogVol11 successfully resized

FileSystemの拡大(ext3/ext4)

# /sbin/resize2fs /dev/VolGroup01/LogVol11
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup01/LogVol11 is mounted on /mnt1; on-line resizing required
Performing an on-line resize of /dev/VolGroup01/LogVol11 to 2097152 (4k) blocks.
The filesystem on /dev/VolGroup01/LogVol11 is now 2097152 blocks long.
# df
/dev/mapper/VolGroup01-LogVol11
                       8256952    363528   7474008   5% /mnt1

LVのサイズ縮小

縮小時はumountの必要あり

FileSystemの縮小(ext3/ext4)(6GBに)

# umount /mnt1
# /sbin/fsck.ext3 -f /dev/VolGroup01/LogVol11
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup01/LogVol11: 10076/1048576 files (0.1% non-contiguous), 123796/2097152 blocks
# /sbin/resize2fs /dev/VolGroup01/LogVol11 6G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VolGroup01/LogVol11 to 1572864 (4k) blocks.
The filesystem on /dev/VolGroup01/LogVol11 is now 1572864 blocks long.

LVのサイズ縮小(-2GB)

# /usr/sbin/lvreduce -L -2GB /dev/VolGroup01/LogVol11
  WARNING: Reducing active logical volume to 6.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol11? [y/n]: y
  Reducing logical volume LogVol11 to 6.00 GB
  Logical volume LogVol11 successfully resized
# mount -t ext3 /dev/VolGroup01/LogVol11 /mnt
# df
/dev/mapper/VolGroup01-LogVol11
                      6192704    361740   5579308   7% /mnt

VGにPV追加・切り離し

ボリュームグループ(VolGroup01:24GB)に物理ボリューム(sdf:4GB)を追加

# /usr/sbin/vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID
  Format                lvm2
(略)
  VG Size               23.99 GB  <==元容量
  PE Size               4.00 MB
  Total PE              6141
  Alloc PE / Size       1536 / 6.00 GB
  Free  PE / Size       4605 / 17.99 GB
  VG UUID               BaY2tc-6r9Q-00nn-rE7D-cjsj-f5jH-r4TeIw

追加

# /usr/sbin/vgextend VolGroup01 /dev/sdf
  Volume group "VolGroup01" successfully extended
# /usr/sbin/vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID
  Format                lvm2
(略)
  VG Size               27.98 GB <= sdf 4GBが追加された
  PE Size               4.00 MB
  Total PE              7164
  Alloc PE / Size       1536 / 6.00 GB
  Free  PE / Size       5628 / 21.98 GB
  VG UUID               BaY2tc-6r9Q-00nn-rE7D-cjsj-f5jH-r4TeIw

ボリュームグループから物理ボリュームを切り離し

PV内のPE(Physical Extent:物理エクステント)を同一VG内の別のPVに移動し、切り離し可能な状態にする

PE移動

# /usr/sbin/pvmove /dev/sdc1
  /dev/sdc1: Moved: 0.1%
  /dev/sdc1: Moved: 13.9%
 (略)
  /dev/sdc1: Moved: 93.8%
  /dev/sdc1: Moved: 100.0%

切り離し

# /usr/sbin/vgreduce VolGroup01 /dev/sdc1
  Removed "/dev/sdc1" from volume group "VolGroup01"
# /usr/sbin/pvdisplay /dev/sdc1
  "/dev/xvdc1" is a new physical volume of "8.00 GB"
 --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               8.00 GB <=sdcの容量
(略)
  Allocated PE          0
  PV UUID               N1hPFy-W0jy-uLN1-4DOT-5ZKk-ZczK-w2kf1v

確認

# /usr/sbin/vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID
 (略)
  VG Size               19.99 GB <= 元 28GBからsdc(8GB)が切り離された
  PE Size               4.00 MB
  Total PE              5117
  Alloc PE / Size       1536 / 6.00 GB
  Free  PE / Size       3581 / 13.99 GB
  VG UUID               BaY2tc-6r9Q-00nn-rE7D-cjsj-f5jH-r4TeIw

PE(8MBにして)を変更してボリュームグループの作成

# /usr/sbin/vgcreate -s 8M VolGroup02 /dev/sdc1
 Volume group "VolGroup02" successfully created
# /usr/sbin/vgdisplay  /dev/VolGroup02
 --- Volume group ---
 VG Name               VolGroup02
 System ID
 Format                lvm2
(略)
 VG Size               7.99 GB
 PE Size               8.00 MB <=8Mになっている
 Total PE              1023
 Alloc PE / Size       0 / 0
 Free  PE / Size       1023 / 7.99 GB
 VG UUID               clPzPe-MGoD-3wsG-LzVg-Lv4J-IjkC-cy9eF1

Raid1

Raid1を作成後、ボリュームグループの作成 する例

Raid1デバイス(/dev/md0)を/dev/xvdg1,/dev/xvdh1から作成

# /sbin/mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/xvdg1 /dev/xvdh1
mdadm: /dev/xvdg1 appears to contain an ext2fs file system
    size=987964K  mtime=Thu Jan  1 09:00:00 1970
mdadm: /dev/xvdh1 appears to contain an ext2fs file system
    size=987964K  mtime=Thu Jan  1 09:00:00 1970
Continue creating array? y
mdadm: array /dev/md0 started.
# /sbin/mdadm --detail --scan >> /etc/mdadm.conf

物理ボリュームとして初期化

# /usr/sbin/pvcreate  /dev/md0
  Physical volume "/dev/md0" successfully created

ボリュームグループの作成

# /usr/sbin/vgcreate VolGroup03 /dev/md0
  Volume group "VolGroup03" successfully created

論理ボリュームの作成

# /usr/sbin/lvcreate -L 960M -n LogVol_raid01 VolGroup03
  Logical volume "LogVol_raid01" created

Format後、/mnt-raidにmount

# /sbin/mkfs -t ext3 /dev/VolGroup03/LogVol_raid01
# mkdir /mnt-raid
# mount /dev/VolGroup03/LogVol_raid01 /mnt-raid

参考


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2012-01-28 (土) 23:08:13 (2338d)