KUSANAGI AWSでLVMディスクを拡張

EBSボリュームのストレージ領域の拡張

以下の以前の記事で、EBS拡張について書きました。

EBS ボリュームのストレージ領域を拡張(Amazon Linux)

この時点では、EBS拡張のために一度スナップショットを作成して、容量増加した新規ボリュームを作成してEBSを差し替える必要がありました。
現在は、インスタンスを停止せずに容量を増加させることが可能となっております。以下参考。

EBSボリュームを拡張した後は、resize2fsコマンドでOS上でもディスクサイズを拡張します。

KUSANAGIのCentOS7ではLVMでボリューム管理

KUSANAGIのCentOS7ではディスクボリュームをLVMで管理しています。LVMでは以下の層でディスクを管理しています。

  • PV(物理ボリューム)
  • VG(ボリュームグループ)
  • LV(論理ボリューム)

LVMの考え方は、以下のサイトで分かりやすく図解されています。

今回は30GBから50GBへのEBS拡張を行いました。

LVMのディスク拡張する際には、resize2fs コマンドで一発で作業完了とはいかなかったので、コンソールでEBSボリュームサイズを拡張した後の作業内容を記録しておきます。

growpartを使用してパーティションを拡張

ファアイルシステム上の既存ディスク領域の使用状況を確認します。

# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 20G 7.5G 13G 38% /
devtmpfs devtmpfs 909M 0 909M 0% /dev
tmpfs tmpfs 919M 0 919M 0% /dev/shm
tmpfs tmpfs 919M 8.3M 911M 1% /run
tmpfs tmpfs 919M 0 919M 0% /sys/fs/cgroup
tmpfs tmpfs 184M 0 184M 0% /run/user/1000

ルートパーティションが、20GBのままで拡張されていません。lsblkコマンドでインスタンスにアタッチされたすべてのデバイスおよびパーティションをリストします。

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 50G 0 disk
└─xvda1 202:1 0 29G 0 part ├─centos-root 253:0 0 20G 0 lvm / └─centos-swap 253:1 0 9G 0 lvm [SWAP]

/dev/xvda1 は、50GB のデバイスに含まれる 29GB のパーティションであり、このボリュームのパーティションは他にありません。このボリュームの残りの領域を使用できるようにします。

まず、growpartを使用してパーティションを拡張します。

# rpm -qa | grep growpart
# yum install cloud-utils-growpart
# growpart /dev/xvda 1
CHANGED: partition=1 start=2048 old: size=60815360 end=60817408 new: size=104855519,end=104857567
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 50G 0 disk
└─xvda1 202:1 0 50G 0 part ├─centos-root 253:0 0 20G 0 lvm / └─centos-swap 253:1 0 9G 0 lvm [SWAP]

lsblk の出力を見ると、パーティション /dev/xvda1 によってボリューム /dev/xvda の使用可能スペースが埋められていることを確認できます。しかし、ルート領域は20Gのままです。

FDISKでパーティションを一旦削除して再作成(データは消さない)

既存パーティションの拡張の場合、一旦削除してから再作成しないといけないようです。

削除してしまってデータも削除されないか心配だったので、インスタンスをコピーしてそちらでデータが削除されないのを確認して実施しました。実際に作業される際には、コピーしたインスタンスで試してから作業をされることをお勧めします。

まず、パーティションの状況をFDISKで確認します。

# fdisk -l /dev/xvda
Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00044bc0 Device Boot Start End Blocks Id System
/dev/xvda1 2048 104857566 52427759+ 8e Linux LVM

fdiskの「d」コマンドでパーティションを削除します。

# fdisk /dev/xvda
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/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00044bc0 Device Boot Start End Blocks Id System
/dev/xvda1 2048 104857566 52427759+ 8e Linux LVM
Command (m for help): d
Selected partition 1
Partition 1 is deleted

「n」コマンドでパーティションを再作成します。

Command (m for help): n
Partition type: p primary (0 primary, 0 extended, 4 free) e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set

「t」コマンドでパーティションタイプを「Linux LVM」に設定します。

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00044bc0 Device Boot Start End Blocks Id System
/dev/xvda1 2048 104857599 52427776 8e Linux LVM

「w」コマンドで設定内容を保存します。

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.

一旦ここで再起動してディスクを認識させます。

# reboot

PV(物理ボリューム)の拡張

