Btrfs/ko

Btrfs is Article description::a copy-on-write (CoW) for Linux aimed at implementing advanced features while focusing on fault tolerance, self-healing properties, and easy administration. Jointly developed at Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO, and many others,  btrfs is licensed under the GPL and open for contribution from anyone.

기능
Ext4 is safe and stable and can handle large filesystems with extents, but why switch? While it is true that Btrfs is still considered experimental and is growing in stability, the time when Btrfs will become the default filesystem for Linux systems is getting closer. Some Linux distributions have already begun to switch to it with their current releases. Btrfs has a number of advanced features in common with ZFS, which is what made the ZFS filesystem popular with BSD distributions and NAS devices.


 * Copy on Write (CoW) and snapshotting - Make incremental backups painless even from a "hot" filesystem or virtual machine (VM).
 * File level checksums - Metadata for each file includes a checksum that is used to detect and repair errors.
 * Compression - Files may be compressed and decompressed on the fly, which speeds up read performance.
 * Auto defragmentation - The filesystems are tuned by a background thread while they are in use.
 * Subvolumes - Filesystems can share a single pool of space instead of being put into their own partitions.
 * RAID - Btrfs does its own RAID implementations so or  are not required in to have RAID. Currently RAID 0, 1 and 10 are supported; RAID 5 and 6 are considered unstable.
 * Partitions are optional - While Btrfs can work with partitions, it has the potential to use raw devices directly.
 * Data deduplication - There is limited data deduplication support; however, deduplication will eventually become a standard feature in Btrfs. This enables Btrfs to save space by comparing files via binary diffs.

Down the road, new clustered filesystems will readily take advantage of Btrfs with its copy on write and other advanced features for their object stores. is one example of a clustered filesystem that looks very promising, and can take advantage of Btrfs.

커널
btrfs 기능을 활용하려면 다음 커널 옵션을 활성화하십시오:

Emerge
The package contains the utilities necessary to work with the Btrfs filesystem. To install it:

사용법
Typing long Btrfs commands can quickly become a hassle. Each command (besides the initial command) can be reduced to a very short set of instructions. This method is helpful when working from the command line to reduce the amount of characters typed.

For example, to defragment a filesystem located at, the following shows the long command:

Shorten each of the longer commands after the command by reducing them to their unique, shortest prefix. In this context, unique means that no other commands will match the command at the command's shortest length. The shortened version of the above command is:

No other commands start with  ;   is the only one. The same goes for the  sub-command under the   command.

만들기
분할 영역에 btrfs 파일 시스템을 만들려면:

위 예제에서  대신 분할 영역 번호를,   대신 포맷한 디스크의 문자를 넣으십시오. 예를 들어 시스템의 첫번째 드라이브의 세번째 분할 영역을 포맷한다면 다음 명령을 실행합니다:

마운트
파일 시스템을 만들고 나면 다양한 방법으로 마운트할 수 있습니다:


 * - Manual mount.
 * - Defining mount points in enables automatic mounts on system boot.
 * - Automatic mounts on demand (useful for USB drives).
 * - Automatic mount on filesystem access.

ext* 기반 파일 시스템 변환
It is possible to convert ext2, ext3, and ext4 filesystems to Btrfs using the utility.

이 부분은 비 루트 파일 시스템의 변환만 설명합니다.

우선 마운트 지점의 마운트를 해제하십시오:

Check the integrity of the filesystem using the appropriate tool. In the next example, the filesystem is ext4:

Use to convert the ext* formatted device into a Btrfs-formatted device:

Be sure to edit after the device has been formatted to change the filesystem column from ext4 to Btrfs:

단편화 제거
btrfs의 다른 기능으로 가동중 단편화 제거 기능이 있습니다. btrfs 루트 파일 시스템의 단편화를 제거하려면 다음 명령을 실행하십시오:

The  mount option sets the default behavior to online defragmentation.

압축
btrfs에서는 zlib와 lzo 알고리즘으로 전송 단계 압축을 지원합니다.

파일 속성을 활용하여 특정 파일을 압축할 수 있습니다:

마운트 옵션은 새로 만든 모든 파일에 대해 기본적으로 압축동작이 동작하도록 설정합니다. 파일 시스템 전체를 다시 압축하려면 다음 명령을 실행하십시오:

Depending on the CPU and disk performance, using lzo compression could improve the overall throughput.

