BTRFS or EXT4: System Overview, Performance, Conversion

On Linux, everything is a file. The type of organization on Linux is a good foundation for improving OS security. Systems are mounted in a directory whose files form its contents. Such a directory is called a mount point. When the BTRFS and EXT4 file systems are mounted, their own mount point files will be detected by it. This remarkable feature of Linux allows you to quickly mount and uninstall various file systems, without the need for drivers. This gives users and developers the freedom to choose to process documents.

File System History

File System History




When writing the original Linux kernel, Linus Torvalds needed a new file system, but he didn’t want to write it and simply used Minix, written by Andrew S. Tanenbaum and part of the Unix-like Minix OS, written for educational purposes. Her code is still in the public domain and has the appropriate license.

Minix has structures, most of which are located in the section where the file system is generated - this is the boot sector in the first sector of the hard drive where it is installed. The boot block includes a boot record and a partition table.





The original EXT (Extended) file system was written by Rémy Card and was released with Linux in 1992 to overcome some Minix size restrictions. Major structural changes affected the metadata of Unix-based OS (UFS), also known as FFS. EXT had significant problems and was quickly replaced by EXT2 and then EXT3.

EXT4 latest modification




EXT4 is the latest modification of the original file system. It improves the performance, functionality and throughput of the OS. For security, metadata and log checksums have been added. Timestamps have been improved with the addition of intervals up to nanoseconds.

In 2014, significant changes took place - the two most important professional Linux distributions Red Hat and SUSE, said goodbye to the classic EXT file system and released new standards - BTRFS and XFS. B-tree is the next generation file system for Linux, pronounced Butter FS or B-tree FS. BTRFS has a number of features that make it an attractive solution for local disk storage. However, the final choice of BTRFS or EXT4 remains with the user.

File types

On Linux, everything is seen as a file, even devices such as printers and drives. Since all data, in fact, is a stream of bytes, each device can logically be considered as a file.





In order to make the right choice - BTRFS or EXT4, you need to understand the structure of the file system. All files in Unix can be divided into 3 types, namely:

  • Ordinary;
  • directories
  • devices.

The last two are not intuitively like files, so they are considered “special”. The first type listed above is a regular file, that is, without a "special purpose". It consists of data streams (bytes) stored on some physical device. Examples are simple text documents, applications containing high-level source code, executable text and binary files.

The second type is a special file called a directory. This type acts as a container for other categories called a subdirectory. They do not contain data in a custom sense, but only links to the files contained in them.

The third category mentioned above is the device. This is another special type that is used to describe a physical device, such as a printer or portable storage device. In this case, BTRFS or EXT4 will not contain any data, but simply display information received on the described device.

BTRFS: Storage Scaling

BTRFS is based on a B-tree copy when writing COW. According to Chris Mason, author of BTRFS, his goal was to allow Linux to scale for available storage. Scaling is not only access to the repository, but also the ability to administer and manage using a simple interface that allows users to see what is being used, making the process more reliable. Therefore, the choice of BTRFS or EXT4 has more advantages than the first standard.

BTRFS is also an extents-based storage system such as XFS. It saves space for small files and indexed directories and supports dynamic inode allocation. It handles multiple storage devices and provides support for RAID striping, mirroring, and shared striping and mirroring. It also has flash drive support with direct support for TRIM / reset operations.

The system supports compressed, writable, and accessible data for reading snapshots, as well as efficient incremental backups. Epitomes allow you to separate the internal roots of the file system, as well as the implementation of quotas and external deduplication. These features are very useful in embedded high availability systems.

BTRFS has minimal information stored in fixed locations. This is an advantage for EXT2 / 3/4 migration, since in-place conversion is possible provided there is sufficient free space. In addition, the standard is the storage base for Ceph, the cluster file system. For the user, these arguments are sufficient when choosing BTRFS and EXT4.

Extended system

Extended system




This multi-year standard is a family that includes EXT2, EXT3, and EXT4 and is still de facto widely used.

EXT2 was introduced in 1993 and supported Linux features such as symbolic links and long file names, processed volumes up to 32 TB and files up to 2 TB in size. The format is still used in many flash-based storage with FAT. It lacks the journal system inherent in the EXT3 and EXT4 standards. A multi-level hierarchy is used to host EXT2, which provides quick access to smaller files. Large files add a one- and two-level link before they become available.

