Monday, June 20, 2016

How To Install Btrfs Tools And Manage BTRFS Operations

http://linuxpitstop.com/install-btrfs-tools-on-ubuntu-linux-to-manage-btrfs-operations

Hello everybody, today we are going to show you installation of Btrfs tools and its Operation. Btrfs is a new copy on write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair and easy administration. Jointly developed at multiple companies, Btrfs is licensed under the GPL and open for contribution from anyone. Considering the rapid development of Btrfs at the moment, Btrfs is currently considered experimental. But according to the wiki maintained by the btrfs community, many of the current developers and testers of Btrfs run it as their primary file system with very few “unrecoverable” problems. Thus, Linux distributions tend to ship with Btrfs as an option but not as the default. Btrfs is not a successor to the default Ext4 file system used in most Linux distributions, but it can be expected to replace Ext4 in the future.
Now we will be going to install the latest version of brtfs-tools on Ubuntu Linux based server.

Prerequisites

Before installing the Btrfs on your linux system, make sure that you are using the latest version of kernel as it has been included in the mainline kernel. After that you are required to install some packages that are are necessary and helps in the installation of Btrfs tools.
Let’s run the below command to install build tools on your Linux system.
# apt-get install git install asciidoc xmlto --no-install-recommends
installing build tools
Now run the command below to install some more libraries for your system and press ‘y’ to continue.
# apt-get install uuid-dev libattr1-dev zlib1g-dev libacl1-dev e2fslibs-dev libblkid-dev liblzo2-dev
required btrfs libs

Downloading Brtfs-tools

To download the latest stable version of brtfs-tools run the the following git command in your command line terminal.
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
download btrfs-toosl

Build Btrf-tools

Run the following command for preparing your btrf-tools to build for compilation after changing directory to the downloaded package as shown.
# cd btrfs-progs/
# ./autogen.sh
After generating the build you will be asked to type ‘./configure’ and ‘make’ to compile. Just flow the below commands one by one.
# ./configure
make
compiling btrfs-tools

Installing Btrfs-Tools

Once the btrfs-tools compilation process completes, we can install it by using ‘make install’ command as shown below.
# make install
After installation, run below command to verify the installed version of btrfs-tools on your system.
# btrfs version
Installing btrfs-tools

Managing Btrfs Operations

BTRFS aims to provide a modern answer for making storage more flexible and efficient. Now we are going to show you some of the useful operations of Btrfs. It stores data in chunks across all of the block devices on the system. The total storage across these devices is shown in the standard output of df -h.
Raw data and filesystem metadata are stored in one or many chunks, typically 1 GiB in size. When RAID is configured, these chunks are replicated instead of individual files.

Btrfs Filesystem creation

‘mkfs.btrfs’ can accept more than one device on the command line using different options to control the raid configuration for data (-d) and metadata (-m). Once you have added another disk to your system and you wish to mount it using btrfs, then run below command to create its system.
# mkfs.btrfs /dev/sdb
creating btrfs
Once you have create a filesystem, you can mount your new btrfs device using below command.
# mount /dev/sdb /mnt

Btrfs Device scanning

btrfs device scan is used to scan all of the block devices under /dev and probe for Btrfs volumes. This is required after loading the btrfs module if you’re running with more than one device in a filesystem.
Let’s run below command to scan all devices.
#btrfs device scan
To scan a single device use below command.
#btrfs device scan /dev/sdb
You can use below command to print information about all of the btrfs filesystems on the machine.
# btrfs filesystem show

Adding New devices

New physical disks can be added to an existing btrfs filesystem. The first step is to have the new block device mounted on the machine like have already done this. Afterwards, let btrfs know about the new device and re-balance the file system. The key step here is re-balancing, which will move the data and metadata across both block devices.
So, first run below command to add new devices to a mounted filesystem.
#btrfs device add /dev/sdb /mnt
Then use below command to balance (restripe) the allocated extents across all of the existing devices. For example, with an existing filesystem mounted at /mnt, you can add the device /dev/sdb to it.
# btrfs filesystem balance /mnt
new device
Run the following command that prints very useful information that you can use to debug and check how the BTRFS volume has been created.
# btrfs filesystem df /mnt
Data, single: total=1.00GiB, used=320.00KiB
System, DUP: total=32.00MiB, used=16.00KiB
Metadata, DUP: total=128.00MiB, used=112.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B
Adding in /etc/fstab
If you don’t have an initrd, or your initrd doesn’t perform a btrfs device scan, you can still mount your volume btrfs filesystem by passing your devices in the filesystem explicitly to the mount command by adding below entry in your ‘/etc/fstab’ file.
# vim /etc/fstab
/dev/sdb /mnt btrfs 0 0
A common practice in system administration is to leave some head space, instead of using the whole capacity of a storage pool (just in case). With btrfs one can easily shrink and expand the volumes.
Let’s shrink the volume a bit (about 25%) using below command.
# btrfs filesystem resize -1g /mnt
To grow the volume run below command.
# btrfs filesystem resize +150m /mnt
This is the opposite operation, you can make a BTRFS grow to reach a particular size (e.g. 150 more megabytes) as in above command. You can also take an “all you can eat” approach via the max option, meaning all of the possible space will be used for the volume with below command.
 #btrfs filesystem resize max /mnt

Removing devices

Use below command to remove devices online. It redistributes the any extents in use on the device being removed to the other devices in the filesystem.
#btrfs device delete /dev/sdb /mnt

Conclusion

Btrfs is intended to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in Linux file systems. These features are being crucial as the use of Linux scales upward into larger storage configurations. Btrfs is designed to be a multipurpose filesystem, scaling well on very large block devices. There are alot of its other operational usages that you can use. So, don’t wait and let’s get started with btrfs and I hope you find this quite better than other Linux file systems.

No comments:

Post a Comment