As alternatives to lzo it is possible to use the zlib or zstd compression algorithms. Zlib is slower but has a higher compression ratio, whereas zstd has a good ratio between the two.

To force zlib compression across the whole filesystem:

Substitute zstd for zlib in the example above to activate zstd compression.

Compression level
Since kernel version 4.15.0, zlib compression can now be set by levels 1-9. Since kernel version 5.1.0 zstd can be set to levels 1-15. For example, to set zlib to maximum compression at mount time:

Or to set minimal compression:

Or adjust compression by remounting:

The compression level should be visible in, or by checking the most recent output using the following command:

Adjust fstab for compression
Once a drive has been remounted or adjusted to compress data, be sure to add the appropriate modifications to the file. In this example, zstd compression is set with a level of 9 at mount time:

Compression ratio and disk usage
The usual userspace tools for determining used and free space like and  may provide inaccurate results on a Btrfs partition due to inherent design differences in the way files are written compared to, for example, ext2/3/4.

It is therefore advised to use the du/df alternatives provided by the btrfs userspace tool. In addition, the tool found in the sys-fs/compsize package can be helpful in providing additional information regarding compression ratios and the disk usage of compressed files. The following are example uses of these tools for a btrfs partition mounted under.

RAID
btrfs에서 RAID를 구성하는 방법은 으로 RAID를 구성하는 방법 만큼이나 쉽습니다.

Btrfs handles data and metadata separately. This is important to keep in mind when using a multi-device filesystem. It is possible to use separate profiles for data and metadata block groups. For example, metadata could be configured across multiple devices in RAID1, while data could be configured to RAID5. This profile is possible when using three or more block devices, since RAID5 requires a minimum of 3 block devices.

This type of profile offers the benefit of redundancy for metadata on each device and striping for data across devices, which increases read speeds. The drawback of this profile is more space than necessary is used for metadata, and write speeds are reduced for data blocks, since RAID5 uses a parity bit.

Creation
RAID를 만들 때 전체 장치를 활용할 간단한 방법은:

Conversion
Converting between RAID profiles is possible with the sub-command. For example, say three block devices are presently configured for RAID1 and mounted at. It is possible to convert the data in this profile from RAID1 to RAID5 with the following command:

Conversion can be performed while the filesystem is online and in use. Possible RAID modes in btrfs include RAID0, RAID1, RAID5, RAID6, and RAID10. See the upstream Btrfs wiki for more information.

Addition
Additional devices can be added to existing multi device file systems. Follow the removal section below.

A riskier, but faster, alternative to safely removing a device is to shut the system down (or if the system supports hot swappable drives, at least unmount the filesystem), physically disconnect and remove the device that is to be replaced, substituted and connect the new device in it's place, power up the system (if necessary).

Note: Systems that will be power cycled will have the multi device filesystem fail to mount, since a device has been physically removed from the pool.

Once the system is booted, mount the multi-device filesystem with, then perform the following steps on adding a new device.

After the device has been re-added it is then necessary to re-balance the filesystem to be sure data is spanned across the newly added device:

By device path
Block devices (disks) can be removed from multi-device filesystems using the subcommand:

By device ID
Use the usage subcommand to determine the device IDs:

Next use the device ID to remove the device. In this case will be removed:

Resizing
btrfs partitions can be resized while online using the built-in resize subcommand. For example, to add 50 gigabytes of space to the rootfs:

The command can also fill all available space:

하위 볼륨
As mentioned above in the features list, Btrfs can create subvolumes. Subvolumes can be used to better organize and manage data. They become especially powerful when combined with snapshots. Important distinctions must be made between Btrfs subvolumes and subvolumes created by Logical Volume Management. Btrfs subvolumes are not block level devices, they are POSIX file namespaces. They can be created at any location in the filesystem and will act like any other directory on the system with one difference: subvolumes can be mounted and unmounted. Subvolumes are nestable (subvolumes can be created inside other subvolumes), and easily created or removed.

만들기
To create a subvolume, issue the following command inside a Btrfs filesystem's name space:

Replace  with the desired destination and subvolume name. For example, if a Btrfs filesystem exists at, a subvolume could be created inside it using the following command:

목록
To see the subvolume(s) that have been created, use the  command followed by a Btrfs filesystem location. If the current directory is somewhere inside a Btrfs filesystem, the following command will display the subvolume(s) that exist on the filesystem:

If a Btrfs filesystem with subvolumes exists at the mount point created in the example command above, the output from the list command will look similar to the following:

