… or how to resize a file system on CentOS 7. Due to moving my home partition to a new disk I gained some space back from the logical volume home. After deleting it I thought that it would be a good idea to add those additional 10GB to the my root disk.
I started with:
[root@jcdesk Desktop]# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID jxyjgx-veql-Hzxk-1ynz-b6i2-BQoe-xGhrCb LV Write Access read/write LV Creation host, time jc-desk.luht.scot.nhs.uk, 2015-06-11 .... LV Status available # open 1 LV Size 105.00 GiB Current LE 26879 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
The size of the root volume was 105GiB. The additional space should be 10GiB.
[root@jcdesk Desktop]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 105.00 GiB (26879 extents) to 115.00 GiB (29440 extents). Logical volume root successfully resized
That added all the free space in the volume group to my root volume.
[root@jcdesk ~]# lvdisplay /dev/centos/root --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID jxyjgx-veql-Hzxk-1ynz-b6i2-BQoe-xGhrCb LV Write Access read/write LV Creation host, time jc-desk.luht.scot.nhs.uk, 2015-06-11 ... LV Status available # open 1 LV Size 115.00 GiB Current LE 29440 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
Strike !!! So far so good. Now lets resize the file system.
[root@jcdesk Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 105G 7.0G 98G 7% /
I tried to resize the file system to the new size.
[root@jcdesk Desktop]# resize2fs /dev/mapper/centos-root resize2fs 1.42.9 (28-Dec-2013) resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root Couldn't find valid filesystem superblock.
Oops !!!!! 8-o
I took me a while to find out that LVM is using xfs as their file system.
[root@jcdesk ~]# mount | grep centos-root /dev/mapper/centos-root on / type xfs (rw,relatime,...
Xfs comes with its own command set.
[root@jcdesk ~]# xfs [tab][tab] xfs_admin xfs_copy xfsdump xfs_freeze xfs_growfs xfsinvutil xfs_logprint xfs_metadump xfs_ncheck xfs_repair xfs_rtcp xfs_bmap xfs_db xfs_estimate xfs_fsr xfs_info xfs_io xfs_mdrestore xfs_mkfile xfs_quota xfsrestore
So instead of using the resize2fs command I had to use the xfs_growfs command.
[root@jcdesk ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize= 6881024 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=27524096, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=13439, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 27524096 to 30146560
A final check:
[root@jcdesk ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 115G 7.0G 108G 7% /
….. done.
Thanks, you saved my friday and weekend
Thanks, this blog is super helpful! It hit the nails and resolved my issue on Veteran’s Day.
Another way to find out the type is to run blkid command.
[root@msdlva-ctwwik01 appdev]# blkid /dev/mapper/rhel-root
/dev/mapper/rhel-root: UUID=”xxx” TYPE=”xfs”
[root@wik01 appdev]# mount | grep root
/dev/mapper/rhel-root on / type xfs (rw,noatime,nodiratime,attr2,inode64,noquota)
Many thanks Juergen! I was stumbling at resize2fs and quickly found your post allowing me to complete my partition resizing.
Many kudo!
Robert
Thanks!
Thanks a lot,very helpfull
Thank you!
Many thanks, very helpfull… it saves me time…
Thanks for your tutorial..
thanks, so good!
Looked everywhere.. thanks for that info.. did not see xfs_growfs anywhere.
Thanks.
Exactly what I was looking for…
phew thanks for posting this!
thanks for that info
Thank you for your solution! I was in panic because I didn’t understand what is wrong (I’m new in system administration). Thank you very much for this post:)
Thanks, it worked! Was trying to resolve the issue for hours…
you saved my day thank you so much i was stuck here until i found out of xfs.thanks again cheers!
Thanks a lot for sharing, worked for my CentOS7 VM image.
Thanks for the post !
Thanks man you saved my life hahahah
Saved my job, fantastic … thank you very much.
Thanks for the post
Excelent!!!
Thanks I take the same problem and solved thanks to you.
Thank you man, this saved my evening! ๐
Hi,
Thanks. This was a lifesaver ๐
Many thank’s
Solved my problem
Perfect!!!
Thanks!!!
Thanks a lot,very helpfull
Perfect Thank you very much!
Thanks a lot! In 2018 your post continue to help someone…ME…. ๐
Thanks, Great Help ๐
Great, finally a worthy solution. You saved my day
Perfect!!! You save my weekend!!! Thanks a lot!!!
Great ! solve my problem.
Saved my Evening Brother !!! Good solution
Thanks…..my idol
Thank you for this, I got some info from Amazon while trying to grow a root disk but the advice was based on their Amazon Linux AMI that used a different filesystem type and boy howdy, was _that_ a scary error message to get!
Many thanks for this post !
Very helpful post, many thanks.
Gracias, excelente informacion
Thanks so much!!!!
Thx a lot
he was save me
I was also stranded.
The post did wonders for me.
Thanks a lot
Thank you so much! I had beem struggling with this for hours!
Hi,
Thank you so much for your help. XFS works in a different way
Thanks so much!!
Thank you very much….it saved my day
Thank you so much. You’re save me ๐
Merci infiniment รงa m’a beaucoup aidรฉ !
Many thanks for your post – saved a lot of frustration!