How to install and format a partition with Btrfs on Ubuntu?

How to install and format a partition with the Btrfs on Ubuntu?

Btrfs on Ubuntu gives you snapshots, checksums and transparent compression from a filesystem that already lives inside the Linux kernel. Ubuntu’s desktop installer still offers ext4 as its default, so you add btrfs yourself with the btrfs-progs package.

This guide formats a spare disk and mounts it. Then it goes further with subvolumes, zstd compression, scrubs and RAID1. The commands target Ubuntu 24.04 LTS and 26.04 LTS.

Installing the Btrfs on Ubuntu

Btrfs file system is easily available in the apt package manager.

Before installing, update your apt package manager index by executing the following apt command with sudo:

sudo apt update

Now, to install the Btrfs filesystem, execute the following apt command with sudo:

sudo apt install btrfs-progs

Once we have installed the package, we can proceed further to set up the Btrfs file system on our device.

The device we have used on our system for the Btrfs filesystem is /dev/sdb

Check the installed btrfs version

The kernel carries the filesystem code, while btrfs-progs is the set of userspace tools (mkfs.btrfs, btrfs and friends). Check which build apt gave you:

btrfs --version

Ubuntu 24.04 LTS ships btrfs-progs 6.6.3 with kernel 6.8. Ubuntu 26.04 LTS, released on April 23 2026, ships btrfs-progs 6.17.1 with kernel 7.0. Both support every command in this guide.

The package version mostly decides which mkfs defaults you get. Free space tree and no-holes became defaults in progs 5.15, and 4KiB became the default sector size in progs 6.7. The current btrfs documentation lives at btrfs.readthedocs.io, which replaced the old kernel.org wiki.

Partitioning with the help of cfdisk partition editor

Before creating a filesystem on our device, we need to first create the partition(s). For this purpose, we can make use of the popular Linux partition editor called cfdisk.

Execute cfdisk partition editor for the device /dev/sdb by executing:

sudo cfdisk /dev/sdb
The cfdisk label type prompt opened with sudo cfdisk /dev/sdb on a blank disk
sudo cfdisk /dev/sdb

You might wanna use gpt if you are on a UEFI system. But, for this tutorial, we’ll proceed with dos. Use the down arrow to select dos and press Enter to choose it.

cfdisk showing free space and no partitions on the disk
No partitions

In the above picture, you can see we have no partitions at the moment on this device. So, we have to create a new partition.

Select [ New ] with arrow keys and press Enter.

cfdisk asking for the size of the new partition
Creating a new partition

As you can see in the above picture, we are creating a partition of 10G (that is 10 GB, similarly for M for MB, & T for TB). We are using all the available space on our device, but you can choose as per your needs.

cfdisk asking whether the new partition is primary or extended
Choose primary

Now choose primary, and hit Enter.

The Write option highlighted in the cfdisk menu
Select write to write changes to device

Now type yes to confirm, write changes to the device.

cfdisk asking to type yes before writing the partition table
Type yes to confirm write changes
cfdisk after the write, with the Quit option highlighted
Now you can quit cfdisk

Now you can quit cfdisk. You can list the partition using the lsblk command with sudo:

sudo lsblk
Terminal output of sudo lsblk listing the new sdb1 partition
sudo lsblk output

Now that we have a partition created, we can now proceed to create the Btrfs filesystem on the partition.

Creating Btrfs filesystem on a partition

We can make a filesystem on our partition using the mkfs.btrfs command.

To create a Btrfs filesystem on our partition execute the following command and replace your partition with /dev/sdb1:

sudo mkfs.btrfs -L btrfs /dev/sdb1

The -L option is used to specify the volume label.

Terminal output of mkfs.btrfs reporting the new filesystem on /dev/sdb1
btrfs filesystem created

As you can see in the above image, we have successfully created a Btrfs filesystem on our partition.

What mkfs.btrfs picks by default

On a single device, mkfs.btrfs stores metadata twice (the DUP profile) and data once. A bad metadata sector can be repaired from the second copy. A bad data block is only detected.

So “self-healing” needs a second copy of the data, which means a multi-device profile such as RAID1.

Find the filesystem UUID

Every filesystem gets a UUID (an ID that stays the same when device names like /dev/sdb change). List it with lsblk -f, covered in more detail in the lsblk and blkid guide:

sudo lsblk -f /dev/sdb

