linux檔案系統,具有寫時複製COW(copy-on-write),改善ext3檔案系統單檔案大小限制,並加入其他特性,如可寫快照,快照的快照,內建RAID,子卷(subvloume),專注於容錯,修復和易於管理,下面一起來看看什麼是linux btrfs檔案系統及管理關係吧!
什麼是btrfs?
Btrfs(B-tree檔案系統,通常念成Butter FS,Better FS或B-tree FS),linux檔案系統,具有寫時複製COW(copy-on-write),改善ext3檔案系統單檔案大小限制,並加入其他特性,如可寫快照,快照的快照,內建RAID,子卷(subvloume),專注於容錯,修復和易於管理。單檔案可達16EB,最大檔案數量2^64,最大卷容量16EB,等。
btrfs功能特性
1,COW:寫時複製,每次寫入資料時,先將資料寫入到新的block,寫入成功後,更改舊資料塊指標到新資料塊,而非更改本身。
2,多物理卷支援,btrfs內建raid,可線上增刪磁碟裝置,可線上擴充套件和縮減磁碟空間。
3,資料和元資料校驗碼,checksum
4,子卷,可單獨掛載子卷
5,可寫快照,快照的快照,單個檔案快照。
6,透明壓縮
7,ext3/4和btrfs無痛互轉
btrfs 基本用法:
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# btrfs --help #檢視幫助可以看到btrfs 有很多子命令,用法也很多,這裡只舉例常用選項。
usage: btrfs [--help] [--version] [...] []
btrfs subvolume create [-i ] [/] #建立子卷
Create a subvolume
btrfs subvolume delete [options] [...] #刪除子卷
Delete subvolume(s)
btrfs subvolume list [options] [-G [+|-]value] [-C [+|-]value] [--sort=gen,ogen,rootid,path] #顯示子卷列表
List subvolumes (and snapshots)
btrfs subvolume snapshot [-r] [-i ] |[/] #建立子卷快照
Create a snapshot of the subvolume
btrfs subvolume get-default #獲取子卷預設的檔案系統
Get the default subvolume of a filesystem
btrfs subvolume set-default #設定預設系統給子卷
Set the default subvolume of a filesystem
btrfs subvolume find-new #列出btrfs檔案系統中最近修改的檔案,結合find命令
List the recently modified files in a filesystem
btrfs subvolume show #顯示更多的子卷資訊
Show more information of the subvolume
btrfs subvolume sync [...] #子卷同步,類似mount同步模式,記憶體資料同步到磁碟,有待查證。
Wait until given subvolume(s) are completely removed from the filesystem.
btrfs filesystem df [options] #顯示掛載的檔案系統詳細資訊。
Show space usage information for a mount point
btrfs filesystem show [options] [|||label] #顯示建立檔案系統的磁碟資訊。
Show the structure of a filesystem
btrfs filesystem sync #強制檔案系統同步,
Force a sync on a filesystem
btrfs filesystem defragment [options] |
[|...] #碎片整理
Defragment a file or a directory
btrfs filesystem resize [devid:][+/-][kKmMgGtTpPeE]|[devid:]max #btrfs檔案系統線上擴充套件和縮減空間
Resize a filesystem
btrfs filesystem label [|] [] #改變btrfs檔案系統卷標
Get or change the label of a filesystem
btrfs filesystem usage [options] [..] #顯示檔案系統當前的使用資訊。
Show detailed information about internal filesystem usage .
btrfs balance start [options] #改變磁碟chunk,線上改 資料和元資料 儲存方式,單盤改raid,前提滿足raid要求。
Balance chunks across the devices
btrfs balance pause #暫停chunk更改,資料量較大,轉換時間較長時,先暫停。
Pause running balance
btrfs balance cancel #取消chunk更改,如上
Cancel running or paused balance
btrfs balance resume #中斷balance的操作,如上
Resume interrupted balance
btrfs balance status [-v] #顯示balance操作狀態 如上
Show status of running or paused balance
btrfs device add [options] [...] #檔案系統增加磁碟
Add a device to a filesystem
btrfs device delete [...] #檔案系統刪除磁碟
Remove a device from a filesystem
btrfs device scan [(-d|--all-devices)| [...]] #檔案系統磁碟掃描
Scan devices for a btrfs filesystem
btrfs device ready #猜測是檢測加入的裝置有沒有被掛載
Check device to see if it has all of its devices in cache for mounting
btrfs device stats [-z] | #顯示檔案系統的裝置狀態
Show current device IO stats. -z to reset stats afterwards.
btrfs device usage [options] [..] #顯示檔案系統內部裝置詳細使用資訊
Show detailed information about internal allocations in devices.
btrfs檔案系統管理
為分割槽建立btrfs檔案系統
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# fdisk -l | grep "^Disk /dev/sd[a-z]" #準備sd{b,c,d,e}4塊20G磁碟,未做任何分割槽。
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sde: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors
建立單分割槽btrfs並檢視
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# s -L 'btrfs' /dev/sdb
btrfs-progs v3.19.1
See 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
fs created label btrfs on /dev/sdb
nodesize 16384 leafsize 16384 sectorsize 4096 size 20.00GiB
[root@localhost ~]# btrfs filesystem show
Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
Total devices 1 FS bytes used 112.00KiB
devid 1 size 20.00GiB used 2.04GiB path /dev/sdb
btrfs-progs v3.19.1
[root@localhost ~]# mount -o compress=lzo -L btrfs /btrfs/ 掛載時可以設定透明壓縮機制。
[root@localhost ~]# btrfs filesystem df /btrfs
Data, single: total=8.00MiB, used=256.00KiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
再新增一塊磁碟
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# btrfs device add /dev/sdc /btrfs #新增磁碟,刪除用btrfs device delete /dev/sdc /btrfs
[root@localhost ~]# btrfs fi sh
Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
Total devices 2 FS bytes used 384.00KiB
devid 1 size 20.00GiB used 2.04GiB path /dev/sdb
devid 2 size 20.00GiB used 0.00B path /dev/sdc
btrfs-progs v3.19.1
[root@localhost ~]#
線上增加或縮減空間,線上改變空間,可以讓lvm坐冷板凳了。
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# btrfs fi resize -10G /btrfs/ #線上縮減空間
Resize '/btrfs/' of '-10G'
[root@localhost ~]# btrfs fi sh
Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
Total devices 2 FS bytes used 384.00KiB
devid 1 size 10.00GiB used 2.04GiB path /dev/sdb
devid 2 size 20.00GiB used 0.00B path /dev/sdc
btrfs-progs v3.19.1
[root@localhost ~]# btrfs fi resize +7G /btrfs/ #線上增加空間
Resize '/btrfs/' of '+7G'
[root@localhost ~]# btrfs fi sh
Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
Total devices 2 FS bytes used 384.00KiB
devid 1 size 17.00GiB used 2.04GiB path /dev/sdb
devid 2 size 20.00GiB used 0.00B path /dev/sdc
btrfs-progs v3.19.1
[root@localhost ~]#
線上更改資料和元資料的結構
bash/shell Code複製內容到剪貼簿
[root@localhost ~]# btrfs fi df /btrfs/
Data, single: total=8.00MiB, used=256.00KiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
[root@localhost ~]# btrfs balance start -mconvert=raid1 /btrfs/ #-mconvert 為改變metadata元資料區的儲存結構
Done, had to relocate 4 out of 5 chunks
[root@localhost ~]# btrfs fi sh
Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
Total devices 2 FS bytes used 192.00KiB
devid 1 size 17.00GiB used 296.00MiB path /dev/sdb
devid 2 size 20.00GiB used 288.00MiB path /dev/sdc
btrfs-progs v3.19.1
[root@localhost ~]# btrfs fi df /btrfs/
Data, single: total=8.00MiB, used=64.00KiB
System, RAID1: total=32.00MiB, used=16.00KiB
Metadata, RAID1: total=256.00MiB, used=112.00KiB #對比上改為了raid1
GlobalReserve, single: total=16.00MiB, used=0.00B
[root@localhost ~]# btrfs balance start -dconvert=raid1 /btrfs/ #-dconvert 為改變data資料區的.儲存結構
Done, had to relocate 1 out of 3 chunks