BTRFS (B-tree,butter fs,better FS), announced by Oracle in 2007 and in progress in the Cow (copy-on-write) file system. Btrfs appears because its developers initially wanted to extend the functionality of the filesystem so that it included snapshots, pooled pooling, checksums, and other features. Although unrelated to EXT4, it also wants to preserve the features that benefit consumers and businesses in Ext4, and to integrate additional features that will benefit everyone, especially the business. For businesses using large software and large-scale databases, a file system that looks consistent across multiple hard drives can benefit them and make data consolidation easier. Removing duplicate data can reduce the amount of space your data actually uses, and using Btrfs to mirror a single, huge file system can make data mirroring simple.
Core Features:
1. Multi-physical volume support, support raid, to online "add", "Remove", "modify", is very convenient; Raid section please refer to http://blog.51cto.com/marvin89/2106891
2. About data consistency related features, Btrfs support data and metadata check code, do checksum, to avoid the emergence of silent corrupt. Traditional file systems cannot do this. Btrfs writes the replication update mechanism (COW) to ensure file system consistency.
3.Btrfs supports the creation of extremely convenient snapshots and clones. Btrfs can also easily manage multiple physical devices, making traditional volume management software redundant.
4. Transparent compression, directory index, delay allocation, save hard disk storage space, improve search efficiency.
Specific implementation
1, prepare 4 partitions, preferably 4 disk, where the experiment is convenient to implement on a disk (raid on different disks to achieve meaningful)
/dev/sdc1 2048 20971519 10484736 5 Extended/dev/sdc5 4096 2101247 1048576 83 Linux/dev/sdc6 2103296 4200447 1048576 83 Linux/dev/sdc7 4202496 6299647 1048576 83 Linux
2.1. Create Btrfs File system
[[email protected] ~]# mkfs.btrfs -L mydata -f /dev/sdb{5,6,7,8}btrfs-progs v4.9.1See http://btrfs.wiki.kernel.org for more information.Label: mydataUUID: 54161207-74c5-4851-b945-70c510a914c1Node size: 16384Sector size: 4096Filesystem size: 4.00GiBBlock group profiles: Data: RAID0 409.50MiB Metadata: RAID1 204.75MiB System: RAID1 8.00MiBSSD detected: noIncompat features: extref, skinny-metadataNumber of devices: 4Devices: ID SIZE PATH 1 1.00GiB /dev/sdb5 2 1.00GiB /dev/sdb6 3 1.00GiB /dev/sdb7 4 1.00GiB /dev/sdb8
2.2 Mounting
[[email protected] ~]# mount -U 54161207-74c5-4851-b945-70c510a914c1 /mnt/t1[ro[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 4.0G 17M 3.6G 1% /mnt/t1#等同于mount /dev/sdb5 /mnt/t1
2.3 Specifies that the data metadata is created with RAID1
[[email protected] ~]# umount/mnt/t1[[email protected] ~]# mkfs.btrfs-l mydata-d raid1-m raid1-f/dev/sdb{5 , 6,7,8}btrfs-progs V4.9.1see http://btrfs.wiki.kernel.org for more information. Label:mydatauuid:6a2fe147-c2e3-4c98-b6cb-be6da13886c2node size:16384sector Size: 4096Filesystem size:4.00gibblock Group profiles:Data:RAID1 204.75MiB Metadata: RAID1 204.75MiB system:raid1 8.00MiBSSD detected:noincompat features:extref, SK Inny-metadatanumber of Devices:4devices:id SIZE PATH 1 1.00gib/dev/sdb5 2 1.00GIB/DEV/SDB6 3 1.00GIB/DEV/SDB7 4 1.00gib/dev/sdb8[[email protected] ~]# mount/dev/sdb5/mnt/t1 [[email  ;p rotected] ~]# df-h file system capacity used available% mount point/dev/sdb5 2.0G 17M 1.8G 1%/mnt/t1 #由此可见数据有raid0到raid1 Half Used to do backup meta data is 204.75MB writable part 1.8g[[email protected] ~]# btrfs filEsystem Df/mnt/t1data, Raid1:total=204.75mib, Used=128.00kibsystem, Raid1:total=8.00mib, Used=16.00KiBMetadata, Raid1:total=204.75mib, Used=112.00kibglobalreserve, Single:total=16.00mib, used=0.00b
3, write the data on the basis of RAID1
[[email protected] ~]# dd if=/dev/zero of=/mnt/t1/a bs=1024 count=1048576[[email protected] ~]# dd if=/dev/zero of=/mnt/t1/b bs=1024 count=1048576[[email protected] t1]# ll -htotal 1.8G-rw-r--r--. 1 root root 1.0G Apr 24 09:04 a-rw-r--r--. 1 root root 810M Apr 24 09:06 b[[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 2.0G 1.9G 64K 100% /mnt/t1[[email protected] ~]# btrfs filesystem df /mnt/t1 #btrfs的df用来观察当时 文件系统的存储情况Data, RAID1: total=1.79GiB, used=1.79GiB #数据部分System, RAID1: total=8.00MiB, used=16.00KiBMetadata, RAID1: total=204.75MiB, used=2.00MiB #在创建玩文件系统后元数据是固定的GlobalReserve, single: total=16.00MiB, used=0.00B
4. Modify the RAID mode in the online state
[[email protected] t1]# rm -f {a,b}[[email protected] ~]# btrfs balance start -dconvert=raid0 -mconvert=raid1 /mnt/t1Done, had to relocate 4 out of 4 chunks
5.1. Removal of equipment
[[email protected] ~]# btrfs device delete /dev/sdb8 /mnt/t1 #参考 man btrfs-device remove 是remove的别名 会自动移除数据 The operation can take long as it needs to move all data from the device.[[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 3.0G 418M 1.8G 19% /mnt/t1
5.2. Adding equipment
[[email protected] ~]# btrfs device add /dev/sdb8 /mnt/t1[[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 4.0G 418M 2.9G 13% /mnt/t1
6.1. Reduction
[[email protected] ~]# btrfs filesystem resize -700M /mnt/t1Resize ‘/mnt/t1‘ of ‘-700M‘[[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 3.4G 418M 2.1G 17% /mnt/t1
6.2 Extended to Maximum
[[email protected] ~]# btrfs filesystem resize max /mnt/t1Resize ‘/mnt/t1‘ of ‘max‘[[email protected] ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/sdb5 4.0G 418M 3.1G 12% /mnt/t1
7, reduction or equipment after the move to do the data even
[[email protected] ~]# btrfs balance start /mnt/t1
Sub-volume and snapshot
1. Create a sub-volume
[[email protected] ~]# btrfs subvolume create /mnt/t1/logsCreate subvolume ‘/mnt/t1/logs‘[[email protected]host ~]# btrfs subvolume list /mnt/t1ID 281 gen 196 top level 5 path logs
2, the child volume by default is followed by the parent volume, can also be mounted separately | A sub-volume is not typically mounted separately, and a snapshot volume can be used under a parent volume
[[email protected] ~]# umount /mnt/t1[[email protected] ~]# mount -o subvol=logs /dev/sdb5 /mnt/t1 #mount -o subvolid=281 /dev/sdb5 /mnt/t1 [[email protected] ~]# touch /mnt/t1/a[[email protected] ~]# btrfs subvolume show /mnt/t1//mnt/t1 Name: logs UUID: 7bb3b73f-931c-5a4b-811d-e0290075c534 Parent UUID: - Received UUID: - Creation time: 2018-04-24 10:06:45 -0400 Subvolume ID: 281 Generation: 196 Gen at creation: 196 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):[[email protected] ~]# umount /mnt/t1[[email protected] ~]# mount /dev/sdb5 /mnt/t1[[email protected] ~]# cat /mnt/t1/logs/abc #子卷中的文件依然存在
3. Create a Snapshot
#现在logs下面创建一个标记文件[[email protected] logs]# touch a[[email protected] logs]# echo aa > a#快照 还是要注意大小,快照是记录源文件变化量, 源文件跟快照都在同一个文件系统中[[email protected] logs]# btrfs subvolume snapshot /mnt/t1/logs/ /mnt/t1/logs_snapshotCreate a snapshot of ‘/mnt/t1/logs/‘ in ‘/mnt/t1/logs_snapshot‘
#快照验证
[[email protected] logs]# tail -1 ../logs_snapshot/aaa[[email protected] logs]# echo bb >> a[[email protected] logs]# tail -1 ../logs_snapshot/aaa[[email protected] logs]# touch b[[email protected] logs]# ls ../logs_snapshot/a
4. Deleting snapshots
[[email protected] logs]# btrfs subvolume delete /mnt/t1/logs_snapshot/Delete subvolume (no-commit): ‘/mnt/t1/logs_snapshot‘
5. Realistic copy function (single file snapshot)
#https://bugs.centos.org/view.php?id=14228 目前bug[[email protected] logs]# cp --reflink=auto fstab fstab.bak[[email protected] logs]# echo 888 >> fstab[[email protected] logs]# tail -1 fstab.bakUUID=943c7e04-b733-42fe-a1e2-eabf93693f6b swap swap defaults 0 0#通过写时复制完成
6. Delete a sub-volume
[[email protected] ~]# btrfs subvolume delete /mnt/t1/logs/Delete subvolume (no-commit): ‘/mnt/t1/logs‘
Btrfs of the Linux file system