Get Started With the Btrfs File System on Oracle Linux
Introduction
The Btrfs file system provides the capacity to handle pooling, snapshots, checksums, and multi-device spanning in existing Linux file systems. For an overview of the Btrfs file system and its features, see Oracle Linux 8: Managing Local File Systems .
This tutorial describes how to set up your Oracle Linux system to use the Btrfs file system. This tutorial is targeted at users of Oracle Linux 8 or later.
Objectives
Upon completion of this tutorial, you should be able to:
- Create a Btrfs file system on Oracle Linux 8
- Run basic Btrfs commands to perform tasks such as:
- Checking file system usage
- Extend the size of the file system
- Recover a missing device
- Test and see how the file system works
Prerequisites
Any Oracle Linux 8 system with the following configurations:
- has multiple storage devices installed
- runs the UEKR6 kernel
Check Installation of the Btrfs packages
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
Check whether the system contains the
btrfs-progs
package.dnf list installed | grep btrfs-progs
If the package is not in the system, install it and its dependent packages.
sudo dnf install -y btrfs-progs
Create the Btrfs file system
Check the devices that you would use for the file system.
lsblk
Your lab instance includes the following additional block volumes:
- /dev/sdb
- /dev/sdc
- /dev/sdd
- /dev/sde
Run the following command to create the Btrfs file system.
sudo mkfs.btrfs /dev/sdb /dev/sdc
In the output, the
Devices
section lists the two devices that you used to create the file system. By default, the command configures the file system with Raid 0 to stripe the data and Raid 1 to mirror the metadata.Create a directory on which to mount the file system.
sudo mkdir /data
Mount the file system.
sudo mount /dev/sdb /data
Verify the file system configuration.
sudo btrfs filesystem usage /data
Alternatively, you can also type:
sudo btrfs filesystem df /data
Make the file system mount automatically on reboot.
Get the Btrfs UUID.
sudo btrfs filesystem show
Note that
/dev/sdb
and/dev/sdc
have identical UIDs. You can further verify their identical UIDs with either of the following commands:lsblk -o NAME,UUID,MOUNTPOINT
sudo blkid -s UUID -o value <device-name>
wherecan be either /dev/sdb
or/dev/sdc
.
Add the following line to the
/etc/fstab
file:<UUID> /data btrfs defaults 0 0
Note: You can add the line by using the
tee
command as follows:echo "UUID=$(sudo blkid -s UUID -o value /dev/sdc) /data btrfs defaults 0 0" | sudo tee -a /etc/fstab
Test the new file system
Create a file in
/data
.sudo fallocate -l 5G /data/test1.img
Check the file system usage as a result of the new file.
sudo btrfs filesystem usage /data
Part of the output indicates that the file in
/data
is now striped across the two devices:Data,single: Size:5.01GiB, Used:5.00GiB (99.87%)
/dev/sdb 2.01Gib
/dev/sdc 3.00Gib
Extend the Btrfs file system
Add the
/dev/sdd
device to the file system.sudo btrfs device add /dev/sdd /data
View the new file system configuration.
sudo btrfs filesystem usage /data
The
Unallocated
section of the output includes the new device that you just added.Unallocated:
/dev/sdb 46.98GiB
/dev/sdc 45.99GiB
/dev/sdd 50.00GiB
Reconfigure
/data
to use the new file system configuration.While the file system itself has expanded,
/data
is still distributed based on the previous configuration. This step adjusts the directory to the new configuration.sudo btrfs balance start --bg /data
The
--bg
option causes the process to run in the background.To monitor the progress of the operation, issue one of the following commands:
Note: The balance operation might take about 7 minutes to complete. Do not proceed to the next step until monitoring indicates that the process has completed.
To check the progress at a point in time in the process, type:
sudo btrfs balance status /data
The output specifies the percentage of completion. If the operation has completed, then the command output would be
No balance found on /data.
To run continuous monitoring, type:
sudo watch -t -n5 btrfs balance status /data
The screen periodically displays the percentage of completion of the process, for example,
2 out of about 8 chunks balanced (3 considered), 75% left
.At the end of the process, the output reports
No balance found on /data.
Press Ctrl+C to exit real time monitoring.
Check the results of the balance process.
sudo btrfs filesystem usage /data
Part of the output indicates that
/data
is now striped across the three devices:Data,single: Size:11.00GiB, Used:10.00GiB (90.91%)
/dev/sdb 2.00Gib
/dev/sdc 1.00Gib
/dev/sdd 3.00Gib
Recover the file system after a device loss
To be able to complete the exercise in this section, a scenario is created where a device is lost due to a hardware failure.
Simulate a failure
Detach the
/dev/sdd
device with the following command:echo 1 | sudo tee /sys/block/sdd/device/delete
Check the status of the file system.
sudo btrfs filesystem show
The output reports some missing devices.
Determine which device is missing.
sudo btrfs filesystem usage /data
By comparing the command output with that of the previous
filesystem show
command, you can identify/dev/sdd
as the missing device.
Perform a recovery operation
Remount the file system in degraded mode.
sudo mount -o remount,rw,degraded /data
Replace the missing device.
sudo btrfs replace start -r 3 /dev/sde /data
You specify
-r 3
based on the original configuration that used 3 devices.Check the status of the replacement process.
sudo btrfs replace status /data
The command periodically displays the percentage of process completion, for example,
2.0 done, 0 write errs, 0 uncorr. read errs
.The process takes about 5 minutes to complete. At its completion, a notification similar to the following is displayed:
Started on 30.Sep 16:32:17, finished on 30.Sep 16:40:06, 0 write errs, 0 uncorr. read errs
Check the file system status.
sudo btrfs filesystem show
The list of devices now includes
/dev/sde
.Reconfigure
/data
to use the new file system configuration.sudo btrfs balance start --bg /data
To monitor the progress of the balancing operation, issue one of the following commands:
Note: The balance operation might take about 7 minutes to complete. Do not proceed to the next step until monitoring indicates that the process has completed.
To check the progress at a point in time in the process, type:
sudo btrfs balance status /data
The output specifies the percentage of completion. If the operation has completed, then the command output would be
No balance found on /data.
To run continuous monitoring, type:
sudo watch -t -n5 btrfs balance status /data
The screen periodically displays the percentage of completion of the process, for example,
2 out of about 8 chunks balanced (3 considered), 75% left
.At the end of the process, the output reports
No balance found on /data.
Press Ctrl+C to exit real time monitoring.
Check the results of the balance process.
sudo btrfs filesystem usage /data
The output shows that
/data
is now striped across/dev/sdb
,/dev/sdc
, and/dev/sde
.
Video Demonstration
The video tutorial Get Started with the Btrfs File System on Oracle Linux 8 demonstrates these lab exercise to configure Btrfs on your Oracle Linux system.
For more information
See other tutorials for further instructions on using Btrfs. Refer also to the Btrfs documentation in https://docs.oracle.com/en/operating-systems/oracle-linux/8/fsadmin/ .