{
    "content": [
        {
            "type": "text",
            "text": "# BTRFS-DEVICE (man)\n\n## NAME\n\nbtrfs-device - manage devices of btrfs filesystems\n\n## SYNOPSIS\n\nbtrfs device <subcommand> <args>\n\n## DESCRIPTION\n\nThe btrfs device command group is used to manage devices of the btrfs filesystems.\n\n## TLDR\n\n> Manage devices in a btrfs filesystem.\n\n- Add one or more devices to a btrfs filesystem:\n  `sudo btrfs {{d|device}} {{a|add}} {{path/to/block_device1 path/to/block_device2 ...}} {{path/to/btrfs_filesystem}}`\n- Remove a device from a btrfs filesystem:\n  `sudo btrfs {{d|device}} {{rem|remove}} {{path/to/device1|device_id1 path/to/device2|device_id2 ...}}`\n- Display error statistics:\n  `sudo btrfs {{d|device}} {{st|stats}} {{path/to/btrfs_filesystem}}`\n- Scan all disks and inform the kernel of all detected btrfs filesystems:\n  `sudo btrfs {{d|device}} {{sc|scan}} {{-d|--all-devices}}`\n- Display detailed per-disk allocation statistics:\n  `sudo btrfs {{d|device}} {{u|usage}} {{path/to/btrfs_filesystem}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **DEVICE MANAGEMENT** (2 subsections)\n- **TYPICAL USE CASES** (4 subsections)\n- **SUBCOMMAND** (8 subsections)\n- **DEVICE STATS** (5 subsections)\n- **EXIT STATUS**\n- **AVAILABILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "BTRFS-DEVICE",
        "section": "",
        "mode": "man",
        "summary": "btrfs-device - manage devices of btrfs filesystems",
        "synopsis": "btrfs device <subcommand> <args>",
        "tldr_summary": "Manage devices in a btrfs filesystem.",
        "tldr_examples": [
            {
                "description": "Add one or more devices to a btrfs filesystem",
                "command": "sudo btrfs {{d|device}} {{a|add}} {{path/to/block_device1 path/to/block_device2 ...}} {{path/to/btrfs_filesystem}}"
            },
            {
                "description": "Remove a device from a btrfs filesystem",
                "command": "sudo btrfs {{d|device}} {{rem|remove}} {{path/to/device1|device_id1 path/to/device2|device_id2 ...}}"
            },
            {
                "description": "Display error statistics",
                "command": "sudo btrfs {{d|device}} {{st|stats}} {{path/to/btrfs_filesystem}}"
            },
            {
                "description": "Scan all disks and inform the kernel of all detected btrfs filesystems",
                "command": "sudo btrfs {{d|device}} {{sc|scan}} {{-d|--all-devices}}"
            },
            {
                "description": "Display detailed per-disk allocation statistics",
                "command": "sudo btrfs {{d|device}} {{u|usage}} {{path/to/btrfs_filesystem}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "btrfs-balance",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-balance/8/json"
            },
            {
                "name": "btrfs-device",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-device/8/json"
            },
            {
                "name": "btrfs-replace",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-replace/8/json"
            },
            {
                "name": "mkfs.btrfs",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DEVICE MANAGEMENT",
                "lines": 17,
                "subsections": [
                    {
                        "name": "Profile",
                        "lines": 4
                    },
                    {
                        "name": "RAID level",
                        "lines": 4
                    }
                ]
            },
            {
                "name": "TYPICAL USE CASES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Starting with a single-device filesystem",
                        "lines": 6
                    },
                    {
                        "name": "Add new device",
                        "lines": 8
                    },
                    {
                        "name": "Convert to RAID1",
                        "lines": 38
                    },
                    {
                        "name": "Remove device",
                        "lines": 11
                    }
                ]
            },
            {
                "name": "SUBCOMMAND",
                "lines": 1,
                "subsections": [
                    {
                        "name": "add [-Kf] <device> [<device>...] <path>",
                        "lines": 21
                    },
                    {
                        "name": "remove [options] <device>|<devid> [<device>|<devid>...] <path>",
                        "lines": 39
                    },
                    {
                        "name": "delete <device>|<devid> [<device>|<devid>...] <path>",
                        "lines": 2
                    },
                    {
                        "name": "replace <command> [options] <path>",
                        "lines": 2
                    },
                    {
                        "name": "ready <device>",
                        "lines": 6
                    },
                    {
                        "name": "scan [options] [<device> [<device>...]]",
                        "lines": 25
                    },
                    {
                        "name": "stats [options] <path>|<device>",
                        "lines": 16
                    },
                    {
                        "name": "usage [options] <path> [<path>...]::",
                        "lines": 66
                    }
                ]
            },
            {
                "name": "DEVICE STATS",
                "lines": 11,
                "subsections": [
                    {
                        "name": "write_io_errs",
                        "lines": 3
                    },
                    {
                        "name": "read_io_errors",
                        "lines": 2
                    },
                    {
                        "name": "flush_io_errs",
                        "lines": 5
                    },
                    {
                        "name": "corruption_errs",
                        "lines": 2
                    },
                    {
                        "name": "generation_errs",
                        "lines": 6
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "btrfs-device - manage devices of btrfs filesystems\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "btrfs device <subcommand> <args>\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The btrfs device command group is used to manage devices of the btrfs filesystems.\n",
                "subsections": []
            },
            "DEVICE MANAGEMENT": {
                "content": "BTRFS  filesystem  can be created on top of single or multiple block devices.  Devices can be\nthen added, removed or replaced on demand.  Data and metadata  are  organized  in  allocation\nprofiles  with  various  redundancy  policies.  There's some similarity with traditional RAID\nlevels, but this could be confusing to users familiar with the traditional  meaning.  Due  to\nthe  similarity, the RAID terminology is widely used in the documentation.  See mkfs.btrfs(8)\nfor more details and the exact profile capabilities and constraints.\n\nThe device management works on a mounted filesystem. Devices can be  added,  removed  or  re‐\nplaced, by commands provided by btrfs device and btrfs replace.\n\nThe profiles can be also changed, provided there's enough workspace to do the conversion, us‐\ning the btrfs balance command and namely the filter convert.\n\nType   The  block group profile type is the main distinction of the information stored on the\nblock device. User data are called Data,  the  internal  data  structures  managed  by\nfilesystem are Metadata and System.\n",
                "subsections": [
                    {
                        "name": "Profile",
                        "content": "A  profile  describes  an  allocation  policy based on the redundancy/replication con‐\nstraints in connection with the number of devices. The profile  applies  to  data  and\nmetadata block groups separately. E.g. single, RAID1.\n"
                    },
                    {
                        "name": "RAID level",
                        "content": "Where  applicable, the level refers to a profile that matches constraints of the stan‐\ndard RAID levels. At the moment the supported ones are: RAID0,  RAID1,  RAID10,  RAID5\nand RAID6.\n"
                    }
                ]
            },
            "TYPICAL USE CASES": {
                "content": "",
                "subsections": [
                    {
                        "name": "Starting with a single-device filesystem",
                        "content": "Assume  we've  created  a  filesystem  on  a block device /dev/sda with profile single/single\n(data/metadata), the device size is 50GiB and we've used the whole device for the filesystem.\nThe mount point is /mnt.\n\nThe amount of data stored is 16GiB, metadata have allocated 2GiB.\n"
                    },
                    {
                        "name": "Add new device",
                        "content": "We want to increase the total size of the filesystem and keep the profiles. The size  of  the\nnew device /dev/sdb is 100GiB.\n\n$ btrfs device add /dev/sdb /mnt\n\nThe  amount  of  free  data  space increases by less than 100GiB, some space is allocated for\nmetadata.\n"
                    },
                    {
                        "name": "Convert to RAID1",
                        "content": "Now we want to increase the redundancy level of both data and metadata, but we'll do that  in\nsteps.  Note, that the device sizes are not equal and we'll use that to show the capabilities\nof split data/metadata and independent profiles.\n\nThe constraint for RAID1 gives us at most 50GiB of usable space and exactly 2 copies will  be\nstored on the devices.\n\nFirst  we'll  convert the metadata. As the metadata occupy less than 50GiB and there's enough\nworkspace for the conversion process, we can do:\n\n$ btrfs balance start -mconvert=raid1 /mnt\n\nThis operation can take a while, because all metadata have to be moved and all block pointers\nupdated. Depending on the physical locations of the old and new blocks, the disk  seeking  is\nthe key factor affecting performance.\n\nYou'll  note that the system block group has been also converted to RAID1, this normally hap‐\npens as the system block group also holds metadata (the physical to logical mappings).\n\nWhat changed:\n\n• available data space decreased by 3GiB, usable roughly (50 - 3) + (100 - 3) = 144 GiB\n\n• metadata redundancy increased\n\nIOW, the unequal device sizes allow for combined space for data yet improved  redundancy  for\nmetadata.  If  we decide to increase redundancy of data as well, we're going to lose 50GiB of\nthe second device for obvious reasons.\n\n$ btrfs balance start -dconvert=raid1 /mnt\n\nThe balance process needs some workspace (i.e. a free device space without any data or  meta‐\ndata block groups) so the command could fail if there's too much data or the block groups oc‐\ncupy the whole first device.\n\nThe  device  size  of  /dev/sdb  as seen by the filesystem remains unchanged, but the logical\nspace from 50-100GiB will be unused.\n"
                    },
                    {
                        "name": "Remove device",
                        "content": "Device removal must satisfy the profile constraints, otherwise the command fails.  For  exam‐\nple:\n\n$ btrfs device remove /dev/sda /mnt\nERROR: error removing device '/dev/sda': unable to go below two devices on raid1\n\nIn order to remove a device, you need to convert the profile in this case:\n\n$ btrfs balance start -mconvert=dup -dconvert=single /mnt\n$ btrfs device remove /dev/sda /mnt\n"
                    }
                ]
            },
            "SUBCOMMAND": {
                "content": "",
                "subsections": [
                    {
                        "name": "add [-Kf] <device> [<device>...] <path>",
                        "content": "Add device(s) to the filesystem identified by path.\n\nIf  applicable,  a  whole device discard (TRIM) operation is performed prior to adding\nthe device. A device with existing filesystem detected by blkid(8) will prevent device\naddition and has to be forced. Alternatively the filesystem can be wiped from the  de‐\nvice using e.g. the wipefs(8) tool.\n\nThe  operation is instant and does not affect existing data. The operation merely adds\nthe device to the filesystem structures and creates some block groups headers.\n\nOptions\n\n-K|--nodiscard\ndo not perform discard (TRIM) by default\n\n-f|--force\nforce overwrite of existing filesystem on the given disk(s)\n\n--enqueue\nwait if there's another exclusive operation running, otherwise continue\n"
                    },
                    {
                        "name": "remove [options] <device>|<devid> [<device>|<devid>...] <path>",
                        "content": "Remove device(s) from a filesystem identified by <path>\n\nDevice removal must satisfy the profile constraints, otherwise the command  fails  and\ncannot  be  enforced.  The filesystem must be converted to profile(s) that would allow\nthe removal. This can for example happen when going down from 2 devices to 1 and using\nthe RAID1 profile. See the section Typical use cases.\n\nThe operation can take long as it needs to move all data from the device.\n\nNOTE:\nIt's possible to specify more than one device on the command line but  the  devices\nwill  be removed one by one, not at once.  This means that the remaining devices to\nbe deleted can be still used for writes. In that case there's a warning and  safety\ntimeout  as  this can be confusing and unexpected. The timeout can be overridden by\noption --force.\n\nIt is possible to delete the device that was used to mount the filesystem. The  device\nentry  in  the mount table (/proc/self/mounts) will be replaced by another device name\nwith the lowest device id.\n\nIf the filesystem is mounted in degraded mode (-o degraded), special term missing  can\nbe used for device. In that case, the first device that is described by the filesystem\nmetadata, but not present at the mount time will be removed.\n\nNOTE:\nIn  most  cases, there is only one missing device in degraded mode, otherwise mount\nfails. If there are two or more devices missing (e.g. possible in RAID6), you  need\nspecify  missing  as  many  times as the number of missing devices to remove all of\nthem.\n\nOptions\n\n--enqueue\nwait if there's another exclusive operation running, otherwise continue\n\n--force\nskip the safety timeout when there are multiple devices for removal, this  does\nnot force removing devices that would break the profile constraints\n"
                    },
                    {
                        "name": "delete <device>|<devid> [<device>|<devid>...] <path>",
                        "content": "Alias of remove kept for backward compatibility\n"
                    },
                    {
                        "name": "replace <command> [options] <path>",
                        "content": "Alias of whole command group btrfs replace for convenience. See btrfs-replace(8).\n"
                    },
                    {
                        "name": "ready <device>",
                        "content": "Wait  until  all  devices  of  a multiple-device filesystem are scanned and registered\nwithin the kernel module. This is to provide a way for automatic  filesystem  mounting\ntools to wait before the mount can start. The device scan is only one of the precondi‐\ntions and the mount can fail for other reasons.  Normal users usually do not need this\ncommand and may safely ignore it.\n"
                    },
                    {
                        "name": "scan [options] [<device> [<device>...]]",
                        "content": "Scan  devices  for  a btrfs filesystem and register them with the kernel module.  This\nallows mounting multiple-device filesystem by  specifying  just  one  from  the  whole\ngroup.\n\nIf  no  devices  are passed, all block devices that blkid reports to contain btrfs are\nscanned.\n\nThe options --all-devices or -d can be used as a fallback in case blkid is not  avail‐\nable.  If used, behavior is the same as if no devices are passed.\n\nThe command can be run repeatedly. Devices that have been already registered remain as\nsuch.  Reloading  the kernel module will drop this information. There's an alternative\nway of mounting multiple-device filesystem without the need for  prior  scanning.  See\nthe mount option device.\n\nOptions\n\n-d|--all-devices\nEnumerate  and  register  all  devices,  use as a fallback in case blkid is not\navailable.\n\n-u|--forget\nUnregister a given device or all stale devices if no path is given, the  device\nmust be unmounted otherwise it's an error.\n"
                    },
                    {
                        "name": "stats [options] <path>|<device>",
                        "content": "Read  and print the device IO error statistics for all devices of the given filesystem\nidentified by path or for a single device. The filesystem must be mounted.   See  sec‐\ntion DEVICE STATS for more information about the reported statistics and the meaning.\n\nOptions\n\n-z|--reset\nPrint the stats and reset the values to zero afterwards.\n\n-c|--check\nCheck if the stats are all zeros and return 0 if it is so. Set bit 6 of the re‐\nturn  code if any of the statistics is no-zero. The error values is 65 if read‐\ning stats from at least one device failed, otherwise it's 64.\n\n-T     Print stats in a tabular form, devices as rows and stats as columns\n"
                    },
                    {
                        "name": "usage [options] <path> [<path>...]::",
                        "content": "Show detailed information about internal allocations on devices.\n\nThe level of detail can differ if the command is run under a regular or the root  user\n(due to use of restricted ioctls). The first example below is for normal user (warning\nincluded) and the next one with root on the same filesystem:\n\nWARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root\n/dev/sdc1, ID: 1\nDevice size:           931.51GiB\nDevice slack:              0.00B\nUnallocated:           931.51GiB\n\n/dev/sdc1, ID: 1\nDevice size:           931.51GiB\nDevice slack:              0.00B\nData,single:           641.00GiB\nData,RAID0/3:            1.00GiB\nMetadata,single:        19.00GiB\nSystem,single:          32.00MiB\nUnallocated:           271.48GiB\n\n• Device  size  -- size of the device as seen by the filesystem (may be different than\nactual device size)\n\n• Device slack -- portion of device not used by the filesystem but still available  in\nthe physical space provided by the device, e.g.  after a device shrink\n\n• Data,single,  Metadata,single, System,single -- in general, list of block group type\n(Data, Metadata, System) and profile (single, RAID1, ...) allocated on the device\n\n• Data,RAID0/3 -- in particular, striped profiles  RAID0/RAID10/RAID5/RAID6  with  the\nnumber  of  devices  on which the stripes are allocated, multiple occurrences of the\nsame profile can appear in case a new device has been added and  all  new  available\nstripes have been used for writes\n\n• Unallocated  --  remaining  space  that  the  filesystem can still use for new block\ngroups\n\nOptions\n\n-b|--raw\nraw numbers in bytes, without the B suffix\n\n-h|--human-readable\nprint human friendly numbers, base 1024, this is the default\n\n-H     print human friendly numbers, base 1000\n\n--iec  select the 1024 base for the following options, according to the IEC standard\n\n--si   select the 1000 base for the following options, according to the SI standard\n\n-k|--kbytes\nshow sizes in KiB, or kB with --si\n\n-m|--mbytes\nshow sizes in MiB, or MB with --si\n\n-g|--gbytes\nshow sizes in GiB, or GB with --si\n\n-t|--tbytes\nshow sizes in TiB, or TB with --si\n\nIf conflicting options are passed, the last one takes precedence.\n"
                    }
                ]
            },
            "DEVICE STATS": {
                "content": "The device stats keep persistent record of several error classes related  to  doing  IO.  The\ncurrent  values  are  printed  at mount time and updated during filesystem lifetime or from a\nscrub run.\n\n$ btrfs device stats /dev/sda3\n[/dev/sda3].writeioerrs   0\n[/dev/sda3].readioerrs    0\n[/dev/sda3].flushioerrs   0\n[/dev/sda3].corruptionerrs 0\n[/dev/sda3].generationerrs 0\n",
                "subsections": [
                    {
                        "name": "write_io_errs",
                        "content": "Failed writes to the block devices, means that the layers beneath the filesystem  were\nnot able to satisfy the write request.\n"
                    },
                    {
                        "name": "read_io_errors",
                        "content": "Read request analogy to writeioerrs.\n"
                    },
                    {
                        "name": "flush_io_errs",
                        "content": "Number of failed writes with the FLUSH flag set. The flushing is a method of forcing a\nparticular  order between write requests and is crucial for implementing crash consis‐\ntency. In case of btrfs, all the metadata blocks must be  permanently  stored  on  the\nblock device before the superblock is written.\n"
                    },
                    {
                        "name": "corruption_errs",
                        "content": "A block checksum mismatched or a corrupted metadata header was found.\n"
                    },
                    {
                        "name": "generation_errs",
                        "content": "The  block  generation  does  not  match the expected value (e.g. stored in the parent\nnode).\n\nSince  kernel  5.14  the   device   stats   are   also   available   in   textual   form   in\n/sys/fs/btrfs/FSID/devinfo/DEVID/errorstats.\n"
                    }
                ]
            },
            "EXIT STATUS": {
                "content": "btrfs device returns a zero exit status if it succeeds. Non zero is returned in case of fail‐\nure.\n\nIf the -c option is used, btrfs device stats will add 64 to the exit status if any of the er‐\nror counters is non-zero.\n",
                "subsections": []
            },
            "AVAILABILITY": {
                "content": "btrfs    is    part    of    btrfs-progs.     Please    refer   to   the   documentation   at\nhttps://btrfs.readthedocs.io.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "btrfs-balance(8) btrfs-device(8), btrfs-replace(8), mkfs.btrfs(8)\n\n\n6.6.3                                       Mar 31, 2024                             BTRFS-DEVICE(8)",
                "subsections": []
            }
        }
    }
}