ESXi上の仮想マシンでLVMのXFSファイルシステムを拡張する
はじめに
ESXi上の仮想マシンで、ディスク拡張してLVMのXFSファイルシステムを拡張したときのメモです。
環境
- ESXi 6.0.0 Update 2 (Build 3620759)
- VMware Host Client 1.23.0 (Build 6360286)
拡張対象
OS | パーティション | 論理ボリューム | マウントパス | ファイルシステム |
---|---|---|---|---|
CentOS 7.4 | /dev/sda2 | /dev/mapper/cl-root | / | xfs |
現状確認
LVM
LVMのの構成を確認します。
今回は物理ボリュームが1つあり、そこからボリュームグループが1つ作成されており、さらのそのボリュームグループから/とswap用の論理ボリュームが作成されていることがわかります。
# export LANG=C # pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- <99.00g 0 # vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- <99.00g 0 # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- <94.00g swap cl -wi-ao---- 5.00g
ディスク
作業前の情報を取得し忘れてしまいましたが、事前にfdiskコマンドで確認しておきましょう。
# fdiks -l
マウント
今回の拡張したいのは/配下です。論理ボリューム名とファイルシステムが確認できますね。
# df -PT Filesystem Type 1024-blocks Used Available Capacity Mounted on /dev/mapper/cl-root xfs 98539524 98020788 518736 100% / devtmpfs devtmpfs 3994444 0 3994444 0% /dev tmpfs tmpfs 4005420 0 4005420 0% /dev/shm tmpfs tmpfs 4005420 8840 3996580 1% /run tmpfs tmpfs 4005420 0 4005420 0% /sys/fs/cgroup /dev/sda1 xfs 1038336 189676 848660 19% /boot tmpfs tmpfs 801084 0 801084 0% /run/user/55557 tmpfs tmpfs 801084 0 801084 0% /run/user/55556
手順
ESXiで対象ディスクを拡張する
VMware Host Client経由で対象ディスクを拡張します。 この作業は仮想マシンを停止することなくできますが、OS上での認識はOS再起動が必要でした。
なお、仮想マシンのSCSIドライバは「LSI Logic Parallel」でしたので、準仮想ドライバを使えばOS再起動することなく認識できるのかもしれません。
仮想マシンをOS再起動する
ESXiで拡張されたディスクを認識させるために、OS再起動します。
# reboot
ディスク認識状態の確認
もともと100GBのディスクでしたが、ESXiで拡張して200GBにしました。 OSでは214GBと若干大きめのサイズが表示されていますが、拡張されていることは確認できました。
# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x000b15fd デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM Disk /dev/mapper/cl-root: 100.9 GB, 100927537152 bytes, 197124096 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/mapper/cl-swap: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
パーティションの拡張
拡張対象のパーティション情報を一度削除し、新しいサイズでパーティションを定義することでパーティションを拡張します。
下記コマンドでパーティションを再作成した際に、/dev/sda2のStartは変化せずにEndとBlocksのみが変化することを確認してください。ESXiでのディスク拡張によりディスク後方に空きブロックが発生するので、そこを新しいパーティションで含めるようにしています。
# fdisk /dev/sda 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): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p Disk /dev/sda: 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: 0x000b15fd Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 is deleted Command (m for help): p Disk /dev/sda: 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: 0x000b15fd Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (2099200-419430399, default 2099200): Using default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-419430399, default 419430399): Using default value 419430399 Partition 2 of type Linux and of size 199 GiB is set Command (m for help): p Disk /dev/sda: 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: 0x000b15fd Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 419430399 208665600 83 Linux Command (m for help): t Partition number (1,2, default 2): 2 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/sda: 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: 0x000b15fd Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 419430399 208665600 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.
ここで、OSに新しいパーティション情報を認識させるためにOS再起動します。
# reboot
上記のWARNINGに記載の通り、partprobeやkpartxコマンドを使うことでOS再起動不要かもしれません。
物理ボリュームの拡張
物理ボリュームを拡張し、新しいパーティションの全ブロックをLVMで使えるようにします。
# pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- <99.00g 0 # pvresize /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized # pvs PV VG Fmt Attr PSize PFree /dev/sda2 cl lvm2 a-- <199.00g 100.00g
ボリュームグループの確認
物理ボリュームが拡張されたことで、ボリュームグループに空き領域ができたことを確認します。
# vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- <199.00g 100.00g
論理ボリュームの拡張
今回拡張した/配下に該当する論理ボリュームに対して、ボリュームグループの全空き領域を割り当てます。
これにより、ボリュームグループの空きが0になり、対象の論理ボリュームが100GB拡張されたことが確認できます。
# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- <94.00g swap cl -wi-ao---- 5.00g # lvextend -l +100%FREE /dev/mapper/cl-root Size of logical volume cl/root changed from <94.00 GiB (24063 extents) to <194.00 GiB (49663 extents). Logical volume cl/root successfully resized. # vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- <199.00g 0 # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- <194.00g swap cl -wi-ao---- 5.00g
ファイルシステムの拡張
最後にファイルシステムを拡張します。
今回は xfs というファイルシステムだったので、xfs_growfs というコマンドを使います。
このコマンドによる拡張はすぐに終わりました。
df コマンドでファイルサイズを確認すると、/配下の領域が約200GB程度にまで拡張されていることが確認できます。
# xfs_growfs / meta-data=/dev/mapper/cl-root isize=512 agcount=9, agsize=2883328 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=24640512, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5631, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 24640512 to 50854912 # df -PT Filesystem Type 1024-blocks Used Available Capacity Mounted on /dev/mapper/cl-root xfs 203397124 98038144 105358980 49% / devtmpfs devtmpfs 3994444 0 3994444 0% /dev tmpfs tmpfs 4005420 0 4005420 0% /dev/shm tmpfs tmpfs 4005420 8832 3996588 1% /run tmpfs tmpfs 4005420 0 4005420 0% /sys/fs/cgroup /dev/sda1 xfs 1038336 189676 848660 19% /boot tmpfs tmpfs 801084 0 801084 0% /run/user/55557 tmpfs tmpfs 801084 0 801084 0% /run/user/55556
まとめ
ESXi上の仮想マシンでLVMのXFSファイルシステムを拡張する手順をまとめてみました。
ディスクのパーティションやLVMの構成次第では、今回の方法では拡張できない場合もあるので注意が必要です。
その場合は、素直にディスクを追加してボリュームグループを拡張する方法が良いと思います。