EXT4 has a number of features, including file systems up to 1 byte in size and files up to 16 TB. Extents replace the traditional block mapping engine used with earlier relatives. Despite backward compatibility, EXT4 cannot be mounted as EXT3 if newer features, such as support for extents, are included.

EXT4 supports continuous pre-distribution - useful for applications such as streaming media where serial access performance is paramount. It also supports delayed distribution, one-piece distributor, quick validation, and logs for increased reliability.

Next Generation Format

BTRFS is the next-generation Linux standard for large files and systems from scratch, snapshots, simplified administration, integrated RAID, and volume management.

BTRFS has advantages over EXT4:

  1. Integrated data integrity - checksums and metadata.
  2. Detecting and repairing data corruption improves the overall reliability of the file system.
  3. Create lightweight copies and clones of files or entire directory structures with minimal additional disk space requirements. This feature is especially useful in combination with virtualization technologies, for example, for storing images of Linux virtual machines and containers.
  4. Quickly finds the latest file changes.
  5. Improves backup operations, instead of having to bypass the entire directory structure for files that have been changed, the file system can provide this information directly.
  6. Support for Discard and TRIM.
  7. Optimized support for solid-state (Flash) storage devices, allowing them to recover sectors from deleted files for future write operations.
  8. Snapshot integration with yum package management.
  9. Allows you to quickly roll back software and OS updates or quickly boot to an older patch level.
  10. Online defragmentation. It prevents fragmentation when many small files are created and deleted in quick succession, and thus the overall performance of the file system is improved by reducing the number of disk accesses.
  11. Cleaning with bug fixes. Detects and fixes file system corruption automatically.
  12. Online data compression. Increases storage capacity, and reduces the number of I / O operations.
  13. Integrated support for multiple devices. Allows spanning a single file system across multiple disks without a separate volume manager and provides RAID functionality for increased redundancy or performance.

Comparison: BTRFS vs EXT4

Comparison: BTRFS vs EXT4




Not so long ago, Linux users were still working with file systems that have changed little since Unix, such as EXT3. The standard uses block pointers, the index of each file in the central data structure, containing all the file information and a list of pointers to each individual block.

Standards Comparison




Later EXT4 standards use extents pointers. Each represents a group of adjacent blocks. Because they work with continuous storage of data based on extents, which significantly reduces the cost of managing file space.

BTRFS also uses extents, but they are significantly different from other Linux operating systems and are able to copy when writing COW. When data is overwritten in EXT4, new data is written over the existing data on the storage device, destroying the old copy. BTRFS moves the rewritten blocks to another location and writes new ones there, leaving the old copy in place.

Another important feature of BTRFS is its built-in manager. BTRFS can span multiple physical devices in a number of RAID configurations. Any volume - a set of one or more physical disks can also be divided into "ups", which are considered as independent systems that share one set of physical volumes. Thus, BTRFS allows you to group part or all of the storage into a large pool, and then divide this pool between a set of file systems, each of which has its own limitations.

BTRFS offers a wide range of other features not supported by other Linux file standards. It can perform full checksumming of both data and metadata, which makes it reliable against possible data corruption on equipment. A full checksum is expensive, so it will only be used in a small number of installations.

Data can be stored on disk in compressed form. The transmit / receive function is used as part of additional backup schemes. The online defragmentation mechanism fixes fragmented files in a running system. In kernel 3.12, the autonomous deduplication function has been added; it scans blocks containing duplicated data and collapses them into one common copy.

Although comparing EXT4 and BTRFS in favor of the latest standard, the great new BTRFS functionality is not free. In many cases, administrators may decide that the costs associated with BTRFS outweigh the benefits. As soon as it becomes generally accepted that BTRFS is ready for public use in the real world, it is likely that the standard will appear on many systems.

Choosing a Model for SSD

Choosing a Model for SSD




When setting up a new Linux installation with an SSD, many users do not know which file system to work with. This is understandable, because when users install Linux, often they choose the default settings.

SSD-BTRFS has many opponents. They say that it is unstable, and this seems to be true, since it is still in a difficult stage of development. However, this is actually a pretty solid file system for basic use, especially for solid state drives.