The FSTYPE column should read btrfs and the LABEL column should show the label you passed with -L. Copy the UUID column, since the fstab entry later in this guide needs it.

Mounting a Btrfs partition

To mount a Btrfs partition, create an empty directory preferably in / using the mkdir command with sudo:

sudo mkdir /btrfs

We will use the mount command with sudo to mount our Btrfs partition.

sudo mount /dev/sdb1 /btrfs

You can verify it by executing the following df command:

df -h
Terminal output of df -h showing /dev/sdb1 mounted on /btrfs
Btrfs Partition Mounted

Mount options for everyday use

Two options are worth setting on most machines. The first is noatime, which stops the kernel from writing a timestamp on every read. The second is compress=zstd:3, which compresses data as it is written.

sudo umount /btrfs
sudo mount -o noatime,compress=zstd:3 /dev/sdb1 /btrfs

Since Linux 6.2, asynchronous discard is on by default for disks that support it. So you rarely need to add a discard option for an SSD by hand.

Make the mount permanent with fstab

A manual mount disappears at reboot. Add a line to /etc/fstab (the file that lists filesystems to mount at boot) with your own UUID from lsblk -f:

UUID=replace-with-your-uuid  /btrfs  btrfs  noatime,compress=zstd:3  0  0

The last two numbers are the dump flag and the fsck order. Btrfs has no boot-time fsck, so the order stays 0. Test the entry before rebooting. A typo here can drop you into emergency mode. For one-off drives, the mount guide for USB drives covers the same command:

sudo mount -a

Read real usage with btrfs filesystem usage

Btrfs allocates space in chunks per profile, so df often disagrees with reality, especially on RAID1 or with snapshots. Ask btrfs directly:

sudo btrfs filesystem usage /btrfs

Look at the Unallocated line first. When it nears zero, run a balance (covered below) before the disk reports full while df still shows free space.

Btrfs subvolumes and snapshots on Ubuntu

A subvolume is a separate file tree inside the same filesystem, and it is the unit that snapshots work on. Timeshift expects the names @ and @home for a btrfs root, so many Ubuntu setups copy that naming.

Create a subvolume

The create command makes a new subvolume at the path you give it. List them to confirm:

sudo btrfs subvolume create /btrfs/@data
sudo btrfs subvolume list /btrfs

Take a read-only snapshot

A snapshot shares every block with its source, so it starts at almost zero size and only grows as the two diverge. That is copy-on-write (CoW) at work. The -r flag makes it read-only:

sudo btrfs subvolume snapshot -r /btrfs/@data /btrfs/@data-2026-10-26

Roll back or delete a snapshot

To roll back, snapshot the read-only copy into a new writable subvolume. To free space, delete the old snapshot:

sudo btrfs subvolume snapshot /btrfs/@data-2026-10-26 /btrfs/@data-restored
sudo btrfs subvolume delete /btrfs/@data-2026-10-26

A snapshot on the same disk is not a backup. To copy one to another btrfs disk, pipe btrfs send into btrfs receive. Send only accepts read-only snapshots:

sudo btrfs send /btrfs/@data-2026-10-26 | sudo btrfs receive /mnt/backup

Enable btrfs compression with zstd

Btrfs supports zlib, lzo and zstd. Zstd accepts levels 1 to 15 and level 3 is the default. Low levels cost little CPU and often shrink text, logs and source trees well. Set it at mount time, as shown earlier.

Compression only applies to data written after you turn it on. To recompress existing files, run defragment with the -czstd flag:

sudo btrfs filesystem defragment -r -v -czstd /btrfs/@data

Defragmenting breaks block sharing with existing snapshots, so used space can jump. Skip this step on subvolumes that have many snapshots. Already compressed files such as video and JPEG gain nothing, and btrfs detects that and stops trying.

Scrub and balance a btrfs filesystem

A scrub reads all data and metadata and checks every checksum. On RAID1 it repairs a bad copy from the good one. On a single-device filesystem it can only report the damage. Run it on a schedule:

sudo btrfs scrub start /btrfs
sudo btrfs scrub status /btrfs

A balance rewrites chunks to reclaim allocated but mostly empty space. The usage filter limits it to chunks that are at most half full, which keeps the run short:

sudo btrfs balance start -dusage=50 /btrfs

Set up btrfs RAID1 on Ubuntu

