Hello, and welcome to today's video on getting started with the Btrfs file system on Oracle
Linux 8.
This video aims to provide a quick introduction to Btrfs, create a new multi-device file system,
add a device to an existing file system, and replace a failed Btrfs device.
So let us get started.
Btrfs was initially designed at Oracle in 2007 by Chris Mason to address the lack of
pooling, snapshots, checksums, and integral multi-device spanning in existing Linux file
systems.
By November 2013, the Linux Kernel team declared Btrfs stable enough to include it in the kernel.
Btrfs remains under development today and provides the following features:
Copy-on-write data and metadata
Checksum functionality to ensure data integrity
Snapshots
Transparent compression to help save disk space
Online resizing and defragmentation
Efficient storage for small files
and
Integrated, logical volume management support to implement RAID 0, RAID 1, or RAID 10 configurations
and dynamically add or remove storage capacity.
For more information on these features, visit the Btrfs Wiki.
[ silence ... https://btrfs.wiki.kernel.org/index.php/Main_Page ]
With this general knowledge covered, time to create a new Btrfs file system.
Use a terminal and connect to our Oracle Linux 8 instance on Oracle Cloud Infrastructure.
Next, get a listing of all available block devices by typing `lsblk`.
This instance shows four unallocated devices, which we will use with Btrfs.
Before proceeding, it is essential to note that Btrfs requires the UEK R6 kernel.
To verify the instance is running the UEK R6 kernel, type `uname -a` and note the kernel
version.
Next, run `dnf repolist` and see that the ol8_UEKR6 repo is active.
Then run `dnf list kernel-uek` to see the version of the installed package.
The installed version should match the uname command's output and verifies we are running
with UEK R6.
For more information on UEK R6, see our video "Installing Unbreakable Enterprise Kernel
Release 6".
We also need to ensure the installation of the btrfs_progs package.
In our instance, these requirements were pre-installed.
If your system does not have them, use `dnf` to install them and any necessary dependencies.
To create the new file system, we need to run `mkfs.btrfs`.
The default configuration for this command for a file system with multiple devices is
to use:
`-d raid0` – Stripe the file system data across all devices.
`-m raid1` – Mirror the file system metadata across all devices.
These devices can be disk partitions, loopback devices, multipath devices, or LUNs that implement
RAID in hardware.
For this example, we use several Oracle Cloud Infrastructure block volumes attached to the
instance.
Create the file system by typing `sudo mkfs.btrfs /dev/sdb /dev/sdc`.
As we took the defaults, the output shows the data in a stripped RAID0 and the metadata
in a mirrored RAID1.
The Btrfs "RAID" implementation bears only a passing resemblance to traditional RAID
implementations as the data replicates on a per-chunk basis.
See more details on creating the file system or Btrfs RAID in the `mkfs.btrfs` manual page
or the Btrfs Wiki Sysadmin Guide.
[ silence ... https://btrfs.wiki.kernel.org/index.php/SysadminGuide ]
With the file system created, mount it so we can use it.
Create a mount point by typing `sudo mkdir /data`.
Then `sudo mount /dev/sdb /data`, where `/dev/sdb` is one of the devices containing the file
system.
As the file system is mounted, we can check its usage by typing `sudo btrfs filesystem
usage /data` or `sudo btrfs filesystem df /data`.
Now ensure the file system mounts after system reboot by adding an entry to `/etc/fstab`.
First, get the UUID from running `sudo btrfs filesystem show`.
Then add an entry to the /etc/fstab file as shown.
[ silence ... `UUID= /data btrfs defaults 0 0` ]
Now put the new file system to use.
Write a file by typing `sudo fallocate -l 10G /data/test1.img`.
Check that the data allocated across all the devices using `sudo btrfs filesystem usage
/data`.
If we need additional space for files, grow the storage by expanding the Btrfs file system
using the `/dev/sdd` device.
Type `sudo btrfs device add /dev/sdd /data`
Running `sudo btrfs filesystem usage /data` again now shows the storage size increased
by 50 GiB, which is the added `sdd` block device's size.
Although we added the `sdd` device to the file system, the data did not automatically
reallocate across all the devices.
The handling of data reallocation is a manual process and accomplished by running `sudo
btrfs balance start --bg /data`, where the `--bg` flag runs the task in the background.
After hitting enter, wait for the 10-second on-screen count down to complete, and the
data reallocation starts.
As the balancing of the data and metadata across all the disks may take a while to complete,
you can check the status with `sudo btrfs balance status /data`.
One way to check the status without retyping the command is by using the `watch` command.
Typing `sudo watch -t -n5 btrfs balance status /data`.
After the reallocation completes, rerun `sudo btrfs filesystem usage /data` to show all
the devices used and data allocated across each.
The last example today shows how to recover from a Btrfs device failure.
To simulate this behavior, remove the `sdd` block device from the instance by disconnecting
the block volume.
For details on managing block volumes, see the Oracle Cloud Infrastructure documentation.
[ silence ... see docs https://docs.oracle.com/en-us/iaas/Content/Block/Tasks/disconnectingfromavolume.htm ]
After removing the block volume, run `sudo btrfs filesystem show`.
The output indicates some devices are missing.
To determine which are missing, compare the output of the `btrfs filesystem show,` and
`usage` commands.
Start the recovery process by remounting the `/data` mount point in degraded mode with
`sudo mount -o remount,rw,degraded /data`.
Then, remove the failed device and replace it with a new one using `sudo btrfs replace
start -r 3 /dev/sde /data`.
Use the `-r` option and the `devid` of 3 since the source device is no longer available.
Next, run `sudo btrfs filesystem show` to display the `/dev/sde` device added as `devid
0` and `/dev/sdd` still missing.
The recovery task will take a while to complete.
Show the progress using the command `sudo btrfs replace status /data`.
Once complete, the output of `sudo btrfs filesystem show` no longer lists missing devices, and
`/dev/sde` is now listed as `devid 3`.
Lastly, rebalance the file system with `sudo btrfs balance start /data`.
The recovery is complete.
Again, verify the file system utilizes all devices by typing `sudo btrfs filesystem usage
/data` and examining the output.
That completes this introductory presentation on the Btrfs file system.
Thank you for watching, and enjoy using Oracle Linux 8.
Please check our additional information on Oracle Linux 8 in the Oracle Linux 8 Documentation
or Oracle Linux Learning Library.