Expand XFS filesystem in RHEL 7 using same disk in vSphere/vCenter
# fdisk -l
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 20G 5.8G 15G 29% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 13M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/rhel-opt 15G 781M 15G 6% /opt
/dev/mapper/rhel-tmp 15G 33M 15G 1% /tmp
/dev/mapper/rhel-var 20G 1.6G 19G 8% /var
/dev/mapper/vg_DATA-lv_DATA 100G 33M 100G 1% /DATA
/dev/sda1 1014M 270M 745M 27% /boot
/dev/mapper/rhel-home 15G 673M 15G 5% /home
We need to increase /DATA by doing expansion on same disk( no new disk).
Increase the disk size at VM from 100G to 200G.
Run below command:
# ls /sys/class/scsi_device/
1:0:0:0
1:0:1:0 2:0:0:0
Here 1:0:0:0 is root disk and 1:0:1:0 is the DATA disk.
To expand DATA at RHEL 7 , run below command:
echo 1 > /sys/class/scsi_device/
1\:0\:1\:0/device/rescan
Run fdisk -l and we can see the same disk /dev/sdb has expanded to 200G.
# fdisk -l
Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Now run below to increase physical volume.
# pvresize /dev/sdb
Physical volume "/dev/sdb" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Here we can see that 100G free space has allocated.
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 117.00g 4.00m
/dev/sdb vg_DATA lvm2 a-- <200.00g 100.00g
Same has visible in volume group:
]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 6 0 wz--n- 117.00g 4.00m
vg_DATA 1 1 0 wz--n- <200.00g 100.00g
# vgdisplay
VG Name vg_DATA
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <200.00 GiB
PE Size 4.00 MiB
Total PE 51199
Alloc PE / Size 25599 / <100.00 GiB
Free PE / Size 25600 / 100.00 GiB
Expand the logical volume:
]# lvextend -l +100%FREE /dev/mapper/vg_DATA-lv_DATA
Size of logical volume vg_DATA/lv_DATA changed from <100.00 GiB (25599 extents) to <200.00 GiB (51199 extents).
Logical volume vg_DATA/lv_DATA successfully resized.
Now expand the partition:
# xfs_growfs /dev/mapper/vg_DATA-lv_DATA
meta-data=/dev/mapper/vg_DATA-lv_DATA isize=512 agcount=4, agsize=6553344 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=26213376, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 26213376 to 52427776
We can see that now /DATA has extended to 200G.
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 20G 5.8G 15G 29% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 13M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/rhel-opt 15G 781M 15G 6% /opt
/dev/mapper/rhel-tmp 15G 33M 15G 1% /tmp
/dev/mapper/rhel-var 20G 1.6G 19G 8% /var
/dev/mapper/vg_DATA-lv_DATA 200G 33M 200G 1% /DATA
/dev/sda1 1014M 270M 745M 27% /boot