제거
All available subvolume paths in a Btrfs filesystem can be seen using the list command above.

Subvolumes can be properly removed by using the  command, followed by the path to the subvolume:

As above, replace  with the actual path to the subvolume to be removed. To delete the subvolume used in the examples above, the following command would be issued:

스냅샷
Snapshots are subvolumes that share data and metadata with other subvolumes. This is made possible by Btrfs' Copy on Write (CoW) ability. Snapshots can be used for several purposes, one of which is to create backups of file system structures at specific points in time.

If the root filesystem is Btrfs, it is possible to create a snapshot using the  commands:

The following small shell script can be added to a timed cron job to create a timestamped snapshot backup of a Btrfs formatted root filesystem. The timestamps can be adjusted to whatever is preferred by the user.

Mounting
A subvolume can be mounted in a location different from where it was created, or users can choose to not mount them at all. For example, a user could create a Btrfs filesystem in and create  and  subvolumes. The subvolumes could then be mounted at and, with the original top level subvolume left unmounted. This results in a configuration where the subvolumes' relative path from the top level subvolume is different from their actual path.

To mount a subvolume, perform the following command, where  is the relative path of the subvolume from the top level subvolume, obtainable through the   command:

Similarly, the filesystem tab can be updated to mount a Btrfs subvolume:

Filesystem check
With a failing disk or corrupted data, it may be necessary to run the a filesystem check. Typically filesystem check commands are handled through the prefix, but for btrfs filesystems, checks are handled via the  subcommand:

Multi device filesystem mount fails
After ungracefully removing one or more devices from a multi device filesystem, attempting to mount the filesystem will fail:

This type of mount failure could be caused by missing one or more devices from the multi device filesystem. Missing devices can be detected by using the subcommand. In the following example is one of the devices still connected to the multi device filesystem:

Missing device can be ungracefully dropped from the filesystem by using the following command:

Using with VM disk images
When using Btrfs with virtual machine disk images, it is best to disable copy-on-write on the disk images in order to speed up IO performance. This can only be performed on files that are newly created. It also possible to disable CoW on all files created within a certain directory. For example, using the command:

여분 공간 캐시 삭제
btrfs의 여분 공간 캐시는 파일 시스템을 마운트할 때  마운트 옵션을 주어 비울 수 있습니다. 예를 들면:

btrfs의 메모리 점유(디스크 캐시)
btrfs 의 특별한 기능을 활용할 때(많은 양의   사본을 만들거나 상당한 양의 스냅샷을 만들 때), 상당한 양의 메모리를 차지할 수 있으며 커널의 아이노드 캐시로 바로 점유 영역을 해제할 수 없습니다. 이 문제는 기존 시스템 감시 유틸리티에서 디스크 캐싱에 관여하는 메모리 영역을 분명하게 볼 수 없어 확인할 수 없게 되는 경우가 있습니다. 커널 객체에서 메모리를 얼마나 차지하는지 확인하려고 ( 꾸러미에 있는) 유틸리티를 따로 만들었습니다:

If the inode cache is consuming too much memory, the kernel can be manually instructed to drop the cache by echoing an integer value to the file.

To be safe, and to help the kernel determine the maximum amount of freeable memory, be sure to run a before running the  commands below:

Most of the time Btrfs users will probably want to to reclaim just the slab objects (dentries and btrfs_inodes):

To clear the entire disk cache (slab objects and the page cache) use instead:

More information on kernel slabs can be found in this dedoimedo blog entry.

Mounting Btrfs fails, returning mount: unknown filesystem type 'btrfs'
The original solution by Tim on Stack Exchange inspired the following solution: build the kernel manually instead of using :

Btrfs root doesn't boot
Genkernel's initramfs as created with the command below doesn't load btrfs:

Compile support for btrfs in the kernel rather than as a module, or use to generate the initramfs.

External resources

 * https://wiki.debian.org/Btrfs - As described by the Debian wiki.
 * https://wiki.archlinux.org/index.php/Btrfs Btrfs article - As described by the Arch Linux wiki.
 * http://www.funtoo.org/BTRFS_Fun - BTRFS Fun on the Funtoo wiki.
 * http://marc.merlins.org/perso/btrfs/post_2014-05-04_Fixing-Btrfs-Filesystem-Full-Problems.html - Tips and tricks on fixing niche Btrfs filesystem problems in some situations.