CentOS7.3 KVMゲストOSのディスク容量拡張

シェアする

KVMゲストOSのディスク容量を拡張します。

容量を拡張するのは、2つ目の仮想ディスク「/dev/vdb」を、下記のように40GB追加して、全体として100GBにします。

kvm_volup

ゲストOSの拡張前状態確認

対象となるゲストOSの拡張を行なう前にディスクの状態を確認し、ディスクの対象を間違わないようにします。

# fdisk -l
  
Disk /dev/vda: 4294 MB, 4294971392 bytes, 8388616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ab0ff
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624     8388607     3668992   8e  Linux LVM
 
Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e856f3a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
 
Disk /dev/mapper/vg01-lv_root: 2680 MB, 2680160256 bytes, 5234688 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 
Disk /dev/mapper/vg01-lv_swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 
Disk /dev/mapper/vg02-lv_repo: 64.4 GB, 64420315136 bytes, 125820928 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

ゲストOSのディスク拡張

KVMホストで、対象となるゲストOSを停止し、対象の仮想ディスクを拡張します。

# virsh shutdown SERVER_NAME
Domain SERVER_NAME is being shutdown
 
# ls -l SERVER_NAME_disk*.img
-rw-------. 1 root root  4294971392 Jul 11 14:29 SERVER_NAME_disk01.img
-rw-------. 1 root root 64424509440 Jul 11 14:29 SERVER_NAME_disk02.img
# qemu-img resize SERVER_NAME_disk02.img +40G
Image resized.
# ls -l SERVER_NAME_disk*.img
-rw-------. 1 root root   4294971392 Jul 11 14:29 SERVER_NAME_disk01.img
-rw-------. 1 root root 107374182400 Jul 11 14:33 SERVER_NAME_disk02.img

パーティション設定

ゲストOSの拡張された仮想ディスクに、パーティションを設定します。

# virsh start SERVER_NAME --console
    :(省略)
CentOS Linux 7 (Core)
Kernel 3.10.0-514.26.1.el7.x86_64 on an x86_64
 
SERVER_NAME login: root
パスワード: xxxx
 
# fdisk -l
 
Disk /dev/vda: 4294 MB, 4294971392 bytes, 8388616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ab0ff
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624     8388607     3668992   8e  Linux LVM
 
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e856f3a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
 
Disk /dev/mapper/vg01-lv_root: 2680 MB, 2680160256 bytes, 5234688 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 
Disk /dev/mapper/vg01-lv_swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 
Disk /dev/mapper/vg02-lv_repo: 64.4 GB, 64420315136 bytes, 125820928 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
 
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): p
 
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e856f3a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
 
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): <空エンター(デフォルト値)>
Partition number (2-4, default 2): <空エンター(デフォルト値)>
First sector (125829120-209715199, default 125829120): <空エンター(デフォルト値)>
Last sector, +sectors or +size{K,M,G} (125829120-209715199, default 209715199): <空エンター(デフォルト値)>
Partition 2 of type Linux and of size 40 GiB is set
 
Command (m for help): p
 
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e856f3a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
/dev/vdb2       125829120   209715199    41943040   83  Linux
 
Command (m for help): t
Partition number (1,2, default 2): <空エンター(デフォルト値)>
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
 
Command (m for help): p
 
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2e856f3a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
/dev/vdb2       125829120   209715199    41943040   8e  Linux LVM
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
# shutdown -r now

ボリュームの作成

物理ボリュームを作成し、既存のボリュームグループに参加させて、論理ボリュームを作成します。
その後、ファイルシステム(xfs)の拡張を行ないます。

SERVER_NAME login: root
パスワード: xxxx
 
# pvcreate /dev/vdb2
  Physical volume "/dev/vdb2" successfully created.
# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               vg01
  PV Size               3.50 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              895
  Free PE               0
  Allocated PE          895
  PV UUID               QbxlYm-AtI7-Rb8r-7ray-xLjs-cwgB-7QcO6h
 
 
  --- Physical volume ---
  PV Name               /dev/vdb1
  VG Name               vg02
  PV Size               60.00 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              15359
  Free PE               0
  Allocated PE          15359
  PV UUID               q2fNCe-4m9m-DVHy-aOo2-MW33-kpHS-Kx7Vi3
 
 
  "/dev/vdb2" is a new physical volume of "40.00 GiB"  <= 物理ボリュームが作成された
  --- NEW Physical volume ---
  PV Name               /dev/vdb2
  VG Name
  PV Size               40.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cViNYf-C9bs-K6dj-9cvT-wWCd-Bz1O-j0fq0e
 
 
