欢迎来到之路教程(on itroad-com)

btrfs 设备实用程序

使用 btrfs device 命令管理 Btrfs 文件系统上的设备。
可用命令列表如下:

# btrfs device
usage: btrfs device [command] [args]
    btrfs device add [options] [device] [device...] [path]
        Add a device to a filesystem
    btrfs device delete [device]|[devid] [device|devid...] [path]
    btrfs device remove [device]|[devid] [device|devid...] [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 [options] [path]|[device]
        Show device IO error statistics
    btrfs device usage [options] [path] [path..]
        Show detailed information about internal allocations in devices.
manage and query devices in the filesystem

btrfs device scan 命令扫描物理设备以寻找 Btrfs 卷的成员。
此命令允许挂载多磁盘 Btrfs 文件系统,而无需在 mount 命令中指定所有磁盘。

我们不需要从命令行运行“btrfs 设备扫描”,因为 udev 会在启动时自动运行 btrfs 设备扫描。
使用 btrfs device add 命令将设备添加到文件系统。
本例中,当前文件系统结构如下:

# btrfs filesystem show
Label: none  uuid: ba60ac96-1628-4656-b68b-c7327ff49179
	Total devices 1 FS bytes used 325.29MiB
	devid    1 size 10.00GiB used 867.66MiB path /dev/sda

btrfs 文件系统 df 命令显示:

# btrfs filesystem df /btrfs
Data, single: total=547.66MiB, used=324.75MiB
System, single: total=32.00MiB, used=16.00KiB
Metadata, single: total=288.00MiB, used=528.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B

df 命令的输出显示:

# df -h /btrfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda         10G  342M  9.4G   4% /btrfs

使用 btrfs device add 命令将 10 GB 磁盘 /dev/sdb 添加到挂载在 /btrfs 上的文件系统:

# btrfs device add /dev/sdb /btrfs

btrfs filesystem show 命令的输出显示了新添加的设备:

# btrfs filesystem show
Label: none  uuid: ba60ac96-1628-4656-b68b-c7327ff49179
	Total devices 2 FS bytes used 325.29MiB
	devid    1 size 10.00GiB used 867.66MiB path /dev/sda
	devid    2 size 10.00GiB used 0.00B path /dev/sdb

添加新设备后,btrfs filesystem df 命令的输出显示没有区别:

# btrfs filesystem df /btrfs
Data, single: total=547.66MiB, used=324.75MiB
System, single: total=32.00MiB, used=16.00KiB
Metadata, single: total=288.00MiB, used=528.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B

输出没有区别,因为新添加的设备尚未分配给数据或者元数据。
另外的大小反映在 df 的输出中:

# df -h /btrfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda         20G  342M   20G   2% /btrfs

添加设备后,建议我们在文件系统上运行以下 balance 命令:

# btrfs filesystem balance /btrfs
WARNING:
	Full balance without filters requested. This operation is very
	intense and takes potentially very long. It is recommended to
	use the balance filters to narrow down the balanced data.
	Use 'btrfs balance start --full-balance' option to skip this
	warning. The operation will start in 10 seconds.
	Use Ctrl-C to stop it.
10 9 8 7 6 5 4 3 2 1
Starting balance without any filters.
Done, had to relocate 17 out of 17 chunks

运行此命令通过在所有设备之间平衡文件系统的块来重新分配空间。
此命令还会回收任何浪费的空间。
使用 btrfs device delete 命令从文件系统中删除设备。
例子:

# btrfs device delete /dev/sdb /btrfs
如何使用“btrfs device”命令在 btrfs 文件系统中添加/删除设备

Btrfs 是一个用于 Linux 的开源通用文件系统。
该名称源自使用 B 树来存储内部文件系统结构。
文件系统使用了不同的名称,包括“Butter F S”和“B-tree F S”。
Btrfs 的开发始于 2007 年的 Oracle,现在许多(包括 Red Hat、Fujitsu、Intel、SUSE 和许多其他)都在为开发工作做出贡献。
Btrfs 包含在主线 Linux 内核中。

日期:2020-09-17 00:13:07 来源:oir作者:oir