Manpage/btrfs-device

From btrfs Wiki
(Difference between revisions)
Jump to: navigation, search
(Update from git, v4.5.3)
(Update from git, v4.7+)
Line 4: Line 4:
  
 
==NAME==
 
==NAME==
btrfs-device - control btrfs devices
+
btrfs-device - manage devices of btrfs filesystems
  
 
==SYNOPSIS==
 
==SYNOPSIS==
Line 11: Line 11:
 
==DESCRIPTION==
 
==DESCRIPTION==
  
<p><b>btrfs device</b> is used to control the btrfs devices, since btrfs can be used
+
<p>The <b>btrfs device</b> command group is used to manage devices of the btrfs filesystems.</p>
across several devices, <b>btrfs device</b> is used for multiple device management.</p>
+
 
==DEVICE MANAGEMENT==
 
==DEVICE MANAGEMENT==
  
<p>Btrfs filesystem is capable to manage multiple devices.</p>
+
<p>Btrfs filesystem can be created on top of single or multiple block devices.
<p>Btrfs filesystem uses different profiles to manage different RAID level, and
+
Data and metadata are organized in allocation profiles with various redundancy
use balance to rebuild chunks, also devices can be added/removed/replace
+
policies. There&#8217;s some similarity with traditional RAID levels, but this could
online.</p>
+
be confusing to users familiar with the traditional meaning. Due to the
 +
similarity, the RAID terminology is widely used in the documentation.  See
 +
[[Manpage/mkfs.btrfs|mkfs.btrfs(9)]] for more details and the exact profile capabilities and
 +
constraints.</p>
 +
<p>The device management works on a mounted filesystem. Devices can be added,
 +
removed or replaced, by commands profided by <b>btrfs device</b> and <b>btrfs replace</b>.</p>
 +
<p>The profiles can be also changed, provided there&#8217;s enough workspace to do the
 +
conversion, using the <b>btrfs balance</b> comand and namely the filter <em>convert</em>.</p>
 
<dl>
 
<dl>
 
<dt>
 
<dt>
Line 24: Line 30:
 
<dd>
 
<dd>
 
<p>
 
<p>
Btrfs filesystem uses data/metadata profiles to manage allocation/duplication
+
A profile describes an allocation policy based on the redundancy/replication
mechanism.<br/>
+
constrants in connection with the number of devices. The profile applies to
Profiles like RAID level can be assigned to data and metadata separately.
+
data and metadata block groups separately.
 
</p>
 
</p>
<p>See [[Manpage/mkfs.btrfs|mkfs.btrfs(8)]] for more details.</p>
 
  
 
<dt>
 
<dt>
Line 34: Line 39:
 
<dd>
 
<dd>
 
<p>
 
<p>
Btrfs filesystem supports most of the standard RAID level: 0/1/5/6/10.<br/>
+
Where applicable, the level refers to a profile that matches constraints of the
RAID levels can be assigned at mkfs time or online.
+
standard RAID levels. At the moment the supported ones are: RAID0, RAID1,
 +
RAID10, RAID5 and RAID6.
 
</p>
 
</p>
<p>See [[Manpage/mkfs.btrfs|mkfs.btrfs(8)]] for mkfs time RAID level assign and [[Manpage/btrfs-balance|btrfs-balance(8)]] for
 
online RAID level assign.</p>
 
<blockquote><b>Note:</b>
 
Since btrfs is under heavy development especially the RAID5/6 support,
 
it is <b>highly</b> recommended to read the follow btrfs wiki page to get more
 
updated details on RAID5/6:<br/>
 
https://btrfs.wiki.kernel.org/index.php/RAID56</blockquote>
 
 
<dt>
 
Balance
 
<dd>
 
<p>
 
[[Manpage/btrfs-balance|btrfs-balance(8)]] subcommand can be used to balance or rebuild chunks to the
 
desired profile.
 
</p>
 
<p>Due to the fact that balance can rebuild/recovery chunks according to its RAID
 
duplication if possible, so when using RAID1/5/6/10 with some devices failed
 
and you just added a new device to btrfs using [[Manpage/btrfs-device|btrfs-device(8)]], you should
 
run [[Manpage/btrfs-balance|btrfs-balance(8)]] to rebuild the chunks.</p>
 
<p>See [[Manpage/btrfs-balance|btrfs-balance(8)]] for more details.</p>
 
 
<dt>
 
