Btrfs (Btree FS) file system:
is a copy to write file system developed by Oracle in 2007 to enable large-scale storage of missing pools, snapshots, checksums and cross-device access issues in the file system.
Btrfs Features:
1.btrfs can consist of multiple underlying physical volumes, RAID enabled, online Add, remove, modify
2. Copy-on-write update mechanism (CoW): Copy, update, and replace pointers instead of "in-place" updates;
3. Extensibility: The overall performance after expansion does not decrease with the increase of system capacity
4. Data consistency: Btrfs uses the cow mechanism to support the checksum, ensuring the integrity of the data and determined that the unexpected hardware failure caused the loss
5. Sub-Volume: sub_volume#
6, Snapshot and clone: Snapshot support snapshot; a copy of a sub-volume, equivalent to a snapshot in VMware
7. Transparent compression: Automatically compress the data, non-user interaction, automatic decompression when viewing
Btrfs File System creation:
Mkfs.btrfs Common parameters:
-l ' LABEL ' #设定文件系统卷标
-D <type>: Raid0, RAID1, RAID5, Raid6, RAID10, single# indicates the type of data storage
-M <profile>: RAID0, RAID1, RAID5, Raid6, RAID10, single, DUP #语言数据存储机制
-O <feature> #格式化时启动的特性
-O List-all: Lists all supported feature;
First we add a few hard drives to do the Btree file system:
[[email protected] ~]# fdisk -l disk /dev/sda:21.5 GB, 21474836480 bytes, 41943040 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:0x000f09eb device Boot Start End Blocks id system/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 41943039&NBSP;&NBSP;&NBSP;&NBSP;20458496&NBSP;&NBSP;&NBSP;8E&NBSP;&NBSP;LINUX&NBSP;LVM Disk /dev/sdb:21.5 GB, 21474836480 bytes,41943040 Sector UNITS&NBSP;=&NBSP, Sector of 1 * 512 = 512 bytes sector size (logical/Physical):512 bytes / 512 byte i/o size (min/Best):512 bytes / 512 bytes Disk /dev/sdc:21.5 GB, 21474836480 BYTE,41943040 sector units = sector of 1 * 512 = 512 bytes sector size (logical/physical) :512 bytes / 512 bytes i/o size (min/Best):512 bytes / 512 bytes
Here we use SDB and SDC two disk directly formatted as Btrfs file system:
[[email protected] ~]# mkfs.btrfs-l mybtrfs/dev/sdb/dev/sdcbtrfs v3.16.2 See http://btrfs.wiki.kernel.org for more info Rmation. Turning on Incompat feature ' extref ': increased Hardlink limit per file to 65536adding DEVICE/DEV/SDC ID 2FS created Labe L Mybtrfs on/dev/sdb# Volume label created on SDB for "Mybtrfs" nodesize 16384 leafsize 16384 sectorsize 4096 size 40.00gib# space Total 40G
Is it easy to create a Btrfs file system?
Now that the creation is complete, let's take a look at the Btrfs specific information:
Btrfs FileSystem Show #btrfs文件系统的查看命令
[Email protected] ~]# btrfs filesystem showlabel: ' mybtrfs ' UUID:1C74225E-A36B-46B2-8BDE-BEF50D0F89FB total devices 2 FS bytes used 112.00KiB devid 1 size 20.00GiB used 2.03GiB path/dev/sdb devid 2 size 20.00GiB used 2.01GiB Path/dev/sdcbtrfs v3.16.2
We can also use Blkid [/dev/device] to view:
[[email protected] ~]# blkid/dev/sdb/dev/sdc# View two disk information/dev/sdb:label= "Mybtrfs" uuid= " 1C74225E-A36B-46B2-8BDE-BEF50D0F89FB "uuid_sub=" 87045ae0-ae5f-4e56-811c-1b246532047c "TYPE=" Btrfs "/dev/sdc:label = "Mybtrfs" uuid= "1C74225E-A36B-46B2-8BDE-BEF50D0F89FB" uuid_sub= "6c491f79-b13e-44c3-94e0-ad7e895b7613" TYPE= " Btrfs
#包括卷标名LABLE, Uuid,type type information, and we noticed that the UUID of the two disks is the same because the two disks belong to the same btrfs system, and the sub volumes are different, Btrfs supports multiple sub-volumes
Then we can mount the Btrfs file system.
[[email protected] ~]# mkdir /mydata# Create a mount point [email protected] ~]# mount -t btrfs /dev/sdb /mydata/#挂载btrfs文件系统 [[email protected] ~]# mount | tail -n 5 #mount查看最后一个挂载成功mqueue on /dev/mqueue type mqueue (Rw,relatime,seclabel) Debugfs on /sys/kernel/debug type debugfs (rw,relatime)/dev/sda1 on /boot type xfs (Rw,relatime,seclabel, Attr2,inode64,noquota)/dev/sr0 on /media/cdrom type iso9660 (ro,relatime)/dev/sdb on /mydata type btrfs (Rw,relatime,seclabel,space_cache)
Note: Mount mounts because two disks are btrfs, so just mount any block of two disks
Btrfs filesystem:
show View information
show--all-devices: View all devices
[device] View a specific device's Btrfs
DF: Usage rate of Mounted btrfs file system
Resize: Modify Btrfs file system size
[[email protected] ~]# btrfs filesystem show --all-deviceslabel: ' Mybtrfs ' uuid: 1c74225e-a36b-46b2-8bde-bef50d0f89fb total devices 2 fs bytes used 896.00kib devid 1 size 20.00GiB used 2.03GiB path /dev/sdb devid 2 size 20.00GiB used 2.01GiB path /dev/sdcBtrfs v3.16.2[[email Protected] ~]# btrfs filesystem show /dev/sdc failed to open /dev /fd0: no such device or addresslabel: ' Mybtrfs ' uuid: 1c74225e-a36b-46b2-8bde-bef50d0f89fb total devices 2 fs bytes Used 896.00kib devid 1 size 20.00gib used 2.03gib path /dEv/sdb devid 2 size 20.00gib used 2.01gib path /dev/sdc
Btrfs v3.16.2 #因为属于同一个文件系统, so looking at one shows all
After the Btrfs file system is created, we enter the directory to create the file to test for success:
[Email protected] ~]# cd/mydata/[[email protected] mydata]# Ls[[email protected] mydata]# touch A.txt[[email protected] mydata]# cp/etc/grub2.cfg/[[email protected] mydata]# ls #可以添加文件, btrfs normal use a.txt grub2.cfg
Uninstall we can use Umount [/dev/sd#] to uninstall
We can also use Btrfs's built-in transparent compression mechanism when mounting file systems, so that users do not need to participate:
Mount-o compress={lzo|zlib} [DEVICE] [Mount_point]
Supports two compression algorithms for Lzo and zlib
After setting this parameter we will store the data in Btrfs file system automatically by Lzo or zlib compression mechanism, that is, transparent compression
[[email protected] ~]# umount/dev/sdb[[email protected] ~]# mount-o compress=lzo/dev/sdb/mydata/[[email protected] ~]# Cp/etc/rc.d/init.d/functions/mydata/[[email protected] ~]# cd/mydata/[[email protected] mydata]# ll-h functions/etc/ Rc.d/init.d/functions-rw-r--r--. 1 root root 14K January 2015/etc/rc.d/init.d/functions-rw-r--r--. 1 root root 14K September 3 15:21 functions
Because the functions file is too small, we see that the size does not change, large files can see the size of the compressed
Btrfs can also be added online to reduce file system size by:
Btrfs filesystem resize + size [Mount_point]
[[Email protected] mydata]# btrfs filesystem resize -10g /mydata/resize '/mydata/' of ' -10g ' #这样原来的btrfs文件系统大小减少10G大小 [[Email protected] mydata]# btrfs filesystem df /mydata# View Btrfs usage data, raid0: total=2.00gib, used=776.00kibdata, single: total=8.00mib, used=0.00system, raid1: total=8.00mib, used= 16.00kibsystem, single: total=4.00mib, used=0.00metadata, raid1: total=1.00gib, Used=112.00kibmetadata, single: total=8.00mib, used=0.00globalreserve, single: total= 16.00MIB,&NBSP;USED=0.00[[EMAIL&NBSP;PROTECTED]&NBSP;MYDATA]#&NBSP;DF&NBSP;-LH File System capacity used available used% mount point/dev/mapper/centos-root 18g 4.2g 14g 24% /devtmpfs 481m 0 481M 0% /devtmpfs 490M 72K 490M 1% /dev/shmtmpfs 490m 14m 477M 3% /runtmpfs 490m 0 490M 0% /sys/fs/cgroup/dev/sda1 497M 125M 373M 25% /boot/dev/sr0 7.1g 7.1g 0 100% /media/cdrom/dev/sdb 30G 1.1M 18g 1% /mydata# is now 30G
This way, Btrfs is reduced to 30G by the original 40G, while the CP and the files created before us are unaffected, provided there is room for the data to be stored.
[[email protected] mydata]# lsa.txt functions grub2.cfg[[email protected] mydata]# cat grub2.cfg #文件照样可以查看 # # do not EDIT This file## It was automatically generated by Grub2-mkconfig using templates# from/etc/grub.d and Settings From/etc/defa ult/grub#### Begin/etc/grub.d/00_header # # #set pager=1if [-S $prefix/grubenv]; Then Load_envfiif ["${next_entry}"]; Then set default= "${next_entry}" set next_entry= save_env next_entry set Boot_once=trueelse
Since we can reduce the size of the space, let's try to increase its size.
[[Email protected] mydata]# btrfs filesystem resize +10g /mydata/resize '/mydata/' of ' +10g ' #这里我们增加10G大小 [[email protected] mydata]# [[email protected] mydata]# btrfs filesystem showlabel: ' Mybtrfs ' uuid: 1c74225e-a36b-46b2-8bde-bef50d0f89fb total devices 2 fs bytes Used 904.00kib devid 1 size 20.00gib used 2.03GiB path /dev/sdb devid 2 size 20.00gib used 2.01gib path /dev/sdcbtrfs v3.16.2[[email protected] mydata]# &NBSP;LL&NBSP;-LH Total dosage 20k-rw-r--r--. 1 root root 0 9 month 3 15:00 a.txt-rw-r--r--. 1 root root 14k 9 Month 3 15:21 functions-rw-R--r--. 1 root root 4.0k 9 Month 3 15:00 grub2.cfg[[email protected] mydata]# df -lh /mydata/File System capacity used available used% mount point/dev/sdb 40g 1.1m 38g 1% /mydata# this again for the original 40G
[Email protected] mydata]# btrfs filesystem resize Max/mydata/resize '/mydata/' of ' Max ' #指定扩展为最大容量
Btrfs supports increasing online to reduce the size of existing capacity, but what if the loaded disk capacity is not enough??
The Btrfs file system also supports the direct addition of disk devices to the file system:
Btrfs device Add [Divice] [Mount_point]
Here we have a reserved disk. SDD, let's look at the effect:
[[email protected] mydata]# btrfs device add /dev/sdd /mydata/#直接加载 [email &NBSP;PROTECTED]&NBSP;MYDATA]#&NBSP;DF&NBSP;-LH File System capacity used available used% mount point/dev/mapper/ Centos-root 18g 4.2g 14g 24% /devtmpfs 481m 0 481M 0% /devtmpfs 490m 72K 490M 1% /dev/shmtmpfs 490M 14M 477M 3% /runtmpfs 490M 0 490M 0% /sys/fs/cgroup/dev/sda1 497m 125m 373m 25% /boot/dev/sr0 7.1g 7.1G 0 100% /media/cdrom/dev/sdb 60g 1.1m 56g 1% /mydata# we see that the load is increased from the original 40G size to 60G size
The Btrfs file system also supports data file equalization operations: (usually rarely done)
Btrfs balance start [Mount_point]
Pause: Paused
Cancel: Canceled
Resume: Continue
Status: State
[[email protected] mydata]# Btrfs balance Start/mydata/done, had to relocate 6 out of 6 chunks# migrated 6 Chunks[[email Protect Ed] mydata]# btrfs balance status/mydata/no balance found on '/mydata/'
#状态信息由于文件很小, execution has ended and viewing can only be seen during the migration process, and large files are available.
To create a sub-volume:
Btrfs subvolume Create [mount_point]/[files]
[[email protected] mydata]# btrfs subvolume Create use/mydata/logs# creating sub-volume Creation Subvolume '/mydata/logs ' [[email protected] mydata]# btrfs subvolume list/mydata/#列出子卷信息ID 260 Gen-top Level 5 path logs
Mount a sub-volume:
[Email protected] ~]# umount/mydata/#需要先卸载挂载点 [[email protected] ~]# mount-o subvol=logs/dev/sdb/mnt/#挂载子卷 [[Email Prot Ected] ~]# ls/mnt/#logs没有文件 [[email protected] ~]# cp/var/log/messages/mnt/#cp文件到子卷可以 [[email protected] ~]# ls /mnt/messages
[[email protected] ~]# btrfs subvolume show /mnt/#查看子卷详细信息/mnt Name: logs uuid: cb76840f-56df-db4e-8077-2faf03a8351a parent uuid: - Creation time: 2015-09-03 16:37:54 Object ID: 260 Generation (Gen): 55 Gen at creation: 52 parent: 5 top level: 5 flags: - snapshot (s):
Delete a sub-volume using: Btrfs subvolume delete/mydata/logs
There is also a snapshot of the creation of the sub-volume, no specific action is written.
[Email protected] ~]# Btrfs subvolume snapshot/mydata/logs/mydata/logs_snapshot
Our Btrfs file system is introduced here, such as where there are problems also hope that the great God pointed out, thank you!
This article is from the "Open Source Prosperity" blog, please be sure to keep this source http://zhaohongfei.blog.51cto.com/6258685/1691126
Btrfs (Btree FS) file system