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 日誌中。