CentOS8におけるLVMディスクの拡張方法を記載します。
基本手順はCentOS7と同一なのですが、xfs_growfsをする際、
CentOS7の場合
xfs_growfs /dev/cl/root
CentOS8 の場合
xfs_growfs /
の違いにより、とてもハマったのでその辺のポイントを記載したいと思います。
ちなみに、CentOS8で以下のコマンドを実行すると、
以下のようにエラーが出力されて拡張領域が反映されません。
[root@c80g167 ~]# xfs_growfs /dev/cl/root xfs_growfs: /dev/cl/root is not a mounted XFS filesystem
以下、fdiskやLVMなど細かい説明は書きませんが、赤文字箇所だけ見てもらえればポイントは掴めると思います。
1.デバイスの拡張
今回はVMWareで以下のように拡張しますが、KVMではqemu-img resizeコマンドにより拡張してください。
ここでは例として、200GB→250GBに拡張する場合とします。
2.現状確認とfdisk
[root@c80g167 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 888M 0 888M 0% /dev tmpfs tmpfs 904M 0 904M 0% /dev/shm tmpfs tmpfs 904M 9.4M 894M 2% /run tmpfs tmpfs 904M 0 904M 0% /sys/fs/cgroup /dev/mapper/cl-root xfs 197G 6.6G 191G 4% / /dev/sda1 ext4 976M 134M 776M 15% /boot tmpfs tmpfs 181M 20K 181M 1% /run/user/0 [root@c80g167 ~]# fdisk -l Disk /dev/sda: 250 GiB, 268435456000 bytes, 524288000 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 Disklabel type: dos Disk identifier: 0x47600f97 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 419430399 417331200 199G 8e Linux LVM Disk /dev/mapper/cl-root: 197 GiB, 211472613376 bytes, 413032448 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/cl-swap: 2 GiB, 2197815296 bytes, 4292608 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 [root@c80g167 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.32.1). 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/sda: 250 GiB, 268435456000 bytes, 524288000 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 Disklabel type: dos Disk identifier: 0x47600f97 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 419430399 417331200 199G 8e Linux LVM Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): 空Enter First sector (419430400-524287999, default 419430400): 空Enter Last sector, +sectors or +size{K,M,G,T,P} (419430400-524287999, default 524287999): 空Enter Created a new partition 3 of type 'Linux' and of size 50 GiB. Command (m for help): t Partition number (1-3, default 3): 3 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: 250 GiB, 268435456000 bytes, 524288000 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 Disklabel type: dos Disk identifier: 0x47600f97 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 419430399 417331200 199G 8e Linux LVM /dev/sda3 419430400 524287999 104857600 50G 8e Linux LVM Command (m for help): w The partition table has been altered. Syncing disks.
3.LVM設定
[root@c80g167 ~]# vgextend cl /dev/sda3
Volume group "cl" successfully extended
[root@c80g167 ~]# lvextend /dev/cl/root /dev/sda3
Size of logical volume cl/root changed from <196.95 GiB (50419 extents) to <246.95 GiB (63218 extents).
Logical volume cl/root successfully resized.
4.xfs_growfsとdf確認
[root@c80g167 ~]# xfs_growfs / meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=12907264 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=51629056, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=25209, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 51629056 to 64735232 [root@c80g167 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 888M 0 888M 0% /dev tmpfs tmpfs 904M 0 904M 0% /dev/shm tmpfs tmpfs 904M 9.4M 894M 2% /run tmpfs tmpfs 904M 0 904M 0% /sys/fs/cgroup /dev/mapper/cl-root xfs 247G 7.0G 240G 3% / /dev/sda1 ext4 976M 134M 776M 15% /boot tmpfs tmpfs 181M 16K 181M 1% /run/user/0
以上です。
5.最後に
以下のサイトを参考にさせて頂きました。
Extending Centos 8 root size - CentOS
冒頭にも書きましたが、最初は
xfs_growfs /
に気付かず、
resize2fsを試したりと、時間を浪費してしまったので、今回の記事を書きました。