We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Resize XFS / Btrfs file systems on Linux

Learn how to – How To Resize XFS / Btrfs file systems on Linux.

A Linux file system can be defined as a structured collection of files on a partition or disk. This is an in-built layer in the Linux Operating system that handles data management in the storage. Data is stored in a hierarchal structure with root directories and subdirectories in it. There are many supported file systems on Linux that include; EXT, EXT2, EXT3, EXT4, JFS, Swap, XFS, ReiserFS, Btrfs e.t.c

In this guide, we will walk through how to resize XFS / Btrfs file systems on Linux. The XFS file system is referred to as the high-speed JFS(Journaled File System). This file system is developed for parallel I/O processing. The Btrfs(B tree file system) is known for fault tolerance, extensive storage configuration, repair system e.t.c

Resizing file systems is different from resizing partitions/volumes which makes more space on the physical volume. When using the YaST Partitioner to resize logical volumes, the files systems are automatically adjusted to new sizes of the partition. However, in some cases, you might need to resize the file systems manually. The cases that you might need to resize the file system manually include:

  • After resizing a virtual disk of a VM Guest.
  • To shrink Btrfs file systems, YaST only supports growing Btrfs file systems
  • After resizing a volume from a network-attached storage
  • After resizing partitions manually with fdisk/parted

But remember, resizing file systems involves risks that potentially could lead to data loss. Therefore, it is highly recommended that you take a backup of the available data before you resize the file system. Below is a table to show Linux file systems that support resizing.

File System Utility Tool Grow Shrink
XFS xfs_growfs Online Not supported
Btrfs btrfs filesystem resize Online Online
Ext2 resize2fs Online/Offline Offline only
Ext3 resize2fs Online/Offline Offline only
Ext4 resize2fs Online/Offline Offline only

When growing/increasing a file system, you can specify the exact size to grow to or grow to the maximum space available. But before you grow the size of a file system, ensure the size of the logical volume/device has been grown. When shrinking or growing the file system by specifying the size, the following must be met:

  • The new size must be greater than the size of the existing data. Otherwise, data loss will occur.
  • The new size to grow must be equal to/less than the current device size since the file system size cannot extend beyond the available space.

1. Create the Partition/Logical Volume

I assume that you already have the partition/logical volume to grow. This guide will demonstrate how to resize an XFS file system by mounting another disk(sdb) and growing the volume:

$ lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                  8:0    0   40G  0 disk 
├─sda1               8:1    0    1G  0 part /boot
└─sda2               8:2    0   39G  0 part 
  ├─almalinux-root 253:0    0   35G  0 lvm  /
  └─almalinux-swap 253:1    0    4G  0 lvm  [SWAP]
sdb                  8:16   0   10G  0 disk 
sr0                 11:0    1 1024M  0 rom  

To identify the file system on your device, use the lsblk -f command.

Now create a partition table on the mounted disk.

sudo cfdisk /dev/sdb

Select dos type and proceed as below:

    Device        Boot       Start         End     Sectors   Size   Id Type
>>  Free space                2048    20971519    20969472    10G               

           [   New  ]  [  Quit  ]  [  Help  ]  [  Write ]  [  Dump  ]

Create a new partition with say 6GB size and leave some free space on your device.

Set it as a primary partition.

Now you will have the partition created as below. Write changes to the disk.

When prompt to write changes, agree by typing yes.

Once that changes have been made, quit and proceed to verify if the partition has been created:

$ lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                  8:0    0   40G  0 disk 
├─sda1               8:1    0    1G  0 part /boot
└─sda2               8:2    0   39G  0 part 
  ├─almalinux-root 253:0    0   35G  0 lvm  /
  └─almalinux-swap 253:1    0    4G  0 lvm  [SWAP]
sdb                  8:16   0   10G  0 disk 
└─sdb1               8:17   0    6G  0 part 
sr0                 11:0    1 1024M  0 rom  

Create the XFS/Btrfs file system on it.

##For XFS
sudo mkfs.xfs /dev/sdb1 -f

##For Btrfs
sudo mkfs.btrfs /dev/sdb1 -f

Mount the file:

sudo mkdir /mnt/datastore
sudo mount /dev/sdb1 /mnt/datastore
sudo mount | grep /dev/sdb1

Sample Output:

##For XFS
/dev/sdb1 on /mnt/datastore type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)

##For Btrfs
/dev/sdb1 on /mnt/datastore type btrfs (rw,relatime,space_cache,subvolid=5,subvol=/)

I assume to have content in the path:

$ ls -al /mnt/datastore/
total 0
drwxr-xr-x. 4 root root 32 Apr 12 05:23 .
drwxr-xr-x. 3 root root 23 Apr 12 05:22 ..
drwxr-xr-x. 2 root root  6 Apr 12 05:23 new
drwxr-xr-x. 2 root root  6 Apr 12 05:23 new.txt

2. Grow the Partition/Logical Volume

First, check the current size of the partition.

$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    1.8G     0  1.8G   0% /dev
tmpfs                       1.9G     0  1.9G   0% /dev/shm
tmpfs                       1.9G  9.2M  1.9G   1% /run
tmpfs                       1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/almalinux-root   36G  4.6G   31G  14% /
/dev/sda1                  1014M  347M  668M  35% /boot
tmpfs                       374M   12K  374M   1% /run/user/42
tmpfs                       374M  4.0K  374M   1% /run/user/1000
/dev/sdb1                   6.0G   76M  6.0G   2% /mnt/datastore

Here, we will grow the /dev/sdb1 partition manually with fdisk to 10GB. Launch the utility tool and proceed to modify the partition to a new size:

sudo cfdisk /dev/sdb

Delete the partition.

Create a new partition bigger than the previous one of the preferred size. Here, we will create a 10GB partition using the free space on the device.

Set it as a primary partition and write the changes and quit:

3. Resize XFS/Btrfs file systems on Linux

Once you have grown the partition, proceed and resize the file systems as below.

3.1. Resize XFS file systems

This can be achieved using the xfs_growfsutility tool. This command is only used to grow the size of a file system and shrinking cannot be done.

To grow the XFS file system, use the command with the syntax below:

sudo xfs_growfs -d size /mount/point

The -d size specifies the size to grow to. Using the -d command without specifying the size will grow to the maximum size supported by the device.

For this guide, the command will be

sudo xfs_growfs -d /mnt/datastore

Sample Output:

Verify if the changes have been made:

$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    1.8G     0  1.8G   0% /dev
tmpfs                       1.9G     0  1.9G   0% /dev/shm
tmpfs                       1.9G  9.2M  1.9G   1% /run
tmpfs                       1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/almalinux-root   36G  4.6G   31G  14% /
/dev/sda1                  1014M  347M  668M  35% /boot
tmpfs                       374M   12K  374M   1% /run/user/42
tmpfs                       374M  4.0K  374M   1% /run/user/1000
/dev/sdb1                    10G  104M  9.9G   2% /mnt/datastore

Verify if the files still exist:

3.2. Resize Btrfs file systems on Linux.

For the Btrfs file system, the btrfs filesystem resizecommand can be used to grow and shrink the file system considering the required conditions are met.

To grow/shrink the Btrfs file system on Linux using the command with the syntax:

sudo btrfs filesystem resize amount /mount/point

For example, to grow the filesystem with 1GB, the command will be:

$ sudo btrfs filesystem resize +1G /mnt/datastore
Resize '/mnt/datastore' of '+1G'

Verify the size:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  1.2M  392M   1% /run
/dev/sda1        39G  5.0G   32G  14% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           394M   84K  394M   1% /run/user/116
tmpfs           394M   56K  394M   1% /run/user/1000
/dev/sdb1       7.0G  3.6M  6.5G   1% /mnt/datastore

To shrink the file system by 1GB, the command will be:

$ sudo btrfs filesystem resize -1G /mnt/datastore
Resize '/mnt/datastore/' of '-1G'

Verify if the file system has been decreased:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  1.2M  392M   1% /run
/dev/sda1        39G  5.0G   32G  14% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           394M   84K  394M   1% /run/user/116
tmpfs           394M   56K  394M   1% /run/user/1000
/dev/sdb1       6.0G  3.6M  5.5G   1% /mnt/datastore

You can also grow the file system to the maximum available space:

$ sudo btrfs filesystem resize max /mnt/datastore
Resize '/mnt/datastore' of 'max'

Verify as below:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  1.2M  392M   1% /run
/dev/sda1        39G  5.0G   32G  14% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           394M   84K  394M   1% /run/user/116
tmpfs           394M   56K  394M   1% /run/user/1000
/dev/sdb1        10G  3.6M  9.5G   1% /mnt/datastore

Verify if the files exist:

Voila!

We have triumphantly walked through how to resize XFS / Btrfs file systems on Linux. With this guide, you can proceed and resize your XFS / Btrfs file systems. I hope this was significant.

Related posts:

Cart

Your Cart is Empty

Back To Shop