Btrfs builds RAID inside the filesystem, so you need no mdadm layer. The next command erases both disks. Check the names with lsblk first. It mirrors both data (-d) and metadata (-m) across /dev/sdb and /dev/sdc:

sudo mkfs.btrfs -L pool -d raid1 -m raid1 /dev/sdb /dev/sdc

To grow an existing single-disk filesystem into RAID1, add a device and convert the profiles with a balance:

sudo btrfs device add /dev/sdc /btrfs
sudo btrfs balance start -dconvert=raid1 -mconvert=raid1 /btrfs

RAID10 and raid1c3 (three copies) exist too. RAID5 and RAID6 still carry a write hole warning in the btrfs documentation, so avoid them for data you care about.

Use btrfs as the root filesystem on Ubuntu

Ubuntu’s desktop installer does not offer btrfs as a root choice by default. People usually install a layout by hand from a live session, with subvolumes @ for / and @home for /home. The fstab then selects them with the subvol option:

UUID=replace-with-your-uuid  /      btrfs  noatime,subvol=@      0  0
UUID=replace-with-your-uuid  /home  btrfs  noatime,subvol=@home  0  0

Once root is on btrfs, automatic snapshots before upgrades are the main payoff. Snapper (sudo apt install snapper) manages snapshot timelines, and btrfs-assistant gives it a GUI. The Timeshift backup guide covers its btrfs mode.

Swap files and repair rules on btrfs

Since btrfs-progs 6.1, a dedicated command makes a swap file with the right attributes. The swap file must live on a single-device filesystem and cannot be compressed. A subvolume with an active swap file cannot be snapshotted. For sizing, see the swap file guide.

sudo btrfs filesystem mkswapfile --size 4g /btrfs/swapfile
sudo swapon /btrfs/swapfile

For repairs, run btrfs check only on an unmounted filesystem. It is read-only unless you add –repair, and the documentation treats –repair as a last resort after a backup.

Btrfs vs ext4 on Ubuntu

Ext4 is simpler and is what the installer picks. Btrfs adds checksums, snapshots and compression at the cost of more tuning, such as scrubs and balances. The ext4 vs btrfs comparison covers the trade-offs. For background on filesystem layers, read the partitions and filesystems primer. Ubuntu also supports OpenZFS as another option.

Key Takeaways

  • Install btrfs-progs with apt on Ubuntu 24.04 or 26.04.
  • Ubuntu’s desktop installer defaults to ext4.
  • Format with mkfs.btrfs and always check the device name first.
  • Mount by UUID in fstab with a 0 0 tail.
  • Use read-only snapshots and send/receive for backups.
  • Set compress=zstd:3 and noatime for daily use.
  • Scrub regularly and balance when unallocated space runs low.
  • Use RAID1 or RAID10 and skip RAID5 and RAID6.

Frequently asked questions

Does Ubuntu support btrfs?

Yes. The kernel includes btrfs and btrfs-progs installs from apt on Ubuntu 24.04 and 26.04. The desktop installer defaults to ext4, so add btrfs on extra disks.

How do I format a disk as btrfs on Ubuntu?

Install btrfs-progs, partition the disk with cfdisk, then run sudo mkfs.btrfs -L label /dev/sdb1. The command erases the partition, so confirm the device name with lsblk first.

How do I mount a btrfs partition at boot?

Find the UUID with lsblk -f, add a line with the UUID, mount point, btrfs, options and 0 0 to /etc/fstab, then test it with sudo mount -a.

How do I check free space on a btrfs volume?

Run sudo btrfs filesystem usage on the mount point. It reports allocated and unallocated space per profile, which df often misreports on RAID1 or when snapshots exist.

Is btrfs RAID5 or RAID6 safe on Ubuntu?

Not for data you care about. The btrfs documentation still flags RAID5 and RAID6 as unstable because of the write hole, so use RAID1 or RAID10 instead.

Does btrfs repair corrupted files on its own?

Only with a second copy. Checksums detect bad data on any btrfs disk, and a scrub repairs it from the good copy on RAID1. A single disk keeps one data copy.

Conclusion

Using btrfs on Ubuntu takes four steps: install btrfs-progs, partition the disk, run mkfs.btrfs and mount it with a UUID entry in fstab. Add zstd compression and read-only snapshots for daily value, scrub on a schedule, and avoid RAID5 and RAID6. Keep backups on a separate disk and test restores.