I have a very large partition (15TB) formated with the XFS filesystem that I want to expand to 30TB. This partition was created with Parted to use GPT, which fdisk does not support. The problem with this is Parted automatically will expand the underlying filesystem when resizing a partition, but it does not support XFS. The slightly advanced solution is not hard, you just have to be careful.
To start with let me say, if you are not somewhat experienced with filesystems and partition tables, please do not attempt this. I am not responsible if you hose your system.
With that out of the way, we will be deleting the partion table, recreating it with the same starting boundary and then expanding the filesystem. When you modify the partition table, it does not necessarily change the data stored on the partition. You can delete it and then recreate it with the same boundaries and not hurt the data. It is extremely important that you line your partition on the same boundaries or you can over-write existing data. So by creating a new partition with the same starting boundary and extending it past any written data, we are ensuring that the boundaries line up properly.
I have already completed my own partition and filesystems resizing, so I will by using a flash drive as an example. The method is the same, just smaller sizes.
First examine the device. As you can see, I have roughly a 4GB partition. To resize the partition, you must first unmount it.
[cpowell@cp-linuxsvr] ~ $ sudo parted /dev/sdd GNU Parted 2.2 Using /dev/sdd Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: Corsair Flash Voyager (scsi) Disk /dev/sdd: 8087MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 512B 4043MB 4043MB primary XFS
Now the to reiterate, the most important thing is to line up the starting boundary of the partition. The problem shown above, is the Start 512B is listed in bytes. You might get away using that as the starting boundary, but it is not accurate enough for me to feel safe. We must change the units to sectors so we can see the exact sector used as the starting boundary.
(parted) help unit unit UNIT set the default unit to UNIT UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %, kiB, MiB, GiB, TiB (parted) unit s (parted) p Model: Corsair Flash Voyager (scsi) Disk /dev/sdd: 15794176s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1s 7897087s 7897087s primary XFS
As you can see, if you run help unit, it lists all the available units with compact being the default. We then set the unit to s and print out the partition table again. You can see now the exact sector it starts on, 1s.
Now to remove the existing partition and create a new one using the entire device.
(parted) rm 1 (parted) mkpart primary 1s 100% (parted) p Model: Corsair Flash Voyager (scsi) Disk /dev/sdd: 15794176s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1s 15794175s 15794175s primary XFS (parted) unit compact (parted) p Model: Corsair Flash Voyager (scsi) Disk /dev/sdd: 8087MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 512B 8087MB 8087MB primary XFS
There is alot happening above, so lets walk through it. First we are deleting partition 1, rm 1. We then create a new primary partition with a starting boundary of 1s and to extend to use 100% of the device. I then print out the partition table again, but because the units are still in s, it is hard to determine size so I change to a more user friendly output unit (compact) and print it out again. You can now see partition extends to 8GBs. Now we can grow out the underlying filesystem.
To grow out an XFS filesystem, you must mount it first. Remember, that you can always grow with XFS, but you cannot shrink. Below, you see that even though the partition is 8GB, the filesystem is only using 4GB.
[cpowell@cp-linuxsvr] ~ $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sdd1 3.8G 4.2M 3.8G 1% /mnt/tmp
Growing with XFS is simple. xfs_growfs mount_point This will grow out the mounted filesystem to use the remainder of the partition, if you wish to do something more fancy please consult the man pages.
[cpowell@cp-linuxsvr] ~ $ sudo xfs_growfs /mnt/tmp meta-data=/dev/sdd1 isize=256 agcount=4, agsize=246784 blks = sectsz=512 attr=2 data = bsize=4096 blocks=987135, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 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 987135 to 1974271 [cpowell@cp-linuxsvr] ~ $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sdd1 7.6G 4.3M 7.6G 1% /mnt/tmp
The filesystem is now expanded to ~8GB utilizing the entire device.