查看命令状态特性
[root@CentOS7 ~]# mkfs.btrfs -O list-all
Filesystem features available at mkfs time:
mixed-bg - mixed data and metadata block groups (0x4)
extref - increased hardlink limit per file to 65536 (0x40, default)
raid56 - raid56 extended format (0x80)
skinny-metadata - reduced-size metadata extent refs (0x100, default)
no-holes - no explicit hole extents for files (0x200
创建btrfs文件系统
[root@CentOS7 ~]# mkfs.btrfs -L mydata /dev/sdb /dev/sdc
btrfs-progs v3.19.1
See http://btrfs.wiki.kernel.org for more information.
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
adding device /dev/sdc id 2
fs created label mydata on /dev/sdb
nodesize 16384 leafsize 16384 sectorsize 4096 size 40.00GiB
显示btrfs文件系统信息,默认显示所有
[root@CentOS7 ~]# btrfs filesystem show
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
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/sdc
btrfs-progs v3.19.1
只显示指定btrfs文件系统
[root@CentOS7 ~]# btrfs filesystem show /dev/sdc
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
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/sdc
btrfs-progs v3.19.1
压缩挂载
[root@CentOS7 ~]# mount -o compress=lzo /dev/sdb /mydata
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 4.8M 114M 4% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdb 40G 18M 38G 1% /mydata
使用LABEL查看btrfs文件系统
[root@CentOS7 ~]# btrfs filesystem show /mydata
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
Total devices 2 FS bytes used 912.00KiB
devid 1 size 20.00GiB used 2.02GiB path /dev/sdb
devid 2 size 20.00GiB used 2.01GiB path /dev/sdc
联机修改分区大小
[root@CentOS7 ~]# btrfs filesystem resize -10G /mydata/
Resize '/mydata/' of '-10G'
[root@CentOS7 ~]# btrfs filesystem show /mydata
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
Total devices 2 FS bytes used 912.00KiB
devid 1 size 10.00GiB used 2.02GiB path /dev/sdb
devid 2 size 20.00GiB used 2.01GiB path /dev/sdc
[root@CentOS7 ~]# btrfs filesystem df /mydata
Data, RAID0: total=2.00GiB, used=784.00KiB
System, RAID1: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, RAID1: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 4.7M 114M 4% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdb 30G 18M 18G 1% /mydata
增加5G空间大小
[root@CentOS7 ~]# btrfs filesystem resize +5G /mydata/
Resize '/mydata/' of '+5G'
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 4.7M 114M 4% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdb 35G 18M 28G 1% /mydata
[root@CentOS7 ~]# btrfs filesystem df /mydata/
Data, RAID0: total=2.00GiB, used=784.00KiB
System, RAID1: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, RAID1: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
添加到最大分区容量
[root@CentOS7 ~]# btrfs filesystem resize max /mydata
Resize '/mydata' of 'max'
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 8.7M 110M 8% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdb 40G 18M 38G 1% /mydata
添加一块硬进去,如果设置了max,会自动扩展
[root@CentOS7 ~]# btrfs device add /dev/sdd /mydata
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 8.7M 110M 8% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdb 60G 18M 56G 1% /mydata
将数据负载至各个磁盘
[root@CentOS7 ~]# btrfs balance start /mydata/
Done, had to relocate 5 out of 5 chunks
从分区移除一个磁盘
[root@CentOS7 ~]# btrfs device delete /dev/sdb /mydata
[root@CentOS7 ~]# btrfs filesystem show
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
Total devices 2 FS bytes used 912.00KiB
devid 2 size 20.00GiB used 2.03GiB path /dev/sdc
devid 3 size 20.00GiB used 2.03GiB path /dev/sdd
重新加入一个设备
[root@CentOS7 mydata]# btrfs device add /dev/sdb /mydata
将分区转换成RAID5
[root@CentOS7 mydata]# btrfs balance start -dconvert=raid5 /mydata
Done, had to relocate 1 out of 3 chunks
[root@CentOS7 mydata]#
[root@CentOS7 mydata]#
[root@CentOS7 mydata]# btrfs balance start -mconvert=raid5 /mydata
查看子卷信息
[root@CentOS7 mydata]# btrfs subvolume list /mydata/
创建并查看子卷
[root@CentOS7 mydata]# btrfs subvolume create /mydata/logs
Create subvolume '/mydata/logs'
[root@CentOS7 mydata]# btrfs subvolume list /mydata
ID 265 gen 109 top level 5 path logs
取消挂载父卷,只挂载子卷
[root@CentOS7 ~]# umount /mydata/
[root@CentOS7 ~]# mount -o subvol=logs /dev/sdb /mnt
[root@CentOS7 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 23G 56M 23G 1% /
devtmpfs 109M 0 109M 0% /dev
tmpfs 119M 0 119M 0% /dev/shm
tmpfs 119M 8.7M 110M 8% /run
tmpfs 119M 0 119M 0% /sys/fs/cgroup
/dev/sda5 30G 1.2G 29G 4% /usr
/dev/sda2 79G 152M 78G 1% /var
/dev/sda3 40G 33M 40G 1% /usr/local
/dev/sda7 10G 33M 10G 1% /home
/dev/sda9 6.9G 33M 6.8G 1% /tmp
/dev/md0 3.9G 16M 3.7G 1% /backup
/dev/sda1 197M 108M 90M 55% /boot
tmpfs 24M 0 24M 0% /run/user/0
/dev/sdc 60G 17M 58G 1% /mnt
查看子卷详细信息
[root@CentOS7 ~]# btrfs subvolume show /mnt
/mnt
Name: logs
uuid: 757e5898-97be-8942-a9bb-a1bd3bc01506
Parent uuid: -
Creation time: 2016-07-18 10:30:13
Object ID: 265
Generation (Gen): 109
Gen at creation: 109
Parent: 5
Top Level: 5
Flags: -
Snapshot(s):
通过卷id挂载子卷
[root@CentOS7 ~]# btrfs subvolume list /mydata
ID 265 gen 112 top level 5 path logs
ID 266 gen 110 top level 5 path cache
[root@CentOS7 ~]# mount -o subvolid=266 /dev/sdb /mnt
删除子卷,需要父卷也有挂载
[root@CentOS7 ~]# btrfs subvolume delete /mydata/logs
Delete subvolume (no-commit): '/mydata/logs'
[root@CentOS7 ~]# btrfs subvolume list /mydata/
[root@CentOS7 ~]#
创建快照
Create a snapshot of '/mydata/logs' in '/mydata/logs_snapshot'
[root@CentOS7 ~]# btrfs subvolume list /mydata
ID 265 gen 118 top level 5 path logs
ID 266 gen 118 top level 5 path logs_snapshot
删除快照
[root@CentOS7 logs_snapshot]# cd
[root@CentOS7 ~]# btrfs subvolume delete /mydata/logs_snapshot
Delete subvolume (no-commit): '/mydata/logs_snapshot'
什么意思,得查一下,马哥说是对一个文件做快照
[root@CentOS7 logs]# cp --reflink grub2.cfg grub2.cfg_snap
拆除文件系统
[root@CentOS7 logs]# btrfs balance start -dconvert=single /mydata #更改数据类型
Done, had to relocate 1 out of 3
[root@CentOS7 logs]# btrfs balance start -mconvert=raid1 /mydata #更改元数据类型
Done, had to relocate 2 out of 3 chunks
[root@CentOS7 logs]# btrfs device delete /dev/sdd /mydata/ #拆除文件系统
转换文件系统
[root@CentOS7 ~]# umount /mnt/ #先卸载文件系统
[root@CentOS7 ~]# fsck -f /dev/sdd1 #强制检查文件系统是否正常
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdd1: 12/327680 files (0.0% non-contiguous), 58463/1310720 blocks
[root@CentOS7 ~]# btrfs-convert /dev/sdd1 #文件系统转换成btrfs
creating btrfs metadata.
copy inodes [o] [ 0/ 12]
creating ext2fs image file.
cleaning up system chunk.
conversion complete.
[root@CentOS7 ~]# btrfs filesystem show #查看文件系统,发现/dev/sdd1已经变成btrfs文件系统
Label: 'mydata' uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969
Total devices 2 FS bytes used 672.00KiB
devid 2 size 20.00GiB used 2.03GiB path /dev/sdc
devid 4 size 20.00GiB used 1.03GiB path /dev/sdb
Label: none uuid: 42290a33-9e06-4cfb-89a4-6fb660e30915
Total devices 1 FS bytes used 228.50MiB
devid 1 size 5.00GiB used 5.00GiB path /dev/sdd1
btrfs-progs v3.19.1
[root@CentOS7 ~]#
[root@CentOS7 ~]# mount /dev/sdd1 /mnt/ #重新挂载文件系统
[root@CentOS7 ~]# mount
/dev/sdd1 on /mnt type btrfs (rw,relatime,seclabel,space_cache)
从btrfs文件系统转换回原来的系统
[root@CentOS7 ~]# umount /mnt
[root@CentOS7 ~]# btrfs-convert -r /dev/sdd1
[root@CentOS7 ~]# blkid /dev/sdd1
/dev/sdd1: UUID="6ef58403-3584-413e-bc11-6f5281917caa" TYPE="ext4"