Introduction of Btrfs File system
Btrfs (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. Added some features not currently supported by EXT3/4, such as writable disk snapshots (snapshots), and support for recursive snapshots (snapshots of snapshots), built-in disk array (RAID) support, support for the concept of sub-volumes (subvolumes), Allow online sizing of file systems .....
Second, the Environment preparation
Operating system: CentOS7
New 3 new disks added:/dev/sdb,/DEV/SDC,/DEV/SDD
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/53/wKiom1XgdPmx-kkQAAIzKkIRtrk406.jpg "title=" Qq20150828224918.png "alt=" Wkiom1xgdpmx-kkqaaizkkirtrk406.jpg "/>
Three, Btrfs file system management and application
1. btrfs File System creation
[[email protected] ~]# mkfs.btrfs-l DATA/DEV/SDB/DEV/SDC #创建btrfs, volume label set to data
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/53/wKiom1XgdjPhOSweAAEfxlrn0SE401.jpg "title=" Qq20150828225246.png "alt=" Wkiom1xgdjphosweaaefxlrn0se401.jpg "/>
2, Btrfs file system information to view
[Email protected] ~]# btrfs filesystem show #显示系统中的btrfs文件系统Label: ' Data ' uuid:a1ab4260-2dbe-4e62-bb55-4c53533d85 A8total devices 2 FS bytes used 112.00KiBdevid 1 size 20.00GiB used 2.03GiB path/dev/sdbdevid 2 size 20.00GiB used 2.01GiB PATH/DEV/SDC
[Email protected] ~]# blkid/dev/sdb #查看btrfs中物理卷/dev/sdb information/dev/sdb:label= "data" uuid= "a1ab4260-2dbe-4e62-bb55-4 C53533d85a8 "uuid_sub=" 6f565410-b2f7-45db-b7b8-efd6f9fd3523 "type=" btrfs "[email protected] ~]# BLKID/DEV/SDC #查看 Information for physical volume/DEV/SDC in btrfs/dev/sdc:label= "data" uuid= "A1ab4260-2dbe-4e62-bb55-4c53533d85a8" uuid_sub= " 4f2ec113-886a-48e1-b9b7-8d90eec29841 "type=" "Btrfs"
3. Mount the newly created Btrfs file system to the/html directory and use DF to view
[[email protected] ~]# mkdir/html #创建/html directory [[email protected] ~]# mount/dev/sdb/html #将btrfs文件系统挂载至/html[ [Email protected] ~]# df-h/dev/sdb 40G 1.0M 38G 1%/html
4. Adjust the size of Btrfs file system online
Note: No expansion or reduction can exceed the space size of 1 disks
[[email protected] ~]# btrfs filesystem resize -15G /html #缩减btrfs文件系统15GResize '/html ' of ' -15g ' [[email protected] ~]# df -h #查看缩减后的信息/dev/sdb 25g 1.0m 8.0g 1% /html
[Email protected] ~]# btrfs filesystem resize +10g/html #扩展btrfs文件系统10GResize '/html ' of ' +10g ' [[email protected] ~]# D F-h # View extended information/dev/sdb 35G 1.0M 28G 1%/html
5. Add or remove physical devices to Btrfs file system/DEV/SDD
[Email protected] ~]# btrfs device add/dev/sdd/html #添加/DEV/SDD disk to Btrfs file system [[email protected] ~]# Df-h/dev/sdb 55G 448K 55G 1%/html
[[email protected] ~]# btrfs device delete/dev/sdb/html #从btrfs文件系统移除/dev/sdb disk [[email protected] ~]# DF-H/DEV/SDC 40G 448K 40G 1%/html
6. Creation, deletion and mounting of sub-volumes
Description of the commands related to the sub-volume
Btrfs Subvolume Create [-I <qgroupid>] [<dest>/]<name> Create a sub-volume Btrfs subvolume Delete [options] <subvolume> [<subvolume> ...] Delete a child volume Btrfs Subvolume Snapshot [-r] <source> <dest>| [<dest>/]<name> Create a snapshot of a child volume Btrfs Subvolume Show <subvol-path> Displaying information for a sub-volume Btrfs subvolume list [options] [-G [+|-]value] [-C [+|-]value] [--sort=gen,ogen,rootid,path] <path> view Btrfs file system List of neutron volumes |
(1) Create a sub-volume/html/logs
[Email protected] ~]# btrfs subvolume create/html/logscreate subvolume '/html/logs '
(2) To view information about the/html/logs of a sub-volume
[Email protected] ~]# btrfs subvolume list/html #显示子卷列表ID 260 Gen PNs Top Level 5 path logs
[Email protected] ~]# btrfs subvolume show/html/logs #显示子卷详细信息
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/5C/wKiom1XhpyvBgUDqAADz7sn_0dw804.jpg "title=" Qq20150829203603.png "alt=" Wkiom1xhpyvbgudqaadz7sn_0dw804.jpg "/>
(3) Deleting a sub-volume
[[email protected] ~]# btrfs subvolume delete/html/logs # Delete Sub volume transaction commit:none (default) Delete Subvolume '/html /logs '
(4) How to mount a sub-volume
Note: If you mount a sub-volume separately, you cannot see the files in the parent volume
Test one: Mount the sub-volume and copy the/etc/inittab to the child volume, then mount the parent volume to view the files in the child volume
[Email protected] ~]# mount-o subvol=logs/dev/sdc/messages #挂载子卷到/messages [[email protected] ~]# cp/etc/inittab/me Ssages/[[email protected] ~]# umount/messages/[[email protected] ~]# cat/html/logs/inittab #挂载父卷并查看子卷中的文件内容
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/59/wKioL1XhtwOyHKEVAAHk3LQ9mgw158.jpg "title=" Qq20150829213441.png "alt=" wkiol1xhtwoyhkevaahk3lq9mgw158.jpg "/> Test two: Copy/etc/fstab to the parent volume, unmount the parent volume, mount the child volume separately, the child volume does not see the files in the parent volume
[[email protected] ~]# cp /etc/fstab /html #复制/etc/fstab to parent volume [[Email protected] ~]# ll /html-rw-r--r--. 1 root root 619 aug 13 00:50 fstabdrwxr-xr-x. 1 root root 14 Aug 13 00:49 logs[[email protected] ~]# mount -o subvolid=261 /dev/sdc /messages/ #使用子卷id挂载 [[email protected] ~]# ll /messages/ #只能查看到子卷挂载目录中的文件total 4-rw-r--r--. 1 root root 511 aug 13 00:49 inittab [[email protected] ~]# ll / html #看不到父卷中的文件total 0
(5) Snapshot creation and deletion of a sub-volume
Note: You must mount the parent volume
Create a snapshot of a child volume
[Email protected] ~]# mount/dev/sdc/html [[email protected] ~]# Btrfs subvolume snapshot/html/logs/html/logs_snaps Hot #创建子卷的快照Create A snapshot of '/html/logs ' in '/html/logs_snapshot ' [[email protected] ~]# Btrfs subvolume list/html #显示子卷信息ID 261 Gen Top level 5 path Logsid 262 Gen Top level 5 path Logs_snapshot[[email protected] ~]# cat/html/ Logs_snapshot/inittab #查看快照中的文件, as in the original volume; Modify the files on the original volume and the snapshot volume will not change
Delete a snapshot of a child volume
[Email protected] ~]# btrfs subvolume delete/html/logs_snapshot #删除子卷的快照Transaction commit:none (default) Delete Subvol Ume '/html/logs_snapshot ' [[email protected] ~]# btrfs subvolume list/html #父卷中子卷的信息ID 261 Gen Top level 5 path log S
(6)Conversion between ext file system and Btrfs file system
btrfs-convert:invalid option-- '-' usage:btrfs-convert [-d] [-i] [-n] [-r] Device -D disable data Checksum #关闭数据校验码 -I ignore xattrs and ACLs #忽略xattrs和acls < Span class= "Apple-tab-span" style= "WHITE-SPACE:PRE;" > -n Disable packing of small files # -R roll back to ext2fs #回滚到ext文件系统 |
Use/dev/sdb disk to divide 1 5G partition/DEV/SDB1 and format it for EXT4 file system, uninstall EXT4 file system and force repair, then convert to Btrfs file system, then rollback back to Ext4 file system
[Email protected] ~]# mkfs.ext4/dev/sdb1 #格式化/dev/sdb1 for Ext4 file system [[email protected] ~]# BLKID/DEV/SDB1 #查看磁盘分区信息/de V/sdb1:uuid= "6733d53d-bcd8-4341-9f0d-8e1654eef58e" type= "EXT4" [[email protected] ~]# mount/dev/sdb1/mnt #挂载ext4分区 [[ Email protected] ~]# echo "EXT4 filesystem." >/mnt/ext4.txt #创建1个文件用于测试使用 [[email protected] ~]# Cat/mnt/ext4.txt #查 Look at the contents of the file Ext4 filesystem.
Convert the Ext4 file system to Btrfs file system and see if there is a problem with the file inside.
note: After the conversion is complete, there will be more ext2_saved directories;
[[email protected] ~]# umount /mnt #卸载/DEV/SDB1 partition [[EMAIL&NBSP;PROTECTED]&NBSP;~]#&NBSP;FSCK&NBSP;-F&NBSP;/DEV/SDB1 #强制修复/DEV/SDB1 Partition fsck from util-linux 2.23.2e2fsck 1.42.9 (28-dec-2013) pass 1: checking inodes, blocks, and sizespass 2: checking directory structurepass 3: checking directory connectivitypass 4: Checking reference countsPass 5: Checking group summary information/dev/sdb1: 12/327680 files (0.0% non-contiguous), 58463/1310720 blocks[[email protected] ~]# btrfs-convert /dev/sdb1 # Convert to Btrfs file system creating btrfs metadata.creating ext2fs image file.cleaning up System chunk.conversion complete. [[Email protected] ~]# blkid /dev/sdb1 #查看转换后的分区信息/dev/ Sdb1: uuid= "4caab68c-da42-44a8-9cc0-9745b69a3ace" uuid_sub= "3b3e28ea-4d95-42ad-8abc-b68fd82b65b5" type= "Btrfs" [[email protected] ~]# cat /mnt/ext4.txt # View file contents Ext4 filesystem.
Convert Btrfs file system back to the original Ext4 file system before you can roll back
[Email protected] ~]# umount/mnt #卸载btrfs文件系统 [[email protected] ~]# btrfs-convert-r/dev/sdb1 #执行回滚操作 ro Llback complete. [Email protected] ~]# blkid/dev/sdb1 #查看回滚后的磁盘分区信息/dev/sdb1:uuid= "6733d53d-bcd8-4341-9f0d-8e1654eef58e" type= "Ext4 [[email protected] ~]# mount/dev/sdb1/mnt #再挂载后查看里面的内容 [[email protected] ~]# ll/mnttotal 20-rw-r--r--. 1 root root 02:09 ext4.txtdrwx------. 2 root root 16384 02:00 lost+found
Summary
Btrfs also has an important drawback that when an error occurs in a node in BTree, the file system loses all the file information under that node. EXT2/3, however, avoids this problem, which is called "Error diffusion". But in any case, Btrfs will be the most promising file system for Linux in the future.
This article is from the "Bengbengtu" blog, make sure to keep this source http://bengbengtu.blog.51cto.com/9505633/1689643
Btrfs File System Application Brief