Expand XFS Partition using Parted

Expand XFS Partition using Parted

Have you ever tried expanding XFS partition using Parted? If yes, then you might have encountered the following issue for sure.

No Implementation: Support for opening xfs file systems is not implemented yet.

The problem here is that Parted does not support resizing of xfs partition.

But there is a way around this problem. This is a little tricky so you need to be careful and have enough knowledge to deal with this.

I tested this solution on a development machine. Let me mention this very specifically that in case you do not have any experience in table partitioning and filesystem management, I won’t recommend this to you. Any issues that this might cause to your filesystem will be your responsibility.

Enough of statutory warnings! It is important to note that changing the partition table does not impact the data which resides on the partition. In this case what we will do is, delete the partition and recreate it with the same boundary. So expanding would literally mean using the adjacent space on the drive. So we will use the same starting boundary for the partition and expand it to end of drive.

Please note that it is very important to identify the boundaries for your partition.

I will provide the example of the dev machine which I expanded the partition for.

Expand XFS Partition using Parted

Let’s check what we have on this partition first.

[[email protected] ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  6442MB  6441MB  primary  xfs 

We can say that the starting boundary for partition 1 is 1049kB. However, there is more involved than just size in the table partitioning. We should take a look at the actual sector where partition starts.

Thank fully you can change the unit in Parted to find this out. I changed the unit to list the sector based details for the partition.

(parted) unit s
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 83886080s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End        Size       Type     File system  Flags
 1      2048s  12582911s  12580864s  primary  xfs

On the side note, the default unit in Parted is compact. You can find more about available unit in Parted using the following in parted prompt.

help unit

Now beings the tricky part. Here’s a brief overview of what we will be doing.

  • We will make note of starting sector of partition 1 from the output above.
  • We will delete the partition 1.
  • we will create partition 1 with the starting sector of 2048s from above.
  • The end limit will be defined as 100% to fill upto last available space on drive.
  • That is exactly what I did in this case.

    (parted) rm 1                                                             
    (parted) p                                                                
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdb: 83886080s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start  End  Size  Type  File system  Flags
    
    (parted) mkpart                                                           
    Partition type?  primary/extended? primary                                
    File system type?  [ext2]? xfs                                            
    Start? 2048s                                                              
    End? 100%                                                                 
    (parted) p                                                                
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdb: 83886080s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start  End        Size       Type     File system  Flags
     1      2048s  83886079s  83884032s  primary  xfs
    
    (parted) unit compact                                                     
    (parted) p                                                                
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sdb: 42.9GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  42.9GB  42.9GB  primary  xfs
    

    There you go!

    You just Expanded XFS partition using Parted here.

    Now comes the easy part. Expanding the XFS filesystem.

    You can use the xfs_growfs utility provided by XFS. However, to expand the XFS filesystem you need the partition mounted.

    So I mount the partition and expand it using xfs_growfs.

    [[email protected] ~]# mount /dev/sdb1 /mnt/temp
    
    [[email protected] ~]# df -h
    Filesystem                    Size  Used Avail Use% Mounted on
    /dev/sdb1                     6.0G  1.5G  4.6G  25% /mnt/temp
    
    [[email protected] ~]# xfs_growfs /mnt/temp
    meta-data=/dev/sdb1              isize=256    agcount=4, agsize=393152 blks
             =                       sectsz=512   attr=2, projid32bit=0
    data     =                       bsize=4096   blocks=1572608, 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 1572608 to 10485504
    
    [[email protected] ~]# df -h
    Filesystem                    Size  Used Avail Use% Mounted on
    /dev/sdb1                      40G  1.5G   39G   4% /mnt/temp
    

    There you have it. The XFS partition is now using the entire available disk.

    Expand XFS Partition using Parted

    No Comments

    Post a Comment

    Time limit is exhausted. Please reload CAPTCHA.