3.btrfs Management and application

Source: Internet
Author: User

Btrfs Introduction:

Btrfs(usually read asButter FS), byOraclein -announced and conducted in the yearCOW(copy-on-write type ) file system. The goal is to replace Linuxthe currentext3file system, improve ext3 limit, especially single file size limit, total file system size limit and joinfile Checkand features. Added some features not currently supported by EXT3/4, such as writableDisk Snapshots(snapshots), and support RecursiveSnapshot (snapshotsof snapshots), built-indisk array(RAID) support, supports the concept of sub-volume (subvolumes), allowing the file system size to be resized online.

Btrfs features :

Scalability (scalability) related features,Btrfs's most important design goal is to address the scalability requirements of large machines for file systems. features such as Extent,b-tree and dynamic inode creation ensure that Btrfs still has outstanding performance on large machines, Overall performance without decreasing as the system capacity increases.

followed by data consistency   (dataintegrity) related attributes. The system faces unpredictable hardware failure, Btrfs adopt COW Transactional technology to ensure file system consistency. btrfs also supports Checksum Silent corrupt

The third is the features associated with multi-device management. Btrfs supports creating snapshots (snapshot), and cloning (clone) . Btrfs can also easily manage multiple physical devices , making traditional volume management software redundant.

Finally, other features that are difficult to categorize. These features are more advanced technologies that can significantly improve the time /space performance of file systems, including delay allocation, storage optimization of small files, directory indexing, and more.

Btrfs How to use:

Creating a file system

The Mkfs.btrfs command establishes a btrfs -formatted file system. You can create a btrfs file system on the device Sda5 with the following command and mount it to the/btrfsdisk directory:

#mkfs. Btrfs/dev/sda5

#mkdir/btrfsdisk

#mount –t Btrfs/dev/sda5/btrfsdisk

such a Btrfs is set up on the device Sda5 . It is worth mentioning that, in this default case,Btrfs also has redundant protection for metadata even if there is only one device . If you have multiple devices, you can make RAID settings when you create the file system . For more information, see the following introduction.

Here are a few other mkfs.btrfs parameters.

Nodesize and leafsize are used to set the size of the Btrfs internal BTree node, which defaults to a page size. However, users can also use larger nodes to increase fanoutand reduce the height of the tree, which is, of course, only suitable for very large file systems.

The Alloc-start parameter is used to specify the starting address of the file system on the disk device. This allows the user to conveniently reserve some special space in front of the disk.

the Byte-count parameter sets the size of the file system, and the user can use only part of the device to increase the file system size when the space is low.

To modify the file system size

after the file system is set up, you can modify the file system size. /dev/sda5 mounted to the /btrfsdisk , the size is 800M . If you want to use only 500M of these, you need to reduce the size of the current file system, which can be achieved by the following command:

#df

Filesystem 1k-blocks used Available use% mounted on

/DEV/SDA1 101086 19000 76867 20%/boot

/dev/sda5 811248 811216 1%/btrfsdisk

#btrfsctl –r-300m/btrfsdisk

#df

Filesystem 1k-blocks used Available use% mounted on

/DEV/SDA1 101086 19000 76867 20%/boot

/dev/sda5 504148 504106 1%/btrfsdisk

Similarly, you can use the BTRFSCTL command to increase the size of the file system.

Create Snapshot

in the following example, there are 2 files in the system when you create a snapshot Snap1 . After the snapshot is created, modify the contents of the Test1 . Then go back to Snap1, open the test1 file, you can see test1 content is still the previous content.

#ls/btrfsdisk

Test1 Test2

#vi test1

This is a test

#btrfsctl –s Snap1/btrfsdisk

#vi test1

Test1 is modified

#cd/btrfsdisk/snap1

#cat test1

This is a test

As can be seen from the above example, the contents of the snapshot Snap1 saved will not be changed by subsequent write operations.

Create Subvolume

with the Btrfs command, users can easily build subvolume . Assuming that the/btrfsdisk has been mounted to the btrfs file system, the user can create a new subvolume within the file system . For example, create a /sub1 subvolumeand Mount the Sub1 under/mnt/test:

#mkdir/mnt/test

#btrfsctl –s Sub1/btrfsdisk

#mount –t Btrfs–o Subvol=sub1/dev/sda5/mnt/test

Subvolme can make it easier for administrators to create sub-file systems of different uses on file systems, and to configure them in special configurations, such as files in some directories that focus on saving disk space, and therefore need to turn on compression, or configure different RAID policies. Currently Btrfs is still in the development phase, and the Subvolme and snapshot created cannot be deleted. In addition , the disk quota functionality for Subvolume has not been implemented. However , with the continuous maturation of btrfs, these features will inevitably be further improved.

Create Raid

when MKFS, you can specify multiple devices and configure RAID . The following command demonstrates how to Configure RAID1 using Mkfs.btrfs . Sda6 and sda7 can be configured as RAID1, which is mirror . The user can choose to configure the data as RAID1or optionally configure the metadata as RAID1 .

Configure the data to RAID1, you can use the- d parameter of Mkfs.btrfs . As shown below:

#mkfs. Btrfs–draid1/dev/sda6/dev/sda7

#mount –t Btrfs/dev/sda6/btrfsdisk

Add a new device

when the device is running out of space, users can add new disk devices to the file system using the Btrfs-vol command, thereby increasing storage space. The following command adds a device to the/btrfsdisk file system/sda8

#btrfs-vol–a/dev/sda8/btrfsdisk

SSD Support

users can use the mount parameter to open btrfs for SSD optimizations. The command is as follows:

#mount –t Btrfs–o Ssd/dev/sda5/btrfsdisk

Turn on the compression function

users can use the mount parameter to turn on the compression feature. The command is as follows:

#mount –t Btrfs–o Compress/dev/sda5/btrfsdisk

Synchronizing file systems

to improve efficiency,Btrfs 's IO operations are handled asynchronously by some kernel threads. This allows the user to manipulate the file without immediately reacting to the disk. You can do an experiment, after creating a file on Btrfs, wait 5 to ten seconds to power off the system, after restarting again, the new file does not appear.

This is not a problem for most applications, but sometimes users want to The IO operation executes immediately, and the file system needs to be synchronized at this point. The following btrfs commands are used to synchronize the file system:

#btrfsctl –c/btrfsdisk

Debug function

Btrfs provides a certain debug capability, and debug will be your favorite tool for readers who want to learn about the principles of Btrfs's internal implementation . Here is a brief introduction to the Debug function of the command used.

the following command prints meta data from the Btrfs file system on the device Sda5 to the screen.

#btrfs-debug-tree/dev/sda5


3.btrfs Management and application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.