Device add/remove/replace
 
<dd>
 
<p>
 
Device can be added/removed using [[Manpage/btrfs-device|btrfs-device(8)]] subcommand and replaced
 
using [[Manpage/btrfs-replace|btrfs-replace(8)]].
 
</p>
 
<p>When device is removed or replaced, btrfs will do the chunk rebuild if needed.</p>
 
<p>See [[Manpage/btrfs-replace|btrfs-replace(8)]] man page for more details on device replace.</p>
 
  
 
</dl>
 
</dl>
 +
<p>See the section <b>TYPICAL USECASES</b> for some examples.</p>
 
==SUBCOMMAND==
 
==SUBCOMMAND==
  
Line 78: Line 55:
 
Add device(s) to the filesystem identified by <em>&lt;path&gt;</em>.
 
Add device(s) to the filesystem identified by <em>&lt;path&gt;</em>.
 
</p>
 
</p>
<p>If applicable, a whole device discard (TRIM) operation is performed.</p>
+
<p>If applicable, a whole device discard (TRIM) operation is performed prior to
 +
adding the device. A device with existing filesystem detected by [http://man7.org/linux/man-pages/man8/blkid.8.html blkid(8)]
 +
will prevent device addition and has to be forced. Alternatively the filesystem
 +
can be wiped from the device using eg. the [http://man7.org/linux/man-pages/man8/wipefs.8.html wipefs(8)] tool.</p>
 +
<p>The operation is instant and does not affect existing data. The operation merely
 +
adds the device to the filesystem structures and creates some block groups
 +
headers.</p>
 
<p><tt>Options</tt></p>
 
<p><tt>Options</tt></p>
 
<dl>
 
<dl>
Line 85: Line 68:
 
<dd>
 
<dd>
 
<p>
 
<p>
do not perform discard by default
+
do not perform discard (TRIM) by default
 
</p>
 
</p>
  
Line 101: Line 84:
 
<dd>
 
<dd>
 
<p>
 
<p>
Remove device(s) from a filesystem identified by <em>&lt;path&gt;</em>.
+
Remove device(s) from a filesystem identified by <em>&lt;path&gt;</em>
 
</p>
 
</p>
 +
<p>Device removal must satisfy the profile constraints, otherwise the command
 +
fails. The filesystem must be converted to profile(s) that would allow the
 +
removal. This can typically happen when going down from 2 devices to 1 and
 +
using the RAID1 profile. See the example section below.</p>
 +
<p>The operation can take long as it needs to move all data from the device.</p>
 +
<blockquote><b>Note:</b>
 +
It is not possible to delete the device that was used to mount the
 +
filesystem. This is a limitation given by the VFS.</blockquote>
  
 
<dt>
 
<dt>
Line 115: Line 106:
 
<dd>
 
<dd>
 
<p>
 
<p>
Check device to see if it has all of it&#8217;s devices in cache for mounting.
+
Wait until all devices of a multiple-device filesystem are scanned and registered
 +
within the kernel module.
 
</p>
 
</p>
  
Line 122: Line 114:
 
<dd>
 
<dd>
 
<p>
 
<p>
Scan devices for a btrfs filesystem.
+
Scan devices for a btrfs filesystem and register them with the kernel module.
 +
This allows mounting multiple-device filesystem by specifying just one from the
 +
whole group.
 
</p>
 
</p>
<p>If one or more devices are passed, these are scanned for a btrfs filesystem.
+
<p>If no devices are passed, all block devices that blkid reports to contain btrfs
If no devices are passed, btrfs uses block devices containing btrfs
+
are scanned.</p>
filesystem as listed by blkid.
+
<p>The options <em>--all-devices</em> or <em>-d</em> are deprecated and kept for backward compatibility.
Finally, <em>--all-devices</em> or <em>-d</em> is the deprecated option. If it is passed,
+
If used, behavior is the same as if no devices are passed.</p>
its behavior is the same as if no devices are passed.</p>
+
<p>The command can be run repeatedly. Devices that have been already registered
 +
remain as such. Reloading the kernel module will drop this information. There&#8217;s
 +
an alternative way of mounting multiple-device filesystem without the need for
 +
prior scanning. See the mount option <em>device</em>.</p>
  
 
<dt>
 
<dt>
Line 134: Line 131:
 
<dd>
 
<dd>
 
<p>
 
<p>
Read and print the device IO stats for all mounted devices of the filesystem
+
Read and print the device IO error statistics for all devices of the given
identified by <em>&lt;path&gt;</em> or for a single <em>&lt;device&gt;</em>.
+
filesystem identified by <em>&lt;path&gt;</em> or for a single <em>&lt;device&gt;</em>. See section <b>DEVICE
 +
STATS</b> for more information.
 
</p>
 
</p>
 
<p><tt>Options</tt></p>
 
<p><tt>Options</tt></p>
Line 143: Line 141:
 
<dd>
 
<dd>
 
<p>
 
<p>
Reset stats to zero after reading them.
+
Print the stats and reset the values to zero afterwards.
 
</p>
 
</p>
  
Line 223: Line 221:
 
</dl>
 
</dl>
 
<p>If conflicting options are passed, the last one takes precedence.</p>
 
<p>If conflicting options are passed, the last one takes precedence.</p>
 +
==TYPICAL USECASES==
 +
 +
===STARTING WITH A SINGLE-DEVICE FILESYSTEM===
 +
 +
<p>Assume we&#8217;ve created a filesystem on a block device <em>/dev/sda</em> with profile
 +
<em>single/single</em> (data/metadata), the device size is 50GiB and we&#8217;ve used the
 +
whole device for the filesystem. The mount point is <em>/mnt</em>.</p>
 +
<p>The amount of data stored is 16GiB, metadata have allocated 2GiB.</p>
 +
====ADD NEW DEVICE====
 +
 +
<p>We want to increase the total size of the filesystem and keep the profiles. The
 +
size of the new device <em>/dev/sdb</em> is 100GiB.</p>
 +
<pre>$ btrfs device add /dev/sdb /mnt</pre>
 +
<p>The amount of free data space increases by less than 100GiB, some space is
 +
allocated for metadata.</p>
 +
====CONVERT TO RAID1====
 +
 +
<p>Now we want to increase the redundancy level of both data and metadata, but
 +
we&#8217;ll do that in steps. Note, that the device sizes are not equal and we&#8217;ll use
 +
that to show the capabilities of split data/metadata and independent profiles.</p>
 +
<p>The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2
 +
copies will be stored on the devices.</p>
 +
<p>First we&#8217;ll convert the metadata. As the metadata occupy less than 50GiB and
 +
there&#8217;s enough workspace for the conversion process, we can do:</p>
 +
<pre>$ btrfs balance start -mconvert=raid1 /mnt</pre>
 +
<p>This operation can take a while as the metadata have to be moved and all block
 +
pointers updated. Depending on the physical locations of the old and new
 +
blocks, the disk seeking is the key factor affecting performance.</p>
 +
<p>You&#8217;ll note that the system block group has been also converted to RAID1, this
 +
normally happens as the system block group also holds metadata (the physical to
 +
logial mappings).</p>
 +
<p>What changed:</p>
 +
<ul>
 +
<li>
 +
<p>
 +
available data space decreased by 3GiB, usable rougly (50 - 3) + (100 - 3) = 144 GiB
 +
</p>
 +
</li>
 +
<li>
 +
<p>
 +
metadata redundancy increased
 +
</p>
 +
</li>
 +
</ul>
 +
<p>IOW, the unequal device sizes allow for combined space for data yet improved
 +
redundancy for metadata. If we decide to increase redundancy of data as well,
 +
we&#8217;re going to lose 50GiB of the second device for obvious reasons.</p>
 +
<pre>$ btrfs balance start -dconvert=raid1 /mnt</pre>
 +
<p>The balance process needs some workspace (ie. a free device space without any
 +
data or metadata block groups) so the command could fail if there&#8217;s too much
 +
data or the block groups occupy the whole first device.</p>
 +
<p>The device size of <em>/dev/sdb</em> as seen by the filesystem remains unchanged, but
 +
the logical space from 50-100GiB will be unused.</p>
 +
==DEVICE STATS==
 +
 +
<p>The device stats keep persistent record of several error classes related to
 +
doing IO. The current values are printed at mount time and updated during
 +
filesystem lifetime or from a scrub run.</p>
 +
<pre>$ btrfs device stats /dev/sda3
 +
[/dev/sda3].write_io_errs  0
 +
[/dev/sda3].read_io_errs    0
 +
[/dev/sda3].flush_io_errs  0
 +
[/dev/sda3].corruption_errs 0
 +
[/dev/sda3].generation_errs 0</pre>
 +
<dl>
 +
<dt>
 +
write_io_errs
 +
<dd>
 +
<p>
 +
Failed writes to the block devices, means that the layers beneath the
 +
filesystem were not able to satisfy the write request.
 +
</p>
 +
 +
<dt>
 +
read_io_errors
 +
<dd>
 +
<p>
 +
Read request analogy to write_io_errs.
 +
</p>
 +
 +
<dt>
 +
flush_io_errs
 +
<dd>
 +
<p>
 +
Number of failed writes with the <em>FLUSH</em> flag set. The flushing is a method of
 +
forcing a particular order between write requests and is crucial for
 +
implementing crash consistency. In case of btrfs, all the metadata blocks must
 +
be permanently stored on the block device before the superblock is written.
 +
</p>
 +
 +
<dt>
 +
corruption_errs
 +
<dd>
 +
<p>
 +
A block checksum mismatched or a corrupted metadata header was found.
 +
</p>
 +
 +
<dt>
 +
generation_errs
 +
<dd>
 +
<p>
 +
The block generation does not match the expected value (eg. stored in the
 +
parent node).
 +
</p>
 +
 +
</dl>
 
==EXIT STATUS==
 
==EXIT STATUS==
  

Revision as of 17:44, 18 August 2016

Contents

btrfs-device(8) manual page

Note: manual pages are located at read-the-docs site, please update your links.



NAME

btrfs-device - manage devices of btrfs filesystems

SYNOPSIS

btrfs device <subcommand> <args>

DESCRIPTION

The btrfs device command group is used to manage devices of the btrfs filesystems.

DEVICE MANAGEMENT

Btrfs filesystem can be created on top of single or multiple block devices. Data and metadata are organized in allocation profiles with various redundancy policies. There’s some similarity with traditional RAID levels, but this could be confusing to users familiar with the traditional meaning. Due to the similarity, the RAID terminology is widely used in the documentation. See mkfs.btrfs(9) for more details and the exact profile capabilities and constraints.

The device management works on a mounted filesystem. Devices can be added, removed or replaced, by commands profided by btrfs device and btrfs replace.

The profiles can be also changed, provided there’s enough workspace to do the conversion, using the btrfs balance comand and namely the filter convert.

Profile

A profile describes an allocation policy based on the redundancy/replication constrants in connection with the number of devices. The profile applies to data and metadata block groups separately.

RAID level

Where applicable, the level refers to a profile that matches constraints of the standard RAID levels. At the moment the supported ones are: RAID0, RAID1, RAID10, RAID5 and RAID6.

See the section TYPICAL USECASES for some examples.

SUBCOMMAND

add [-Kf] <dev> [<dev>…] <path>

Add device(s) to the filesystem identified by <path>.

If applicable, a whole device discard (TRIM) operation is performed prior to adding the device. A device with existing filesystem detected by blkid(8) will prevent device addition and has to be forced. Alternatively the filesystem can be wiped from the device using eg. the wipefs(8) tool.

The operation is instant and does not affect existing data. The operation merely adds the device to the filesystem structures and creates some block groups headers.

Options

-K|--nodiscard

do not perform discard (TRIM) by default

-f|--force

force overwrite of existing filesystem on the given disk(s)

remove <dev>|<devid> [<dev>|<devid>…] <path>

Remove device(s) from a filesystem identified by <path>

Device removal must satisfy the profile constraints, otherwise the command fails. The filesystem must be converted to profile(s) that would allow the removal. This can typically happen when going down from 2 devices to 1 and using the RAID1 profile. See the example section below.

The operation can take long as it needs to move all data from the device.

Note: It is not possible to delete the device that was used to mount the filesystem. This is a limitation given by the VFS.

delete <dev>|<devid> [<dev>|<devid>…] <path>

Alias of remove kept for backward compatibility

ready <device>

Wait until all devices of a multiple-device filesystem are scanned and registered within the kernel module.

scan [(--all-devices|-d)|<device> [<device>…]]

Scan devices for a btrfs filesystem and register them with the kernel module. This allows mounting multiple-device filesystem by specifying just one from the whole group.

If no devices are passed, all block devices that blkid reports to contain btrfs are scanned.

The options --all-devices or -d are deprecated and kept for backward compatibility. If used, behavior is the same as if no devices are passed.

The command can be run repeatedly. Devices that have been already registered remain as such. Reloading the kernel module will drop this information. There’s an alternative way of mounting multiple-device filesystem without the need for prior scanning. See the mount option device.

stats [-z] <path>|<device>

Read and print the device IO error statistics for all devices of the given filesystem identified by <path> or for a single <device>. See section DEVICE STATS for more information.

Options

-z

Print the stats and reset the values to zero afterwards.

usage [options] <path> [<path>…]

Show detailed information about internal allocations in devices.

Options

-b|--raw

raw numbers in bytes, without the B suffix

-h|--human-readable

print human friendly numbers, base 1024, this is the default

-H

print human friendly numbers, base 1000

--iec

select the 1024 base for the following options, according to the IEC standard

--si

select the 1000 base for the following options, according to the SI standard

-k|--kbytes

show sizes in KiB, or kB with --si

-m|--mbytes

show sizes in MiB, or MB with --si

-g|--gbytes

show sizes in GiB, or GB with --si

-t|--tbytes

show sizes in TiB, or TB with --si

If conflicting options are passed, the last one takes precedence.

TYPICAL USECASES

STARTING WITH A SINGLE-DEVICE FILESYSTEM

Assume we’ve created a filesystem on a block device /dev/sda with profile single/single (data/metadata), the device size is 50GiB and we’ve used the whole device for the filesystem. The mount point is /mnt.

The amount of data stored is 16GiB, metadata have allocated 2GiB.

ADD NEW DEVICE

We want to increase the total size of the filesystem and keep the profiles. The size of the new device /dev/sdb is 100GiB.

$ btrfs device add /dev/sdb /mnt

The amount of free data space increases by less than 100GiB, some space is allocated for metadata.

CONVERT TO RAID1

Now we want to increase the redundancy level of both data and metadata, but we’ll do that in steps. Note, that the device sizes are not equal and we’ll use that to show the capabilities of split data/metadata and independent profiles.

The constraint for RAID1 gives us at most 50GiB of usable space and exactly 2 copies will be stored on the devices.

First we’ll convert the metadata. As the metadata occupy less than 50GiB and there’s enough workspace for the conversion process, we can do:

$ btrfs balance start -mconvert=raid1 /mnt

This operation can take a while as the metadata have to be moved and all block pointers updated. Depending on the physical locations of the old and new blocks, the disk seeking is the key factor affecting performance.

You’ll note that the system block group has been also converted to RAID1, this normally happens as the system block group also holds metadata (the physical to logial mappings).

What changed:

  • available data space decreased by 3GiB, usable rougly (50 - 3) + (100 - 3) = 144 GiB

  • metadata redundancy increased

IOW, the unequal device sizes allow for combined space for data yet improved redundancy for metadata. If we decide to increase redundancy of data as well, we’re going to lose 50GiB of the second device for obvious reasons.

$ btrfs balance start -dconvert=raid1 /mnt

The balance process needs some workspace (ie. a free device space without any data or metadata block groups) so the command could fail if there’s too much data or the block groups occupy the whole first device.

The device size of /dev/sdb as seen by the filesystem remains unchanged, but the logical space from 50-100GiB will be unused.

DEVICE STATS

The device stats keep persistent record of several error classes related to doing IO. The current values are printed at mount time and updated during filesystem lifetime or from a scrub run.

$ btrfs device stats /dev/sda3
[/dev/sda3].write_io_errs   0
[/dev/sda3].read_io_errs    0
[/dev/sda3].flush_io_errs   0
[/dev/sda3].corruption_errs 0
[/dev/sda3].generation_errs 0

write_io_errs

Failed writes to the block devices, means that the layers beneath the filesystem were not able to satisfy the write request.

read_io_errors

Read request analogy to write_io_errs.

flush_io_errs

Number of failed writes with the FLUSH flag set. The flushing is a method of forcing a particular order between write requests and is crucial for implementing crash consistency. In case of btrfs, all the metadata blocks must be permanently stored on the block device before the superblock is written.

corruption_errs

A block checksum mismatched or a corrupted metadata header was found.

generation_errs

The block generation does not match the expected value (eg. stored in the parent node).

EXIT STATUS

btrfs device returns a zero exit status if it succeeds. Non zero is returned in case of failure.

AVAILABILITY

btrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for further details.

SEE ALSO

mkfs.btrfs(8), btrfs-replace(8), btrfs-balance(8)

Personal tools