[root@localhost ~]# btrfs --help #查看帮助可以看到btrfs 有很多子命令,用法也很多,这里只举例常用选项。
usage: btrfs [--help] [--version] <group> [<group>...] <command> [<args>]
btrfs subvolume create [-i <qgroupid>] [<dest>/]<name> #创建子卷
Create a subvolume
btrfs subvolume delete [options] <subvolume> [<subvolume>...] #删除子卷
Delete subvolume(s)
btrfs subvolume list [options] [-G [+|-]value] [-C [+|-]value] [--sort=gen,ogen,rootid,path] <path> #显示子卷列表
List subvolumes (and snapshots)
btrfs subvolume snapshot [-r] [-i <qgroupid>] <source> <dest>|[<dest>/]<name> #创建子卷快照
Create a snapshot of the subvolume
btrfs subvolume get-default <path> #获取子卷默认的文件系统
Get the default subvolume of a filesystem
btrfs subvolume set-default <subvolid> <path> #设置默认系统给子卷
Set the default subvolume of a filesystem
btrfs subvolume find-new <path> <lastgen> #列出btrfs文件系统中最近修改的文件,结合find命令
List the recently modified files in a filesystem
btrfs subvolume show <subvol-path> #显示更多的子卷信息
Show more information of the subvolume
btrfs subvolume sync <path> [<subvol-id>...] #子卷同步,类似mount同步模式,内存数据同步到磁盘,有待查证。
Wait until given subvolume(s) are completely removed from the filesystem.
btrfs filesystem df [options] <path> #显示挂载的文件系统详细信息。
Show space usage information for a mount point
btrfs filesystem show [options] [<path>|<uuid>|<device>|label] #显示创建文件系统的磁盘信息。
Show the structure of a filesystem
btrfs filesystem sync <path> #强制文件系统同步,
Force a sync on a filesystem
btrfs filesystem defragment [options] <file>|<dir> [<file>|<dir>...] #碎片整理
Defragment a file or a directory
btrfs filesystem resize [devid:][+/-]<newsize>[kKmMgGtTpPeE]|[devid:]max <path> #btrfs文件系统在线扩展和缩减空间
Resize a filesystem
btrfs filesystem label [<device>|<mount_point>] [<newlabel>] #改变btrfs文件系统卷标
Get or change the label of a filesystem
btrfs filesystem usage [options] <path> [<path>..] #显示文件系统当前的使用信息。
Show detailed information about internal filesystem usage .
btrfs balance start [options] <path> #改变磁盘chunk,在线改 数据和元数据 存储方式,单盘改raid,前提满足raid要求。
Balance chunks across the devices
btrfs balance pause <path> #暂停chunk更改,数据量较大,转换时间较长时,先暂停。
Pause running balance
btrfs balance cancel <path> #取消chunk更改,如上
Cancel running or paused balance
btrfs balance resume <path> #中断balance的操作,如上
Resume interrupted balance
btrfs balance status [-v] <path> #显示balance操作状态 如上
Show status of running or paused balance
btrfs device add [options] <device> [<device>...] <path> #文件系统增加磁盘
Add a device to a filesystem
btrfs device delete <device> [<device>...] <path> #文件系统删除磁盘
Remove a device from a filesystem
btrfs device scan [(-d|--all-devices)|<device> [<device>...]] #文件系统磁盘扫描
Scan devices for a btrfs filesystem
btrfs device ready <device> #猜测是检测加入的设备有没有被挂载
Check device to see if it has all of its devices in cache for mounting
btrfs device stats [-z] <path>|<device> #显示文件系统的设备状态
Show current device IO stats. -z to reset stats afterwards.
btrfs device usage [options] <path> [<path>..] #显示文件系统内部设备详细使用信息
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 ~]# mkfs.btrfs -L 'btrfs' /dev/sdb
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
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 ~]#
btrfs subvolume
[root@localhost btrfs22]# btrfs subvolume create /btrfs/btrfs.sub #创建子卷
Create subvolume '/btrfs/btrfs.sub'
[root@localhost btrfs22]# btrfs subvolume list /btrfs #显示子卷
ID 259 gen 43 top level 5 path btrfs.sub
[root@localhost btrfs22]# umount /btrfs
[root@localhost ~]# mount -o subvol=btrfs.sub /dev/sdc /btrfs.sub/ #单独挂载子卷
[root@localhost ~]# btrfs subvolume show /btrfs.sub/
/btrfs.sub
Name: btrfs.sub
uuid: 811deb2f-764f-6440-899c-cddb2b9867e2
Parent uuid: -
Creation time: 2016-05-11 08:43:51
Object ID: 259
Generation (Gen): 43
Gen at creation: 43
Parent: 5
Top Level: 5
Flags: -
Snapshot(s):
子卷删除
bash/shell Code复制内容到剪贴板
[root@localhost ~]# umount /btrfs.sub/ #卸卸载子卷
[root@localhost ~]# btrfs subvolume delete /btrfs/btrfs.sub
#执行删除命令
[root@localhost ~]# btrfs subvolume list /btrfs
#查看 已经被删除
ID 260 gen 45 top level 5 path btrfs.sub22
子卷快照,类似创建子卷
bash/shell Code复制内容到剪贴板
[root@localhost ~]# btrfs subvolume list /btrfs
ID 260 gen 45 top level 5 path btrfs.sub22
[root@localhost ~]# btrfs subvolume snapshot /btrfs/btrfs.sub22/ /btrfs/btrfs.sub22_snapshot
Create a snapshot of '/btrfs/btrfs.sub22/' in '/btrfs/btrfs.sub22_snapshot'
[root@localhost ~]# btrfs subvolume list /btrfs
ID 260 gen 50 top level 5 path btrfs.sub22
ID 262 gen 50 top level 5 path btrfs.sub22_snapshot