rss logo

My personal Btrfs file system reminder

Tux logo

Btrfs is a relatively new file system offering a number of features such as transparent compression, snapshots, online volume growth and shrinking and so on… It is increasingly used in GNU/Linux distributions. I'm going to present here the main commands you need to know when using this file system.

Extend a Partition Size

⚠️To avoid any data loss, be sure to back up your data before you begin any resizing task. And make sure you understand the commands before typing them.⚠️

  • Let's assume we have this type of disk configuration:
GNU/Linux | Disk partition scheme
  • First, we need to reconfigure the disk boundaries:
root@host:~# gdisk /dev/sda Command (? for help): d Partition number (1-3): 3 Command (? for help): n Partition number (3-128, default 3): 3 First sector (34-125829086, default = 3147776) or {+-}size{KMGTP}: 3147776 Last sector (3147776-125829086, default = 167772126) or {+-}size{KMGTP}: Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/sda. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. root@host:~# partprobe
  • Extend the file system size to the maximum available size of the device:
root@host:~# btrfs filesystem resize max /
  • We can also reduce or extend the file system to a specific size:
root@host:~# btrfs filesystem resize -1G /data/



  • Run a online file system check:
root@host:~# btrfs scrub start /
  • Check the status of a running scrub:
root@host:~# btrfs scrub status /


  • Subvolumes enable:
    • Isolation: Subvolumes can be used to isolate different parts of your file system
    • Snapshots: Subvolumes can be independently snapshotted
    • Separate mount point: Subvolumes can be mounted independently at different points in the file system hierarchy.
    • Quotas: Btrfs allows you to set quotas on subvolumes
  • Graphical view of Btrfs subvolumes:
Disk partition scheme showing Btrfs subvolumes
  • Create a subvolume:
root@host:~# btrfs subvolume create /home/SUBV
  • List subvolumes:
root@host:~# btrfs subvolume list /
  • Mount subvolume:
root@host:~# mount /dev/sda3 -o subvol=SUBV /home/SUBV/


  • Format partition with Btrfs file system:
root@host:~# mkfs.btrfs /dev/sdb1
  • Online degragmentation:
root@host:~# btrfs filesystem defragment -r -v /
  • Show detailed information about internal filesystem usage:
root@host:~# btrfs filesystem usage /
  • Summarize disk usage of files:
root@host:~# btrfs filesystem du /home/user/file
  • Show space usage information for a mount point:
root@host:~# btrfs filesystem df /
  • Show device IO error statistics:
root@host:~# btrfs dev stats /
  • Show disk infos (uuid, occuped space etc…):
root@host:~# btrfs filesystem show /


  • List snapshots in the root node:
root@host:~# btrfs subvolume list /
  • Create a snapshot of the root directory:
root@host:~# mkdir /.snapshots root@host:~# btrfs subvolume snapshot -r / /.snapshots/\@$(date +%Y.%m.%d)
  • Remove snapshot:
root@host:~# btrfs subvolume delete /.snapshots/@2024.05.04/


  • Modify /etc/fstab so that each new file will be automatically taken into account for compression:
UUID=4e39e49c-6934-41f5-97fd-cb7c699a78a5 / btrfs defaults,compress=zstd,subvol=@rootfs 0 0
  • Compress files inside specific folder:
root@host:~# btrfs filesystem defragment -r -v -czstd /home/user/


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address