Btrfs (usually read as butter FS), announced by Oracle in 2007 and in progress in the Cow (copy-on-write) file system. The goal is to replace Linux's current Ext3 file system to improve ext3 limitations, especially single file size limits, total file system size limits, and the addition of file checksum features.
Characteristics:
The first is extensibility (scalability)-related features, and Btrfs's most important design goal is to address the scalability requirements of large machines for file systems. Features such as extent,b-tree and dynamic inode creation ensure that Btrfs still has excellent performance on large machines, with overall performance not decreasing as the system capacity increases.
Next is the data integrity-related feature. The system is confronted with unpredictable hardware failures, and Btrfs uses COW transaction technology to ensure file system consistency. Btrfs also supports checksum and avoids the emergence of silent corrupt. Traditional file systems cannot do this.
The third is the features associated with multi-device management. Btrfs supports the creation of snapshots (snapshot), and Clone (clone) sub-volumes (sub_volume) for transparent compression. Btrfs can also easily manage multiple physical devices, making traditional volume management software redundant.
Finally, other features that are difficult to categorize. These features are more advanced technologies that can significantly improve the time/space performance of file systems, including delay allocation, storage optimization of small files, directory indexing, and more.
Extensibility-related features
B-tree
All metadata in the Btrfs file system are managed by B-tree. The main benefit of using B-tree is that it is efficient to find, insert, and delete operations. It can be said that B-tree is the core of Btrfs.
Blindly boast that B-tree is very good and efficient may not be convincing, but if a little bit of time to see the EXT2/3 metadata management implementation, you can contrast the advantages of b-tree. (The previous blog file system explained in detail the EXT series of file systems).
Extent-based file storage
Many modern file systems use extent instead of block to manage disks. Extent is a contiguous block, and a Extent is defined by the starting block plus the length, which can effectively reduce the metadata overhead.
Centos7 default support for Btrfs file system
Create 3 partitions with the FDISK command
[[email protected] ~]# fdisk -l disk /dev/sda:128.8 GB, 128849018880 bytes, 251658240 sector units = Sector of 1 * 512 = 512 bytes sector size (logical/physical) :512 bytes / 512 bytes i/o size (min/Best):512 bytes / 512 BYTE disk label type: DOS disk identifier:0x00065fe7 device Boot Start End Blocks id system/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 46194687 22584320 8e linux lvm/dev/sda3 46194688 251658239 102731776 5 extended/dev/sda5 46196736 67168255 10485760 83 Linux/dev/sda6 67170304 88141823 10485760 83 Linux/dev/sda7 88143872 109115391 10485760 83 linux
Mkfs.btrfs creating parameters for Btrfs file system
-L Specify Volume label
-M indicates how the metadata is stored (RAID0 raid1 raid ...)
-D type (raid0 raid1 RAID5 raid6 raid10) for specifying data to be stored across multiple devices
-O format Startup features
-O List-all list supports all feature;
[[email protected] ~]# mkfs.btrfs -l mydata /dev/sda5 /dev/sda6 #创建btrfs文件系统Btrfs v3.16.2see http:// Btrfs.wiki.kernel.org for more information. [[email protected] ~]# btrfs filesystem show #查看btrfs文件属性, whether to create label: ' MyData ' uuid: 4483a0bc-7fa1-4691-b976-a1a98ebf448cTotal devices 2 FS Bytes used 112.00kibdevid 1 size 10.00gib used 2.03gib path /dev/sda5devid 2 size 10.00GiB used 2.01GiB Path /dev/sda6
[Email protected] ~]# blkid/dev/sda5 #显示的子卷uuid和物理uuid是不同的/dev/sda5:label= "MyData" uuid= " 4483a0bc-7fa1-4691-b976-a1a98ebf448c "uuid_sub=" cd986ce4-38c2-4b9d-845e-6009af489925 "TYPE=" Btrfs "[email Protected] ~]# blkid/dev/sda6/dev/sda6:label= "MyData" uuid= "4483a0bc-7fa1-4691-b976-a1a98ebf448c" uuid_sub= " 069a84fe-b9a0-47a2-851c-43ffa83d2aee "type=" "Btrfs"
[[email protected] ~]# mkdir/mysql[[email protected] ~]# mount-o compress=lzo/dev/sda5/mysql/#compress =lzo Specify compression algorithm # hang Download Btrfs file system (attach Btrfs device to any one can)
[[email protected] ~]# df -h #查看是否挂载文件系统 capacity used available used% Mount point/dev/mapper/centos-root 20g 838m 19g 5% /devtmpfs 481m 0 481m 0% /devtmpfs 490m 0 490m 0% /dev/shmtmpfs 490M 6.6M 484M 2% /runtmpfs &nBsp; 490m 0 490M 0% /sys/fs/cgroup/dev/sda1 497M 120M 378M 25% /boot/dev/sda5 20g 1.0m 18g 1% /mysql
[[email protected] ~]# btrfs filesystem resize -8g /mysql/ # File system reduces capacity by 8G, +8g means expansion 8G (resize resizing file system) resize '/mysql/' of ' -8g ' [[email protected] ~]# df -h File System capacity used available used% mount point/dev/mapper/centos-root 20G 838M 19G 5% /devtmpfs 481M 0 481M 0% /devtmpfs 490M 0 490M 0% /dev/shmtmpfs 490m 6.7m 484m 2% /runtmpfs 490m 0 490m 0% /sys/fs/cgroup/dev/sda1 497M 120M 378M 25% /boot/dev/sda5 12g 512k 10g 1% /mysql
btrfs device add /dev/* /mount_point new device to mount point for automatic auto-expansion [[email protected] ~]# btrfs device add /dev/sda7 /mysql/ #新增分区/dev/sda7 to/mysql[[ Email protected] ~]# df -h File System capacity used available used% mount point/dev/mapper/ Centos-root 20g 838m 19g 5% /devtmpfs 481m 0 481M 0% /devtmpfs 490m 0 490M 0% /dev/shmtmpfs 490m 6.7m 484m 2% /runtmpfs 490m 0 490m 0% /sys/fs/cgroup/dev/sda1 497m 120m 378m 25% /boot /dev/sda5 27g 512k 25g 1% /mysql
Btrfs Balance distributes the original data evenly to the new disk
Btrfs Balance Status/mydata #显示状态 (not really visible)
[[email protected] ~]# btrfs balance start/mydata #开启balance Pause paused
Remove a physical volume
Btrfs Device Delete #拆除一个物理卷 automatically moves data before it is removed when it supports online status
[[email protected] ~]# btrfs device delete /dev/sda7 /mysql/ #把/ DEV/SDA7 demolition [[Email protected] ~]# df -h File System capacity used available used% mount point/dev/ mapper/centos-root 20g 838m 19g 5% / devtmpfs 481m 0 481m 0% /devtmpfs 490m 0 490M 0% /dev/shmtmpfs 490m 6.7M 484M 2% /runtmpfs 490M 0 490M 0% /sys/fs/cgroup/dev/sda1 497m 120m 378m 25 % /boot/dev/sda5 17g 640k 17g 1% /mysql
[[email protected] ~]# btrfs balance start -dconvert=raid5 /mysql/ #修改数据的raid级别, modify support dynamics -mconvert=raid5 #修改元数据的raid级別 done, had to relocate 1 out of 3 chunks[[email protected] ~]# btrfs FILESYSTEM DF /MYSQL/DATA, RAID5: TOTAL=2.00GIB, USED=832.00KIBSYSTEM, RAID1: total=32.00mib, used=16.00kibmetadata, raid1: total=256.00mib, used= 112.00kibglobalreserve, single: total=16.00mib, used=0.00
Create a sub-volume
[Email protected] mysql]# btrfs subvolume list/mysql/#查看子卷是否挂载 [[email protected] mysql]# Btrfs subvolume create/mysql /log #创建子卷 instead of subdirectory create Subvolume '/mysql/log '
[[email protected] ~]# mount -o subvol=log /dev/sda5 /mnt/ mount a sub-volume to/mnt[[email protected] ~]# ls /mnt/[[ email protected] ~]# cp /etc/sesecuretty security/ selinux/ services sestatus.conf [[email protected] ~]# cp /etc/ services /mnt/[[email protected] ~]# btrfs subvolume show /mnt/ Viewing sub-volume information/mntname: loguuid: 3f81dd45-b049-084d-828f-59b39ca6318fparent uuid: -creation time: 2015-08-30 13:41:20object id: 267generation (Gen): 109Gen at Creation: 106parent: 5top level: 5flags: -snapshot (s):
[[email protected] ~]# umount/mnt/[[email protected] ~]# mount/dev/sda5/mysql/#挂载父卷依然能看到自己的数据, on the contrary is not possible [email protected ] ~]# Ls/mysql/logservices[[email protected] ~]# btrfs subvolume delete/mysql/log2 #删除子卷Transaction commit:none (defau LT) Delete Subvolume '/mysql/log2 ' [[email protected] ~]# Ls/mysql/abc.txt log
Create a Snapshot
[Email protected] ~]# btrfs subvolume create/mysql/log3 #先创建一个子卷Create subvolume '/mysql/log3 ' [[email protected] ~]# b Trfs subvolume snapshot/mysql/log3//mysql/log3_snapshot #创建快照Create A snapshot of '/mysql/log3/' in '/mysql/log3_snapsh OT ' [[email protected] ~]# btrfs subvolume delete/mydata/log3_snapshot #删除快照卷
Change the Ext series file system to Btrfs
[[email protected] ~]# btrfs device delete /dev/sda7 /mysql/ #先卸载一个分区 (I didn't go to create a new partition) [[email protected] mysql]# mke2fs - t ext4 -l mydata /dev/sda7 #格式化成ext4文件格式 [[email protected] ~]# mount /dev/sda7 /mydata/ #挂载 [[email protected] mysql]# cp /etc/ services /mydata/ #写的数据进去
[[email protected] ~]# umount /mydata/ #改btrfs前先卸载分区 [[email protected] ~]# fsck -f /dev/sda7 #强制修复 [[email protected] ~]# btrfs-convert /dev/sd7 #把ext系列的文件系统改成btrfs [[Email protected] ~]# btrfs filesystem show #显示已改成btrfs文件系统Label: ' MyData ' uuid: 4483a0bc-7fa1-4691-b976-a1a98ebf448ctotal devices 2 fs bytes used 1.77mibdevid 1 size 7.00GiB used 1.28GiB path /dev/sda5devid 2 size 10.00GiB used 1.28GiB path /dev/sda6Label: ' MyData ' uuid: 69d2e02d-4c41-4e58-a186-0202b73d326aTotal devices 1 FS bytes Used 326.20mibdevid 1 size 10.00gib used 10.00gib path /dev/sda7[[email protected] ~]# ls /mydata/ #数据依然还在ext2_saved lost+found Services
Preliminary knowledge and application of Btrfs file system