Btrfs or commonly pronounced as b-tree FS or butter FS is a COW (copy-on-write) based disk storage format and filesystem. In btrfs, all characters except / and Null are applicable for creating the files featuring self-healing and the capability of spanning multiple volumes. It was initially developed by Oracle in 2007 and developed by multiple companies such as Redhat, Linux Foundation, Facebook, suse, etc.
Many features like sub volume file-system, extended base file-system, mks skinny-metadata, ability to link lost files to lost and found, etc. make it a powerful file system compared to others. In this article, I will show you how to create a disk partition and format it with Btrfs file system on Ubuntu 20.04 LTS.
Btrfs File System Installation and Creation
Most of the latest Linux distro provides it pre-installed, if not you can install it using the following command.
$ sudo apt update
$ sudo apt-get install btrfs-tools -y
Now, using the command below enable the kernel module for btrfs
$ modprobe btrfs
Before getting into the process let’s verify the new disk attached to the system using the command given below.
$ sudo fdisk -l
Viewing the newly added disk.
Now, if new disk allocation is confirmed, execute the fdisk command with the newly added disk to continue with the disk partition process.
$ sudo fdisk /dev/sdb
During creating the partition you need to know the following command option what they actually do that is used in the process.
- Command ‘n’ : Create a new partition.
- Command ‘t’ : To change the partition type.
- Command ‘p’ : To print the partition table.
- Command ‘l’ : To list all the known partition types.
- Command ‘w’ : Write the table to disk and quit.
- Command ‘q’ : quit without saving the changes.
Creating the disk partition.
After executing the command you will be requested to enter the command to perform the task. So enter ‘n’ to create a new partition then you will be provided a list of partition types and choose them according to your requirement. Once the partition type is selected, provide the no of the partition you want to create (default 1) then hit double enter to continue with the default. Next, enter ‘t’ to change partition type then, type 8e and hit enter. Hit the ‘p’ command to confirm the partition then lastly hit ‘w’ to write the changes and quit.
Next, add the disk information to the kernel using the following command and then check again partition list
$ sudo partprobe /dev/sdb
$ sudo ls -l /dev | grep sd
Viewing newly created disk partitions.
Setup a Logical Volume
Now, use vgcreate and pvcreate to create the volume group and physical volume respectively on the /dev/sdb1 disk.
$ sudo pvcreate /dev/sdb1
$ sudo vgcreate sdb_vg /dev/sdb1
Physical volume and Group volume generation.
Then, use the volume group to create the Logical volume.
$ lvcreate -L +2G -n volume1 sdb_vg
$ lvcreate -L +2G -n volume2 sdb_vg
You can view all the created volumes and groups in the following way.
Viewing all created volumes and volume groups.
Create Btrfs Filesystem
Till now we have created partitions then set up logical and finally we will create the file system for the logical volumes we set up earlier.
$ mkfs.btrfs /dev/sdb_vg/volume1
Creating the file system for logical volume.
Then, make dir inside /mnt that holds our mounted file-system and mount the file-system.
$ sudo mkdir /mnt/sdb_btrfs1
$ sudo mount /dev/sdb_vg/volume1 /mnt/sdb_btrfs1/
Finally, use the df command to verify the mount point.
$ df -h
Verifying after creating the file system.
Btrfs has become popular and powerful due to its advanced features like snapshot, rollback, and many more. In the upcoming days, this may lead to a default file system in the upcoming Linux distro. Hope you could gather some knowledge and mindset on how we can format the new disk to the btrfs file system.