Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction and usage of btrfs file system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Btrfs file system:

Btrfs (B-tree file system, usually pronounced Butter FS,Better FS or Btree FS), authorized by GPL, is a file system that supports replication on write (COW) announced by Oracle in 2007 and is in progress. The goal is to replace Linux's current ext3 document system, improve ext3 limitations, especially individual file size, total file system size or file checking, and add features that ext3 does not support, such as writable snapshots (writable snapshots), snapshots of snapshots (snapshots of snapshots), built-in disk arrays (RAID), and subvolumes (subvolumes). Btrfs also claims to be focused on "fault tolerance, repair and ease of management".

Core features:

Multi-physical volume support: btrfs can be composed of multiple underlying physical volumes; RAID is supported to "add", "remove" and "modify" online

Copy update mechanism on write (CoW): the so-called COW means that every time you write disk data, the updated data is first written to a new block, and when the new data is written successfully, the relevant data structure is updated to point to the new block. Copy, update, and replace pointers instead of "in-place" updates

Data and metadata check code (checksum): btrfs reads its corresponding checksum as it reads the data. If the final data read from disk is different from checksum, btrfs will first try to read a mirrored backup of the data, and if there is no mirrored backup of the data, btrfs will return an error. Btrfs calculates the checksum of the data before it is written to disk data. Then write the checksum and data to disk at the same time.

Sub-volume: Subvolume is a very elegant concept. That is, part of the file system is configured as a complete sub-file system, called subvolume.

With subvolume, a large file system can be divided into multiple sub-file systems that share the underlying device space and allocate it from the underlying device when disk space is needed, just as an application calls malloc () to allocate memory. You can call it a storage pool. This model has many advantages, such as making full use of the bandwidth of disk and simplifying the management of disk space.

Snapshots: snapshots that support snapshots

Transparent compression: the process of calling data by the user is actually a process of decompression, but this process is transparent and automatic to the user.

Multi-device management: Btrfs supports dynamic addition of devices. After you add a new disk to the system, you can use the btrfs command to add the device to the file system. To make flexible use of device space, Btrfs divides disk space into multiple chunk. Each chunk can use a different disk space allocation strategy. For example, some chunk only store metadata, and some chunk store only data. Some chunk can be configured as mirror, while others chunk can be configured as stripe. This provides users with a very flexible configuration possibility.

File system creation:

Mkfs.btrfs

-L 'LABEL': establishes a volume label.

-d: raid0, raid1, raid5, raid6, raid10, single refer to the type of file system specified

-m: raid0, raid1, raid5, raid6, raid10, single, dup indicates the type

-O indicates that formatting is the feature of startup.

-O list-all: lists all supported feature

Mount the file system:

Mount-t btrfs / dev/sdb MOUNT_POINT

Transparent compression mechanism:

Mount-o compress= {lzo | zlib} DEVICE MOUNT_POINT

The following is the use of the btrfs file subcommand:

Btrfs filesystem show: displaying details of

Btrfs filesystem show-- mounted: displays the details of the mounted file system

Btrfs filesystem show-- all-device: displays the details of all file systems

Btrfs filesystem show / PATH: displays the details of the specified file system

Btrfs filesystem label: displays the label of the file system

Btrfs filesystem resize: reduce or increase the capacity of a file system

Btrfs filesystem df: displays information about mounted file systems

Btrfs filesystem sync synchronous operation

Next, let's do it, as shown in the following figure:

1.mkfs.btrfs-L mydata / dev/sdb / dev/sdc: format two hard drives, sdb and sdc, into a file system marked with volume mydata

Either 2.mount / dev/sdb or / dev/sdc can be mounted

3.btrfs filesystem df / mnt can see the details of the mounted file system

Then we use the blkid command to check / dev/sdc and / dev/sdb, respectively.

From the figure below, we can see that their UUID is the same, but the sub-UUID is different, so it supports multi-volume.

Through these two commands, btrfs filesystem resize-10G / MYDATA df-lh can see that the size of the Btree system has been reduced to 30g.

Btrfs filesystem resize + 10G / MYDATA df-lh and then I added it back to 40G.

As shown below:

Now let's get to know the following subcommands of btrfs device:

Btrfs device add: adding Devic

Btrfs device delete: remove or remove devices from the file system

Btrfs device ready:

Btrfs device stats [- z] |:

From the above execution result, we can see that the newly added utilization of / dev/sdd is 0, how to distribute evenly, and then we use the subcommand of btrfs balance:

Btrfs balance start: start balancing the file system

Btrfs balance start-dconvert: the organizational mechanism for modifying data, that is, raid level

Btrfs balance start-mconvert organization mechanism for modifying metadata, that is, raid level

Btrfs balance start-sconvert: modify the organizational mechanism of the system, that is, the raid level

Btrfs balance pause: stop

Btrfs balance cancel cancel

Btrfs balance resume, continue.

Btrfs balance status to view the equilibrium status

The following figure shows the process of equilibrium.

From the figure below, we can see that after we remove a device, the contents of the previous Btree system can also be viewed, indicating that Btree can automatically save the files that uninstall the device to other places.

You can see from the image above that we can change the raid level of the Btree file system or the data and metadata stored in it.

If we want to subvolume the Btree file system, we have the following command to choose from:

Btrfs subvolume create: creating subvolumes

Btrfs subvolume delete deletes a subvolume

Btrfs subvolume list: lists all subvolumes

Btrfs subvolume snapshot |: create a snapshot

Btrfs subvolume get-default: default Volum

Btrfs subvolume set-default: setting default volum

Btrfs subvolume show: used to view the details of the subvolume

In the process of creating a child volume, if the parent volume is mounted, it means that the child volume is also mounted. If you want to mount it separately, you have to unmount the parent volume first.

The following figure shows the process of mounting a subvolume:

The following is the process of creating a snapshot:

The above introductions are the superficial knowledge of a beginner. If there is any inappropriate place, please correct and revise it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report