• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to use “btrfs device” comamnd to add/delete device to/from btrfs filesystem

by admin

Btrfs is an open-source, general-purpose file system for Linux. The name derives from the use of B-trees to store internal file system structures. Different names are used for the file system, including “Butter F S” and “B-tree F S.” Development of Btrfs began at Oracle in 2007, and now a number of companies (including Red Hat, Fujitsu, Intel, SUSE, and many others) are contributing to the development effort. Btrfs is included in the mainline Linux kernel.

btrfs device Utilities

Use the btrfs device command to manage devices on Btrfs file systems. A list of the available commands is as follows:

# 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

The btrfs device scan command scans physical devices looking for members of a Btrfs volume. This command allows a multiple-disk Btrfs file system to be mounted without specifying all the disks on the mount command.

You do not need to run “btrfs device scan” from the command line, because udev automatically runs btrfs device scan on boot. Use the btrfs device add command to add a device to a file system. In this example, the current file system structure is as follows:

# 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

The btrfs filesystem df command shows:

# 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

The output of the df command shows:

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

Add a 10 GB disk, /dev/sdb, to the file system mounted on /btrfs by using the btrfs device add command:

# btrfs device add /dev/sdb /btrfs

The output of the btrfs filesystem show command shows the newly added device:

# 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

The output of the btrfs filesystem df command shows no difference after adding the new device:

# 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

There is no difference in the output because the newly added device has not yet been allocated for either data or metadata. The additional size is reflected in the output of df:

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

After adding a device, it is recommended that you run the following balance command on the file system:

# 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

Running this command redistributes space by balancing the chunks of the file system across all the devices. This command also reclaims any wasted space. Use the btrfs device delete command to remove a device from a file system. Example:

# btrfs device delete /dev/sdb /btrfs
How to use “btrfs scrub” command to manage scrubbing on Btrfs file systems
“btrfs” command examples to Create and Manage Btrfs File System
How to create and mount Btrfs file system (explained with examples)

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to Disable Docker Process and docker0 Interface on CentOS/RHEL
  2. e4defrag: command not found
  3. nano: command not found
  4. How to recover GRUB (Corrupted boot partition) in CentOS/RHEL 5,6
  5. hdparm Command Examples in Linux
  6. uptime Command Examples in Linux
  7. How to install CentOS / RHEL 7 on RAID Partition
  8. How to change hostname in CentOS/RHEL 7
  9. How to Check whether SELinux is Enabled or Disabled
  10. How to extract RAR files in CentOS/RHEL 7 and 8

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright