How to Add or Extend Btrfs File System Storage in Linux

We know how useful the Btrfs file system. A Btrfs file system allows us to add, resize or delete other Btrfs devices.

This guide will focus on how to add a new btrfs device to the current system in Linux. But before reading further, you should know how to create a btrfs file system. If you don’t know how to create a btrfs format, not a problem I’ll guide you in short.

Check Btrfs File System

We will first list out the all the Btrfs file system are available on the Linux system, To check type the following command on your terminal:

$ sudo btrfs filesystem show
Label: none  uuid: d6b90e68-7485-4786-ac2e-d7bc204b2c7b
	Total devices 1 FS bytes used 192.00KiB
	devid    1 size 14.32GiB used 536.00MiB path /dev/sdb

The above output listed the available btrfs files in my system, and It is not showing my second disk because the file format is ext4.

Now we will convert the second disk to the btrfs system. Otherwise, we will not add the second disk in the current btrfs file system.

Create a Btrfs system

Open your terminal and type command to check disk name

$ lsblk
sda      8:0    0 465.8G  0 disk  
├─sda1   8:1    0   499M  0 part  
├─sda2   8:2    0    99M  0 part  
├─sda3   8:3    0    16M  0 part  
├─sda4   8:4    0 145.3G  0 part  
├─sda5   8:5    0   621M  0 part  
├─sda6   8:6    0 146.5G  0 part  
├─sda7   8:7    0 127.5G  0 part  /
sdb      8:16   1  14.3G  0 disk  /media/linuxshelltips
sdc      8:32   1   3.8G  0 disk 

I want to create a btrfs file system to the “sdc” partition with 3.8G disk size.

Now we know the name of the partition, and move to create a btrfs file system. To create a btrfs system type or copy-paste the below command.

$ sudo mkfs.btrfs -f /dev/sdc
btrfs-progs v5.7 
See http://btrfs.wiki.kernel.org for more information.

Label:              (null)
UUID:               e16ba8be-11b4-4f01-82b2-25b70da898b2
Node size:          16384
Sector size:        4096
Filesystem size:    3.75GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP             256.00MiB
  System:           DUP               8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Runtime features:   
Checksum:           crc32c
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1     3.75GiB  /dev/sdc

Using the above method, you will create a btrfs file system, and now we will add second disk storage to primary disk storage.

Add new disk to Btrfs system

In the above step, we have format second disk storage to the btrfs file system to verify we will check the available btrfs system.

$ sudo btrfs filesystem show

This command will show you the two btrfs disk storage.

In my case already primary disk storage is mounted at “/newbtrfsdir”. Now will add or mount second disk storage with the primary disk storage location using the below command.

$ sudo btrfs device add -f /dev/sdc /newbtrfsdir/

It will not give you any confirmation message, To verify the changes pass the command:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           785M  2.0M  783M   1% /run
/dev/sda7       126G  106G   14G  90% /
tmpfs           3.9G  268M  3.6G   7% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda9       4.0G  201M  3.8G   5% /boot/efi
tmpfs           785M  108K  785M   1% /run/user/110
tmpfs           785M  148K  785M   1% /run/user/1000
/dev/sdb         19G  3.6M   18G   1% /newbtrfsdir

From the above output you can see the primary disk “/dev/sdb” size in now 19GB earlier it was 15GB.

To get into more detail view type below command in your terminal:

$ sudo btrfs filesystem show 
Label: none  uuid: d6b90e68-7485-4786-ac2e-d7bc204b2c7b
	Total devices 2 FS bytes used 192.00KiB
	devid    1 size 14.32GiB used 536.00MiB path /dev/sdb
	devid    2 size 3.75GiB used 0.00B path /dev/sdc

That’s it we able to add a new btrfs disk to the primary btrfs file system. In case you’re facing any difficulty then please let me know in the comment section.

Read this How to Get Install Docker Compose On Ubuntu 20.04 LTS

Leave a Reply