October 2019  |  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

CentOS7上のKVMディスクイメージを拡張する(2)

JUGEMテーマ:コンピュータ

 

http://a98.jugem.jp/?eid=458 の続き。

 

「LVMで新たにディスクを追加して既存のLVを拡張する」(Qiita)という記事を見つけたので、

これを見ながら、直接コンソールからパーティションを追加して、LVMを拡張してみることにした。


簡単に、既存の /dev/vda2 パーティションを切り直して大きくして(危険なので良い子はしないように)、lvextend で拡張しようとすると、

# lvextend -L +20Gb /dev/cl/root
  Insufficient free space: 5120 extents needed, but only 0 available

どうも、やり方違っているよう。なので、手順通りに物理ヴォリュームを作成、ヴォリュームグループに追加してから拡張するとうまくいった。しかし、その後が、う〜む、もうひといきな感じ。

 

まず、コンソールでログインして、増やしたディスク領域をパーティションとして追加。

MBRに書き込んだらリブート。

# fdisk /dev/vda
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/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0006450e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): _
Using default response p
Partition number (3,4, default 3): _
First sector (41943040-83886079, default 41943040): _
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079): _
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set

Command (m for help): p

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0006450e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   83  Linux
/dev/vda3        41943040    83886079    20971520   83  Linux

 

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.
[root@edison7arrow ~]# reboot

パーティションに /dev/vda3 が追加された状態を確認

# fdisk -l /dev/vda

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0006450e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   83  Linux
/dev/vda3        41943040    83886079    20971520   83  Linux

 

# df -h /
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   17G   14G  3.9G  78% /
# vgdisplay
  --- Volume group ---
  VG Name               cl
  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               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ZhaBE8-UwNv-l1nB-Svmk-odLu-46Tw-z1Dw7v

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               cl
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               FMAedh-cjo5-0LAD-Lzqh-o0ZA-90w2-FnAcf9

ここから、pvcreate で、物理ヴォリュームを作成し、それを、vgextend で既存のヴォリュームグループに追加する。

(ヴォリュームグループ名は上記に見るとおり、"cl" )

# pvcreate /dev/vda3
  Physical volume "/dev/vda3" successfully created.
# vgextend cl /dev/vda3
  Volume group "cl" successfully extended

ヴォリュームが拡張されたことを確認。

 

# vgdisplay -v cl
  --- Volume group ---
  VG Name               cl
  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               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               ZhaBE8-UwNv-l1nB-Svmk-odLu-46Tw-z1Dw7v
   
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                Due416-VH35-MV1E-eOG2-chT7-Edtm-ISLra5
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-19 14:59:56 +0900
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                Fm5d5P-xKZS-f13e-p1NT-e9dO-36YH-yEj1vs
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-19 14:59:56 +0900
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/vda2     
  PV UUID               FMAedh-cjo5-0LAD-Lzqh-o0ZA-90w2-FnAcf9
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
  PV Name               /dev/vda3     
  PV UUID               lKsPMA-jaLb-DKZK-661P-rsrN-Xqdf-XmRMgM
  PV Status             allocatable
  Total PE / Free PE    5119 / 5119

拡張したヴォリュームのファイルシステムをresize2で拡張、これがうまくゆかず。

# resize2fs /dev/cl/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/cl/root
Couldn't find valid filesystem superblock.

 

# df -h /
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   17G   14G  3.9G  78% /

 

スポンサーサイト

comments

   

trackback

pagetop