Increase/Expand XFS Filesystem in CentOS 7
This guide will explain how to grow an XFS filesystem once you’ve increased the underlying storage.
I applied these steps to one of my personal VM running on Orange Cloud.
Prerequisites
- A snapshot is created to back up data.
- To prevent data loss caused by incorrect operations, I recommend that you create a snapshot to back up your data by your cloud provider console or take it manually on another storage.
- Request volume resize from your cloud provider console.
- The growpart or xfsprogs tool is installed based on your operating system.
yum install cloud-utils-growpart xfsprogs -y
Steps
We have a root partition of 10G on a 100G disk (commands entered are shown starting with #, notable parts in bold):
[root@gameserver ~]# df -Th / Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 20G 10.1G 9.9G 51% /
Run lsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather information.
[root@gameserver ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom sr1 11:1 1 444K 0 rom vda 252:0 0 100G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 99G 0 part ├─centos-root 253:0 0 20G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] [root@ad-holdingwebserver ~]#
Delete and Create new volume
[root@gameserver ~]# 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): d Partition number (1,2, default 2): Partition 2 is deleted Command (m for help): p Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000a87fe Device Boot Start End Blocks Id System /dev/vda1 * 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): Using default response p Partition number (2-4, default 2): First sector (2099200-209715199, default 2099200): Using default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-209715199, default 209715199): Using default value 209715199 Partition 2 of type Linux and of size 99 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): wq 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.
Then run the following commands
[root@gameserver ~]# pvresize /dev/vda2 Physical volume "/dev/vda2" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@gameserver ~]# lvextend /dev/mapper/centos-root -l +100%FREE Size of logical volume centos/root changed from <20.00 GiB (4351 extents) to <97.00 GiB (24831 extents). Logical volume centos/root successfully resized.
[root@gameserver ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=4455424, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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 4455424 to 25426944 [root@ad-holdingwebserver ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 11M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/centos-root 97G 8.9G 89G 10% / /dev/vda1 1014M 207M 808M 21% /boot tmpfs 779M 0 779M 0% /run/user/0
Post Views: 648