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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. Managing MySQL Using Systemd As A Non Root User
  2. CentOS / RHEL : How to migrate storage (LVM) with pvmove Command
  3. How to Create a tmpfs Filesystem in CentOS/RHEL
  4. CentOS / RHEL 7 : How to open the Firewall port for Samba server using FirewallD
  5. CentOS / RHEL : How to convert volume group metadata between LVM1 and LVM2
  6. How to use tar command under Linux
  7. How to Move Swap From Disk Partition to LVM Volume in Linux
  8. Linux Command line Basics – Executing commands from the command line
  9. Configuring Remote Logging using rsyslog in CentOS/RHEL
  10. How To Limit/Restrict FTP Commands On Vsftpd Services (CentOS/RHEL 6,7)

You May Also Like

Primary Sidebar

Recent Posts

  • MySQL: how to figure out which session holds which table level or global read locks
  • Recommended Configuration of the MySQL Performance Schema
  • MySQL: Identify what user and thread are holding on to a meta data lock that is preventing other queries from running
  • MySQL: How to kill a Long Running Query using max_execution_time
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary