Extend XFS parititon ( xfs_growfs )

9,553

You want to resize your home partition but the swap partition is in the way. Rough outline follows.

First, check the current size of your home partition:

blockdev --getsize64 /dev/sda3

Disable swap:

swapoff -a

Delete swap partition:

parted /dev/sda rm 4

Resize home partition but leave 1GiB for a new swap partition at the end.

parted /dev/sda -- resizepart 3 -1GiB

Re-create swap partition:

parted /dev/sda -- mkpart swap -1GiB -1

Now verify whether the kernel was able to re-read partition table:

blockdev --getsize64 /dev/sda3

If that prints the old size you have reboot first. Note that reboot now might complain about swap missing; adapt your /etc/fstab and update initramfs accordingly.

Finally, grow:

xfs_growfs /dev/sda3

And re-create swap:

mkswap /dev/sda4
swapon /dev/sda4

Don't forget to re-add a new swap entry to your /etc/fstab.

Share:
9,553

Related videos on Youtube

Zorba
Author by

Zorba

Updated on September 18, 2022

Comments

  • Zorba
    Zorba over 1 year

    Here are the partitions of my server :

    NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   54.6T  0 disk
    ├─sda1   8:1    0 1004.5K  0 part
    ├─sda2   8:2    0   19.5G  0 part /
    ├─sda3   8:3    0     16T  0 part /home
    └─sda4   8:4    0    511M  0 part [SWAP]
    

    And here is the print table :

    Disk /dev/sda: 60.0TB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags:
    
    Number  Start   End     Size    File system     Name     Flags
     1      20.5kB  1049kB  1029kB                  primary  bios_grub
     2      2097kB  21.0GB  21.0GB  ext4            primary
     3      21.0GB  17.6TB  17.6TB  xfs             primary
     4      17.6TB  17.6TB  536MB   linux-swap(v1)  primary
    

    I need to grow the partition /home to the total disk space ( 54.6T ).

    I've tried with xfs_growfs and gave the command :

    xfs_growfs  /home -d
    

    although tried with

    xfs_growfs  /dev/sda3 /home -d
    

    But it always says data size unchanged, skipping and instead growing /home to the total disk space of sda it tries to grow it to the total space of sda3 which is already grew totally :

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        16T   33M   16T   1% /home
    

    So how can I solve that problem?

    • frostschutz
      frostschutz about 8 years
      You have to resize your partition first? parted /dev/sda unit mib print free. Might have to delete swap partition first since it seems to be in the way.
    • Zorba
      Zorba about 8 years
      Well parted means alternative method I think, and there will be resize instead of xfs_growfs... anyways I deleted swap partition and now i can see the free space how can I create swap partition again to include the total free space in it, then resize partition 3 to include this free space ? . I tried with mkpartfs but doesn't work !
  • frostschutz
    frostschutz about 8 years
    Hence I said rough outline, I'll leave the minor details to you... :p
  • Zorba
    Zorba about 8 years
    resizepart doesn't work at all so I'm still stuck at the step : parted /dev/sda -- resizepart 3 -1GiB . maybe because the filesystem in partition 3 is XFS, and as I know XFS partitions cannot be reduced but only extended ?
  • Zorba
    Zorba about 8 years
    I never found resizepart or resize in commands list of ( GNU Parted 3.1 ) which included in my OS. maybe it's why that command doesn't work with me ?
  • frostschutz
    frostschutz about 8 years
    Sorry, in that case, try parted 3.2, it's well over a year (closer 2 years) old by now ... also the second one will give you alignment trouble since the "end" does unfortunately not back off by a sector. But if you're managing a 60TB machine you should be able to handle these.
  • frostschutz
    frostschutz about 8 years
    Alternatively you can unit s, print, note down the start sector, then rm, mkpart with exactly that start sector.
  • Zorba
    Zorba about 8 years
    It works and the partition 3 size was really changed, but when I try to xfs_growfs it doesn't grow !
  • frostschutz
    frostschutz about 8 years
    Does blockdev report the new size?
  • Zorba
    Zorba about 8 years
    Yes blockdev reported a new size ... Maybe I have to adapt /etc/fstab and update initramfs before xfs_growfs ? .. how to do both of that ?
  • frostschutz
    frostschutz about 8 years
    No, it should just grow; what's the error message / output of the grow command?
  • Zorba
    Zorba about 8 years
  • frostschutz
    frostschutz about 8 years
    And blockdev --getsize64 says which number? Also can you show /proc/mounts, which mount options is it using?
  • Zorba
    Zorba about 8 years
    Well blockdev --getsize64 /dev/sda3 gives the number 17592168220160 ... do you mean cat /proc/mounts ? , it shows a very big list : s18.postimg.org/8ycs32tft/2016_03_07_21_01_40.jpg
  • frostschutz
    frostschutz about 8 years
    Well, according to blockdev the partition is only 16TB. You might have to reboot (or otherwise umount everything on the disk and tell kernel to re-read partition table)
  • Zorba
    Zorba about 8 years
    Well actually the partition table didn't change after kernel command . I still cannot resize through xfs_growfs
  • Zorba
    Zorba about 8 years
    thanks for your time... I solved it by deleting both partitions 3 and 4, then mkpart for partition 3 .. and now the total disk space 54.6T included in partition 3 /home/ , so there was no need to use xfs_growfs .. and about swap should I make a new swap partition or no problem without swap ? ... what do you recommend ?
  • Zorba
    Zorba about 8 years
    Actually I'm not sure the current situation is fine because lsblk table and blockdev shows that the total disk space included in /home, but in df -h nothing changed, the size of /home still 16 TB ! ... how can that occurs !? s16.postimg.org/d2jhfroh1/2016_03_07_23_43_43.jpg
  • frostschutz
    frostschutz about 8 years
    I wrote step by step in my answer, is it really that hard to follow? You write there was no need to use growfs, but without growfs it's no wonder it's still at 16T...
  • Zorba
    Zorba about 8 years
    Well that means lsblk and blockdev are not necessarily giving always the right values ! .... of course I prefer to grow the partition through growfs to don't have any problem with the new size later , but as you saw the command didn't work with me ... Anyways I'm gonna re-installed the OS and repeating the process again.
  • frostschutz
    frostschutz about 8 years
    not sure what to tell you. xfs_growfs grows the filesystem, not partitions. you have to grow the partition first, then the filesystem. it's two separate things.
  • Zorba
    Zorba about 8 years
    I got it ... that's what I just did now, growing the partition then growing the filesystem and I think it works now as long as the data blocks increased after performing xfs_growfs ... s14.postimg.org/4m05g8ov5/2016_03_08_1_20_12.jpg ... thank you