追加データディスクの併合

ALTUSのrootディスクは20GBと小さいので、追加したデータディスクをLVMで併合します。
なお、事前にディスクのアタッチを行っておく必要があります。

ここからは、「ssh」でログインし、「root」ユーザで実行します。

1. ディスク構成の確認

まず、サーバーのディスク構成を確認します。
# fdisk -l

Disk /dev/xvdb: 214.7 GB, 214748364800 bytes, 419430400 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/centos-root: 18.8 GB, 18756927488 bytes, 36634624 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/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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/xvdb」が追加したディスクです。
このデバイスファイル名を確認しておきます。

2. パーティションの作成

(1) パーティションの作成
パーティションを作成します。
$ fdisk /dev/xvdb
まずは、「p」コマンドで現状を確認します。
Command (m for help): p
 Disk /dev/xvdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x7871ac09
 
   Device Boot      Start         End      Blocks   Id  System

新しいパーティションを「n」コマンドで作成します。
コマンド (m でヘルプ): n
続けてパーティションの種類を指定します。ここでは、「p」および「1」とします。
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
ここでパーティションのサイズを指定します。
ここでは、領域をフル指定したいので、そのままデフォルトの値でOKです。
最初 sector (2048-83886079, 初期値 2048):
Last sector, +sectors or +size{K,M,G} (2048-83886079, 初期値 83886079):
Partition 1 of type Linux and of size 200 GiB is set

(2) ファイルシステムを LVMへ変更
作成済みのパーティションを確認します。
Command (m for help): p
    Device Boot      Start         End      Blocks   Id  System
 /dev/xvdb1            2048   419430399   209714176   83  Linux

作成したパーティションをLVMに変更します。
Command (m for help): t
 
Partition number (1-1): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

パーティションを再確認しておきます。
Command (m for help): p
 
    Device Boot      Start         End      Blocks   Id  System
 /dev/sdb1            2048    83886079    41942016   83  Linux LVM

変更したパーティション情報を書き込み、終了します。
Command (m for help): w

(3) サーバの再起動
変更を反映させるためにサーバを再起動します。
# reboot

4. PV(Physical Volume)の作成

作成したパーティションの物理ボリューム「PV」を作成します。

まずは、現状のPVについて確認します。
# pvdisplay
 --- Physical volume ---
 PV Name               /dev/xvda2
 VG Name               centos
 PV Size               19.51 GiB / not usable 3.00 MiB
 Allocatable           yes
 PE Size               4.00 MiB
 Total PE              4994
 Free PE               10
 Allocated PE          4984
 PV UUID               0yTzZw-rtCB-XEqN-rXsR-H9x1-BsJF-rySufQ
先に作成したパーティションにPVを割り当てます。
# pvcreate /dev/xvdb1
 Physical volume "/dev/xvdb1" successfully created
PVが追加されたか確認します。
# pvdisplay
 --- Physical volume ---
 PV Name               /dev/xvda2
 VG Name               centos
 PV Size               19.51 GiB / not usable 3.00 MiB
 Allocatable           yes
 PE Size               4.00 MiB
 Total PE              4994
 Free PE               10
 Allocated PE          4984
 PV UUID               0yTzZw-rtCB-XEqN-rXsR-H9x1-BsJF-rySufQ
 
 "/dev/xvdb1" is a new physical volume of "200.00 GiB"
 --- NEW Physical volume ---
 PV Name               /dev/xvdb1
 VG Name
 PV Size               200.00 GiB
 Allocatable           NO
 PE Size               0
 Total PE              0
 Free PE               0
 Allocated PE          0
 PV UUID               HbKsy4-rfdR-VKEG-TzwM-PwV1-nKmW-H91g4f

5. LV(Logical Volume)の拡張

先に作成したPVをルートディレクトリの論理ボリューム「VG」へ追加し、拡張します。

現状のVGについて確認します。
# vgdisplay
 --- Volume group ---
 VG Name               centos
 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.51 GiB
 PE Size               4.00 MiB
 Total PE              4994
 Alloc PE / Size       4984 / 19.47 GiB
 Free  PE / Size       10 / 40.00 MiB
 VG UUID               zCvSR6-d0FW-JNT0-EzjV-dz6Z-RFD0-agun4C
rootディスクのVG「centos」に、先に作成したパーティションを追加、拡張します。
vgextend centos00 /dev/xvdb1
 Volume group "centos00" successfully extended
VGのサイズが拡張されたことを確認します。
# vgdisplay
 --- Volume group ---
 VG Name               centos
 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               219.50 GiB
 PE Size               4.00 MiB
 Total PE              56193
 Alloc PE / Size       4984 / 19.47 GiB
 Free  PE / Size       51209 / 200.04 GiB
 VG UUID               zCvSR6-d0FW-JNT0-EzjV-dz6Z-RFD0-agun4C

6. LVの拡張

論理的なボリューム「LV」を変更します。

現在のLVを確認します。
# lvscan
 ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
 ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
LVの容量を変更します。ここでは、余った容量を含めて利用可能な領域の最大を指定(+100%FREE)します。
# lvextend -l +100%FREE /dev/centos/root
変更後のLVを確認します。
# lvscan
 ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
 ACTIVE            '/dev/centos/root' [217.50 GiB] inherit

7. ファイルシステムの拡張

ファイルシステムを拡張します。
# xfs_growfs /dev/centos/root

変更を反映させるためにサーバを再起動します。
# reboot

8. 最終確認

ディスクの容量が増えたことを確認します。
# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       218G  1.4G  217G   1% /
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.8G     0  3.8G   0% /dev/shm
tmpfs                   tmpfs     3.8G  8.4M  3.8G   1% /run
tmpfs                   tmpfs     3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/xvda1              xfs       497M  184M  314M  37% /boot
tmpfs                   tmpfs     773M     0  773M   0% /run/user/0}}




最終更新:2016年12月20日 15:58