# vgdisplay
  --- Volume group ---
  VG Name               vg01
  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               3.50 GiB
  PE Size               4.00 MiB
  Total PE              895
  Alloc PE / Size       895 / 3.50 GiB
  Free  PE / Size       0 / 0
  VG UUID               lEkHYR-R7g3-v5ov-ofFJ-tF33-TNkG-v8Zzzy
 
 
  --- Volume group ---
  VG Name               vg02   <= 対象のボリュームグループ
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               60.00 GiB
  PE Size               4.00 MiB
  Total PE              15359
  Alloc PE / Size       15359 / 60.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               BAC8V2-Po0f-oDSz-ShLk-Dn6x-z2Ar-wKQyEn
 
 
# vgextend vg02 /dev/vdb2
  Volume group "vg02" successfully extended
# vgdisplay
  --- Volume group ---
  VG Name               vg01
  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               3.50 GiB
  PE Size               4.00 MiB
  Total PE              895
  Alloc PE / Size       895 / 3.50 GiB
  Free  PE / Size       0 / 0
  VG UUID               lEkHYR-R7g3-v5ov-ofFJ-tF33-TNkG-v8Zzzy
 
 
  --- Volume group ---
  VG Name               vg02
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               99.99 GiB
  PE Size               4.00 MiB
  Total PE              25598
  Alloc PE / Size       15359 / 60.00 GiB
  Free  PE / Size       10239 / 40.00 GiB    <= 拡張された
  VG UUID               BAC8V2-Po0f-oDSz-ShLk-Dn6x-z2Ar-wKQyEn
 
 
# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv_swap
  LV Name                lv_swap
  VG Name                vg01
  LV UUID                aidNzP-JHpx-mWSw-ex3l-agoW-ECDa-m4ttPj
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-30 07:56:52 +0900
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
 
 
  --- Logical volume ---
  LV Path                /dev/vg01/lv_root
  LV Name                lv_root
  VG Name                vg01
  LV UUID                zPfoY8-h3jS-gQoq-fdMb-Py9a-3ceY-hrmdeQ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-30 07:56:53 +0900
  LV Status              available
  # open                 1
  LV Size                2.50 GiB
  Current LE             639
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
 
 
  --- Logical volume ---
  LV Path                /dev/vg02/lv_repo   <= 対象の論理ボリューム
  LV Name                lv_repo
  VG Name                vg02
  LV UUID                mWfWoR-wMKm-mqjN-xe82-ncq2-z6PI-7gvlzo
  LV Write Access        read/write
  LV Creation host, time SERVER_NAME, 2017-07-02 12:00:15 +0900
  LV Status              available
  # open                 1
  LV Size                60.00 GiB
  Current LE             15359
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
 
 
# lvextend -l +100%FREE /dev/vg02/lv_repo  <= 論理ボリューム拡張
  Size of logical volume vg02/lv_repo changed from 60.00 GiB (15359 extents) to 99.99 GiB (25598 extents).
  Logical volume vg02/lv_repo successfully resized.
# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/lv_swap
  LV Name                lv_swap
  VG Name                vg01
  LV UUID                aidNzP-JHpx-mWSw-ex3l-agoW-ECDa-m4ttPj
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-30 07:56:52 +0900
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
 
 
  --- Logical volume ---
  LV Path                /dev/vg01/lv_root
  LV Name                lv_root
  VG Name                vg01
  LV UUID                zPfoY8-h3jS-gQoq-fdMb-Py9a-3ceY-hrmdeQ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-30 07:56:53 +0900
  LV Status              available
  # open                 1
  LV Size                2.50 GiB
  Current LE             639
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
 
 
  --- Logical volume ---
  LV Path                /dev/vg02/lv_repo
  LV Name                lv_repo
  VG Name                vg02
  LV UUID                mWfWoR-wMKm-mqjN-xe82-ncq2-z6PI-7gvlzo
  LV Write Access        read/write
  LV Creation host, time SERVER_NAME, 2017-07-02 12:00:15 +0900
  LV Status              available
  # open                 1
  LV Size                99.99 GiB   <= 拡張された
  Current LE             25598
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
 
# xfs_growfs /dev/vg02/lv_repo   <= ファイルシステム(xfs)の拡張
meta-data=/dev/mapper/vg02-lv_repo isize=512    agcount=13, agsize=1310464 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=15727616, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 15727616 to 26212352