BTRFS does not keep a log, unlike other systems, saving valuable space for SSDs. It also supports TRIM, an important feature for SSD owners. TRIM allows you to erase unused blocks, which is extremely important to maintain the health of such a disk in Linux.

SSD-EXT4 is today the most used and reliable system in Linux. It is used in large data centers and in manufacturing, on all types of hard drives, including solid state drives.

File conversion

When booting from Live USBumount, you need to convert the EXT4 to BTRFS root section of the directory. Otherwise, the BTRFS-convert command cannot be executed when prompted: / dev / sda1 is mounted.

Execution algorithm:

  1. Go to Application> Ubuntu Software Center from the Edit menu> Software Sources.
  2. Check the entire list: Retry apt-get install BTRFS-tools. It is recommended that you use the updated version of BTRFS-tools. For example, get BTRFS-tools_0.19 + 20100601-3ubuntu3_amd64.deb and write: sudo dpkg -i BTRFS-tools v0.19 + 20100601-3ubuntu3 _amd64.deb
  3. Without this updated tool, you cannot remove snapshot from BTRFS.
  4. If it was possible to convert EXT4 to BTRFS and the BTRFS-convert function is executed, the following messages will be displayed.
File conversion




Next, change the UUID in the menu.lst file. With Grub Legacy, you need to change the root = UUID value in the menu.lst file for the BTRFS partition manually. To do this, use the following lines for the Grub s menu.lst file. Since scripts and hooks are added to initramfs, initrd, the images in the boot directory must be updated.

Disk partition conversion

Disk partition conversion




Before performing the root file system conversion, a full backup of the OS is preliminarily performed for a possible future recovery.

The process of converting EXT2, EXT3, or EXT4 to root BTRFS files:

  1. Run the mount command to determine the device that is mounted as the root and file system type.
  2. Use the ls -l command to determine that the mapped device matches / dev / vg hostol6 / lv_root, and the root file system matches the disk partition / dev / sda2.
  3. Turn off the PC.
  4. Download from the Oracle Linux, DVD, or ISO bootable CD.
  5. In the installation menu, select Rescue Installed System. When prompted, select the language and keyboard, the local CD / DVD as the installation media, and then “No” to bypass the launch of the network interface.
  6. Select “Skip” to bypass the choice of recovery environment.
  7. Select the Start shell to get a bash shell prompt (bash-4.1 #) at the bottom of the screen.
  8. If the existing root system is configured as an LVM volume, use the following command to start the volume group: vg_hostol6.
  9. They start the correct version of fsck, for example, fsck.ext3 or fsck. ext4 to check and fix system integrity.
  10. Convert system to BTRFS.
  11. Create a mount point (/ mnt 1) for the transformed root system.
  12. Use the command to edit the / mnt1 / etc / fstab file and change the root type of the BTRFS system.
  13. Create a .autorelabel file in the root of the mounted system.
  14. The presence of a .autorelabel file tells SE Linux to recreate the security attributes for all files in the system.
  15. Unmount the transformed root system.
  16. Remove the bootable CD, DVD, or ISO and reboot the system.

Synology: SSD Optimization

Synology: SSD Optimization




BTRFS has recently appeared on syno, and is already considered a stable solution and is offered as a standard in most distributions. When choosing a file system for SSDs, BTRFS and EXT4 are based on the following arguments.

BTRFS is a multi-root file system built into the Linux kernel in 2013 and declared stable. It can store 16 million TB in volume (16 Eo) and provides many features:

  1. Automatically detect and optimize SSDs. Diskless drives benefit from certain optimizations and this is a development issue. SF is initially considered, especially in EXT4, if you need to disable certain options during editing, such as the time a file was written.
  2. Linear RAID is useful when the user has various and diverse storage media that need to be combined for processing, such as NAS, adding an NFS server. This is not possible with a RAID card, with MDADM, or with LVM. BTRFS JBOD offers more chances to save data, especially with a small number of drives, so the choice of the standard for Synology - BTRFS and EXT4, remains with the first type.
  3. After the initial full read-only backup, BTRFS can perform incremental backups with rotation, for example, store one backup per day, then one per month, then one per year. Transferring snapshots is also gradual, easier and faster than using rsync, because the system can distinguish between file deletion and simple tree renaming.

BTRFS is the next-generation Linux file system and changes user preferences for choices. , .




All Articles