PV(物理ボリューム)の現状を確認します。

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 50G 0 disk
└─xvda1 202:1 0 50G 0 part ├─centos-root 253:0 0 20G 0 lvm / └─centos-swap 253:1 0 9G 0 lvm [SWAP]
# fdisk -l /dev/xvda
Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00044bc0 Device Boot Start End Blocks Id System
/dev/xvda1 2048 104857599 52427776 8e Linux LVM
# ls /dev/xvda*
/dev/xvda /dev/xvda1
# pvdisplay --- Physical volume --- PV Name /dev/xvda1 VG Name centos PV Size <29.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 7423 Free PE 0 Allocated PE 7423 PV UUID OvPggN-z0kg-Sgao-h917-QXgB-nTSN-Iivr2R
# pvscan PV /dev/xvda1 VG centos lvm2 [&lt;29.00 GiB / 0 free] Total: 1 [&lt;29.00 GiB] / in use: 1 [&lt;29.00 GiB] / in no VG: 0 [0 ]

まだ変わっていません。ここで、VG(ボリュームグループ)「centos」にPV(物理ボリューム)「/dev/xvda1」が入っていることが判ります。
PV(物理ボリューム)をリサイズします。

# pvresize /dev/xvda1 Physical volume &quot;/dev/xvda1&quot; changed 1 physical volume(s) resized / 0 physical volume(s) not resized
# pvdisplay --- Physical volume --- PV Name /dev/xvda1 VG Name centos PV Size <50.00 GiB / not usable 2.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 12799 Free PE 5376 Allocated PE 7423 PV UUID OvPggN-z0kg-Sgao-h917-QXgB-nTSN-Iivr2R

PV(物理ボリューム)が50GBに拡張されました。

VG(ボリュームグループ)の名前・容量確認

VG(ボリュームグループ)の名前・容量を確認します。

# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 5 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 &lt;50.00 GiB PE Size 4.00 MiB Total PE 12799 Alloc PE / Size 7423 / &lt;29.00 GiB Free PE / Size 5376 / 21.00 GiB VG UUID rMuMHs-vxaY-s4eU-IXVZ-hb0X-AOjy-S853uX

LV(論理ボリューム)の名前・容量確認

LV(論理ボリューム)の名前と容量を確認します。

# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID oTvKS9-OZfk-miHO-uXxk-B2cb-U0GF-f4ivKh LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-06-29 17:55:47 +0900 LV Status available # open 1 LV Size 20.00 GiB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID ByOanX-4xrq-heQe-2UDA-hY9T-dEHd-1vIVxk LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-06-29 17:55:48 +0900 LV Status available # open 2 LV Size &lt;9.00 GiB Current LE 2303 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1

ルート領域とスワップ領域が確認できます。
以下で、LV(論理ボリューム)のルート領域を最大限拡張します。

# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 20.00 GiB (5120 extents) to 41.00 GiB (10496 extents). Logical volume centos/root successfully resized.

以下のように、ルート領域が41.00 GiB に拡張できました。

# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID oTvKS9-OZfk-miHO-uXxk-B2cb-U0GF-f4ivKh LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-06-29 17:55:47 +0900 LV Status available # open 1 LV Size 41.00 GiB Current LE 10496 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID ByOanX-4xrq-heQe-2UDA-hY9T-dEHd-1vIVxk LV Write Access read/write LV Creation host, time localhost.localdomain, 2016-06-29 17:55:48 +0900 LV Status available # open 2 LV Size &lt;9.00 GiB Current LE 2303 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1

XFS用の xfs_growfs でボリュームサイズ拡張

KUSANAGIのCentOS7ではデフォルトで、ファイルシステムはXFSとなり、ボリュームサイズ拡張コマンドは「resize2fs」でなく「xfs_growfs」となります。
このコマンドでボリュームサイズ拡張を行います。

# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1310720 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=5242880, imaxpct=25 = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 5242880 to 10747904

以下で拡張されているか確認します。

# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 41G 6.0G 36G 15% /
devtmpfs devtmpfs 485M 0 485M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 6.5M 489M 2% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs tmpfs 100M 0 100M 0% /run/user/1000

OS上でボリュームサイズ拡張が認識できるようになりました。

参考サイト

以下のサイトを参考にさせて頂きました。

補足

コメントを残す

コメントは当サイト運営者の承認後に反映されます。
お名前はニックネームでも結構です。

Comments are allowed only in Japanese. / 日本語が含まれない投稿は無視されますのでご注意ください。