Btrfs是Linux上的新一代文件系统(正在开发中),具备容量扩展、数据一致、多磁盘管理、快照、配额、发送等特性,经过采用B+树存储结构,对较大文件和超小文件具备较好的支持,经过校验码保障数据一致性,支持软件RAID功能,对“大数据时代”所面临的存储问题提供了更好的支持工具。php
整体来讲,btrfs与zfs很是相似。最近linux 5.0内核可能出现zfs不兼容的api,若是不能予以修正,将致使zfs没法升级到5.0的linux kernel。原本一直在用ZFS,可是最近个人存储系统出现了zpool丢失的状况,研究一下btrfs做为分布式存储的节点文件的备选。node
Btrfs具备与ZFS相似的高级特性,包括:linux
参考:git
这里以Ubuntu 18.04LTS安装btrfs相关的工具为例,其它Linux系统参考相应的文档。github
sudo apt install btrfs-progs btrfs-tools
主要参数以下:api
usage: btrfs [--help] [--version] <group> [<group>...] <command> [<args>] Command groups: subvolume manage subvolumes: create, delete, list, etc filesystem overall filesystem tasks and information balance balance data across devices, or change block groups using filters device manage and query devices in the filesystem scrub verify checksums of data and metadata rescue toolbox for specific rescue operations inspect-internal query various internal information property modify properties of filesystem objects quota manage filesystem quota settings qgroup manage quota groups replace replace a device in the filesystem Commands: check Check structural integrity of a filesystem (unmounted). restore Try to restore files from a damaged filesystem (unmounted) send Send the subvolume(s) to stdout. receive Receive subvolumes from a stream help Display help information version Display btrfs-progs version For an overview of a given command use 'btrfs command --help' or 'btrfs [command...] --help --full' to print all available options. Any command name can be shortened as far as it stays unambiguous, however it is recommended to use full command names in scripts. All command groups have their manual page named 'btrfs-<group>'.
个人机器上原来有两个盘,已经做为zfs系统,须要将其转换为btrfs,原来的磁盘会被所有抹去、数据会所有丢失。网络
由于zfs的存储池zpool已经挂载到glusterfs网络存储系统上,须要将其卸载。首先查看gluster的卷信息。app
sudo gluster volume status
而后,使用gluster remove-brick卸载掉该节点的brick。分布式
执行下面的命令,将会对zpool所有卸载。ide
sudo zpool export zpool
将物理磁盘/dev/sda和/dev/sdb作成raid0模式的btrfs系统。执行:
sudo mkfs.btrfs -L bfs -d raid0 /dev/sda /dev/sdb
输出以下:
btrfs-progs v4.15.1 See http://btrfs.wiki.kernel.org for more information. /dev/sdb appears to contain an existing filesystem (btrfs). ERROR: use the -f option to force overwrite of /dev/sdb supermap@podc01:~$ sudo mkfs.btrfs -L bfs -d raid0 /dev/sdb /dev/sda -f btrfs-progs v4.15.1 See http://btrfs.wiki.kernel.org for more information. Label: bfs UUID: fe330ce7-c658-4559-95e6-d91db384af92 Node size: 16384 Sector size: 4096 Filesystem size: 18.19TiB Block group profiles: Data: RAID0 2.00GiB Metadata: RAID1 1.00GiB System: RAID1 8.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 2 Devices: ID SIZE PATH 1 9.10TiB /dev/sdb 2 9.10TiB /dev/sda
mkdir /bpool mount -t btrfs /dev/sda /bpool
这里挂载的第一个设备,可是只须要挂载第一个,其它的自动加载,并且会显示两个设备的总和容量。
查看btrfs磁盘设备信息:
supermap@podc01:~$ sudo btrfs device usage /bpool /dev/sda, ID: 1 Device size: 9.10TiB Device slack: 0.00B Data,RAID0: 1.00GiB Metadata,RAID1: 1.00GiB System,RAID1: 8.00MiB Unallocated: 9.09TiB /dev/sdb, ID: 2 Device size: 9.10TiB Device slack: 0.00B Data,RAID0: 1.00GiB Metadata,RAID1: 1.00GiB System,RAID1: 8.00MiB Unallocated: 9.09TiB
文件系统信息:
supermap@podc01:~$ sudo btrfs filesystem usage /bpool Overall: Device size: 18.19TiB Device allocated: 4.02GiB Device unallocated: 18.19TiB Device missing: 0.00B Used: 1.00MiB Free (estimated): 18.19TiB (min: 9.09TiB) Data ratio: 1.00 Metadata ratio: 2.00 Global reserve: 16.00MiB (used: 0.00B) Data,RAID0: Size:2.00GiB, Used:768.00KiB /dev/sda 1.00GiB /dev/sdb 1.00GiB Metadata,RAID1: Size:1.00GiB, Used:112.00KiB /dev/sda 1.00GiB /dev/sdb 1.00GiB System,RAID1: Size:8.00MiB, Used:16.00KiB /dev/sda 8.00MiB /dev/sdb 8.00MiB Unallocated: /dev/sda 9.09TiB /dev/sdb 9.09TiB
系统磁盘信息:
supermap@podc01:~$ df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 16G 0 16G 0% /dev tmpfs 3.2G 2.8M 3.2G 1% /run /dev/nvme0n1p1 1.9T 62G 1.7T 4% / tmpfs 16G 63M 16G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 16G 0 16G 0% /sys/fs/cgroup tmpfs 3.2G 16K 3.2G 1% /run/user/121 ... 10.1.1.201:/gvzr00 53T 4.3T 49T 9% /home/supermap/gvzr00 /dev/loop16 91M 91M 0 100% /snap/core/6350 tmpfs 3.2G 36K 3.2G 1% /run/user/1000 /dev/sda 19T 17M 19T 1% /bpool
其中的bpool为挂载的btrfs存储卷。
btrfsctl -r 300M /bpool
当设备的空间快被使用完的时候,用户能够使用 btrfs-vol 命令为文件系统添加新的磁盘设备,从而增长存储空间。下面的命令向 /btrfsdisk 文件系统增长一个设备/sdc
btrfs-vol -a /dev/sdc /bpool
用户能够使用 mount 参数打开 btrfs 针对 SSD 的优化。命令以下:
mount – t btrfs – o SSD /dev/sda5 /btrfsdisk
用户能够使用 mount 参数打开压缩功能。命令以下:
mount – t btrfs – o compress /dev/sda5 /btrfsdisk
Btrfs Wiki 术语表中写到 scrub 是一种 "在线文件系统检查工具".它读取文件系统中的文件和元数据,并使用校验值和 RAID 存储上的镜像区分并修复损坏的数据.
启动一个(后台运行的)包含 /
目录的文件系统在线检查任务:
# btrfs scrub start /
检查该任务的运行状态:
# btrfs scrub status /
btrfs-progs 软件包带有 btrfs-scrub@.timer
系统单元,用来每个月运行 scrub 命令.经过添加挂载点的参数来启用它,例如btrfs-scrub@-.timer
(/
) 或者 btrfs-scrub@home.timer
(/home
).
也能够经过启动 btrfs-scrub@.service
来手动运行 scrub (使用一样的挂载点参数) ,相对于 # btrfs scrub
这么作的优势是会记录在 Systemd 日志中。