btrfs文件系统简介及centos7下实例

author author     2022-08-01     660

关键词:

btrfs文件系统简介及CentOS7下实例

由Oracle于2007年宣布并进行中的COW(copy-on-write式)文件系统。目标是取代Linux目前的ext3文件系统,改善ext3的限制,特别是单一文件大小的限制,总文件系统大小限制以及加入文件校验和特性。加入目前ext3/4未支持的一些功能,例如可写的磁盘快照(snapshots),以及支持递归的快照(snapshots of snapshots),内建磁盘阵列(RAID)支持,支持子卷(Subvolumes)的概念,允许在线调整文件系统大小。(自百度百科)


以下自马哥课程笔记和CentOS7帮助文档:

核心特性:

    多物理卷支持:btrfs可由多个底层物理卷组成;支持RAID,以联机“添加”、“移除”,“修改”;

    支持写时复制更新机制(CoW):复制、更新及替换指针,而非“就地”更新;

    支持数据及元数据校验码:checksum

    支持子卷:sub_volume

    支持快照:支持快照的快照;

    支持透明压缩;

命令介绍:

    文件系统创建:

        mkfs.btrfs

        -L ‘LABEL‘

        -d <type>: raid0, raid1, raid5, raid6, raid10, single

        -m <profile>: raid0, raid1, raid5, raid6, raid10, single, dup

        -O <feature>

        -O list-all: 列出支持的所有feature;


    属性查看:

        btrfs filesystem show [--mounted|--all-devices|<path>|<uuid>|<device>|<label>]

        or

        blkid [DEVICE]

    管理命令介绍:

        btrfs文件系统管理命令使用子命令的方式进行管理,具体了命令的功能可通过man SUBCOMMEND来查看。

        btrfs命令的常用子命令:filesystem, device, balance, subvolume


btrfs:

NAME

      btrfs - control a btrfs filesystem

SYNOPSIS

      btrfs <command> [<args>]

COMMANDS

    balance

       Balance btrfs filesystem chunks across single or several devices.

       See btrfs-balance(8) for details.

    check

       Do off-line check on a btrfs filesystem.

       See btrfs-check(8) for details.

    device

       Manage devices managed by btrfs, including add/delete/scan and so on.

       See btrfs-device(8) for details.

    filesystem

       Manage a btrfs filesystem, including label setting/sync and so on.

       See btrfs-filesystem(8) for details.   

    receive

       Receive subvolume data from stdin/file for restore and etc.

       See btrfs-receive(8) for details.

    replace

       Replace btrfs devices.

       See btrfs-replace(8) for details.  

    subvolume

       Create/delete/list/manage btrfs subvolume.

       See btrfs-subvolume(8) for details.          

                  

btrfs filesystem:

NAME

      btrfs-filesystem - control btrfs filesystem

SYNOPSIS

      btrfs filesystem <subcommand> <args>

SUBCOMMAND

    df [options] <path>

      Show space usage information for a mount point.

    show [--mounted|--all-devices|<path>|<uuid>|<device>|<label>]

        Show the btrfs filesystem with some additional info.

    resize [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>

        Resize a filesystem identified by <path> for the underlying device devid online.

        不常用,一般调整子卷。

    label [<dev>|<mountpoint>] [<newlabel>]

        Show or update the label of a filesystem.


btrfs device:

NAME

      btrfs-device - control btrfs devices

SYNOPSIS

      btrfs device <subcommand> <args>       

DEVICE MANAGEMENT      

    RAID level

       Btrfs filesystem supports most of the standard RAID level: 0/1/5/6/10.

    Balance

       btrfs-balance(8) subcommand can be used to balance or rebuild chunks to the desired profile.

    Device add/remove/replace

       Device can be added/removed using btrfs-replace(8) subcommand and replaced using btrfs-replace(8).

       When device is removed or replaced, btrfs will do the chunk rebuild if needed.     

SUBCOMMAND

    add [-Kf] <dev> [<dev>...] <path>

       Add device(s) to the filesystem identified by <path>.

    delete <dev> [<dev>...] <path>

       Remove device(s) from a filesystem identified by <path>.

       拆除物理卷时会自动迁移要移除的物理卷中的数据。

    ready <device>

       Check device to see if it has all of it’s devices in cache for mounting.

    scan [(--all-devices|-d)|<device> [<device>...]]

       Scan devices for a btrfs filesystem.

    stats [-z] <path>|<device>

       Read and print the device IO stats for all devices of the filesystem identified by <path> or for a single <device>.                

                      

btrfs balance:

NAME

      btrfs-balance - balance btrfs filesystem

SYNOPSIS

      btrfs balance <subcommand> <args>       

SUBCOMMAND

    cancel <path>

       Cancel running or paused balance.

    pause <path>

       Pause running balance.

    resume <path>

       Resume interrupted balance.

    start [options] <path>

       Balance chunks across the devices online.

       Options:

       -d[<filters>]

           act on data chunks. See FILTERS section for details about <filters>.

           修改数据的组织机制。

       -m[<filters>]

           act on metadata chunks. See FILTERS section for details about <filters>.

           修改元数据的组织机制。

       -s[<filters>]

           act on system chunks (only under -f). See FILTERS section for details about <filters>.

       -v

           be verbose

       -f

           force reducing of metadata integrity

    status [-v] <path>

       Show status of running or paused balance.

       If -v option is given, output will be verbose.

FILTERS

    convert

        Convert each selected block group to the given profile name identified by parameters.


btrfs subvolume:

NAME

      btrfs-subvolume - control btrfs subvolume(s)

SYNOPSIS

      btrfs subvolume <subcommand> [<args>]

DESCRIPTION

      btrfs subvolume is used to control the filesystem to create/delete/list/show subvolumes and snapshots.

SUBCOMMAND

    create [-i <qgroupid>] [<dest>]<name>

       Create a subvolume <name> in <dest>.

       If <dest> is not given, subvolume <name> will be created in the currently directory.

    Options

       -i <qgroupid>

           Add the newly created subvolume to a qgroup. This option can be given multiple times.

    delete [options] <subvolume> [<subvolume>...]

       -c|--commit-after

           wait for transaction commit at the end of the operation

       -C|--commit-each

           wait for transaction commit after delet each subvolume

    list <path>

       List the subvolumes present in the filesystem <path>.

    snapshot [-r] <source> <dest>|[<dest>/]<name>  


    挂载文件系统:

        mount -t btrfs /dev/sdb MOUNT_POINT


    启用透明压缩机制:

        压缩和解压缩自动透明运行,启用后会增加CPU负载

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


btrfs文件系统管理实例:

    (1)、CentOS7中加载磁盘设备(多块);

            如/dev/sd{b,c,d};


    (2)、将硬盘格式化为btrfs文件系统;

            命令:# mkfs.btrfs -L MYDATA /dev/sd{b,c}

            查看:# btrfs filesystem show


    (3)、挂载btrfs文件系统;

            命令:# mount -t btrfs /dev/sdc /mydata/

                设备可为任意一个btrfs设备名,如/dev/sdb或/dev/sdc

                启用透明压缩机制(可选):# mount -t btrfs -o compress=lzo /dev/sdc /mydata/


    (4)、在线调整btrfs文件系统空间大小;

            命令:# btrfs filesystem resize -20G /mydata/


    (5)、btrfs文件系统中添加/删除磁盘设备;

            添加设备命令:# btrfs device add /dev/sdb /mydata/

            删除设备命令:# btrfs device delete /dev/sdd /mydata/


    (6)、调整数据分部,使数据均衡的分部到各磁盘设备;

            启动balance:# btrfs balance start /mydata/

            查看balance运行时的状态:# btrfs balance status /mydata/


    (7)、动态修改磁盘设备卷的RAID级别;

            修改数据的RIAD级别为RAID5:# btrfs balance start -dconvert=raid5 /mydata/

            修改元数据的RIAD级别为RAID5:# btrfs balance start -mconvert=raid5 /mydata/

            检查:# btrfs filesystem df /mydata/


    (8)、btrfs文件系统上创建和管理子卷;

            查看子卷信息:# btrfs subvolume list /mydata/

            创建子卷,结果类似于在父卷下创建子目录:

# btrfs subvolume create /mydata/bin
ID 269 gen 133 top level 5 path bin//ID 269为该子卷的ID号

            单独挂载子卷,如果挂载父卷,则父卷下的所有子卷都会自动挂载:

                1) # umount /mydata///首先卸载父卷

                2) # mount -o subvol=logs /dev/sdb /mnt///使用子卷名挂载

                    or

                    # mount -o subvolid=269 /dev/sdb /mnt///使用子卷ID挂载

            查看子卷的详细信息:

# btrfs subvolume show /mnt

            删除子卷:

# btrfs subvolume delete /mydata/bin/


    (9)、btrfs文件系统中子卷和文件快照的管理和使用;

            创建子卷快照:# btrfs subvolume snapshot /mydata/logs/ /mydata/logs_snapshot               //子卷的快照必须和该子卷在同一父卷下。

            查看子卷是否生成:# btrfs subvolume list /mydata/

            挂载/删除btrfs文件系统子卷快照的方法和挂载/删除子卷一致:

                挂载子卷:

# mount -o subvolid=269 /dev/sdb /mnt/

                删除子卷快照:

# btrfs subvolume delete /mydata/logs_snapshot/

            创建文件快照:

# cp --reflink /mydata/fstab /mydata/fstab_snap


    (10)、ext4和btrfs文件系统转换;

            ext4 to btrfs:

                1) 首先卸载原ext4文件系统的磁盘,并强制检测:

# umount /mnt/; fsck -f /dev/sdd1

                2) 使用btrfs-convert转换文件系统:

# btrfs-convert /dev/sdd1 
creating btrfs metadata.
copy inodes [o] [         0/        12]
creating ext2fs image file.
cleaning up system chunk.
conversion complete.

                3) 检查btrfs文件系统是否完成转换:

# btrfs filesystem show

                4) 挂载使用:

# mount /dev/sdd1 /mnt/

            btrfs to ext4:

                1) 卸载文件系统:# umount /mnt/

                2)btrfs降级为ext4:

# btrfs-convert -r /dev/sdd1 
rollback complete.

                3) 检查:

# blkid /dev/sdd1
/dev/sdd1: UUID="af904001-4dac-4b10-87b5-8ff9c06f9e36" TYPE="ext4"


    (11)、拆除btrfs文件系统;

            1) 拆除前首先需要确认当前数据和无数据的RAID是否满足RAID的最少设备限制,若不满足修改之。若全部拆除可修改为single。

                查看当前设备卷的RAID状态:

# btrfs filesystem df /mydata/
Data, RAID5: total=2.00GiB, used=788.00KiB
System, RAID5: total=64.00MiB, used=16.00KiB
Metadata, RAID5: total=1.00GiB, used=144.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B

                修改数据和元数据的RAID级别:

# btrfs balance start -mconvert=single /mydata/
# btrfs balance start -f -mconvert=single /mydata/

                检查:

# btrfs filesystem df /mydata/
Data, single: total=1.00GiB, used=532.00KiB
System, single: total=32.00MiB, used=16.00KiB
Metadata, single: total=1.00GiB, used=144.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B

            2) 删除btrfs卷中的磁盘卷:

# btrfs device delete /dev/sdd /mydata/


本文出自 “银凯的博客” 博客,请务必保留此出处http://yinkai.blog.51cto.com/3813923/1843653

btrfs文件系统学习及练习

###########################################################################################    Btrfs(通常念成ButterFS),由Oracle于2007年宣布并进行中的COW(copy-on-write式)文件系统。目标是取代Linux目前的ext3文件系统 查看详情

btrfs文件系统学习

btrfs文件系统由Oracle开发,btrfs设计目标为取代早期ext文件系统。核心特性:1.多物理卷支持:btrfs可由多个底层物理卷组成,支持RAID,以联机“添加”、“移除”、“修改”。2.写时复制更新机(COW):复制、更新及替换指针,而... 查看详情

centos7系统运行级别简介

centos7系统运行级别简介我们知道,centos6及之前的版本中,系统运行级别通过/etc/inittab文件进行设置和控制,但在centos7中,对这个文件的设置将不会对系统运行级别产生影响,这也是centos7中变化比较大的一部分特性。下面,我... 查看详情

btrfs文件系统简单学习

1btrfs文件系统  btrfs文件系统在生产环境应用还不多,技术还不太成熟,因此,本文仅仅简单学习.1.1 btrfs文件系统核心特性  1)多物理卷支持:btrfs可由多个底层物理卷组成(可以是单块物理磁盘,也可以是某一分区等);支持RAI... 查看详情

btrfs文件系统管理与应用

...:sub_volume快照:支持快照的快照(增量快照)透明压缩文件系统 查看详情

btrfs

btrfs文件系统: 技术预览版 核心特征: 多物理卷支持:btrfs可以由多个底层物理卷组成:支持RAID,以联机“添加”,“删除”,“修改” 写时复制更新:复制,更新及替换指针,而非“就地”更新 数据及元数据校验码:checksu... 查看详情

linuxbtrfs文件系统及管理

参考技术ALinuxbtrfs文件系统及管理  linux文件系统,具有写时复制COW(copy-on-write),改善ext3文件系统单文件大小限制,并加入其他特性,如可写快照,快照的快照,内建RAID,子卷(subvloume),专注于容错,修复和易于管理,下面一起... 查看详情

btrfs学习笔记

一、Btrfs文件系统Btrfs(B-tree,ButterFS,BetterFS),Oracle从2007年开始研发的一种新的文件系统,目标是用于取代ext3和ext4文件系统,2014年8月发布稳定版本;采用GPL授权.1.1Btrfs文件系统特性多物理卷支持:Btrfs可由多个底层物理卷组成;支持RAID,以... 查看详情

lvm2逻辑卷创建及扩容

...中有一定的使用场景,在CentOS5、6系统中经常会见到,从CentOS7以后默认的文件系统由ext4改为btrfs,而btrfs也支持空间的动态扩展和收缩,所以在CentOS7以后的系统中再使用LVM就是不明智的选择了二、LVM原理介绍在介绍LVM之前首先需... 查看详情

docker存储驱动之btrfs简介

简介Btrfs是下一代的copy-on-write文件系统,它支持很多高级特性,使其更加适合Docker。Btrfs合并在内核主线中,并且它的on-disk-format也逐渐稳定了。不过,它的很多特性还仍然处于开发中。Docker的btrfs存储驱动利用了很多Btrfs特性来... 查看详情

centos7安装简介及基本操作

计算机基本概念:1、计算机硬件组成:2、计算机系统结构:3、操作系统的功能:硬件驱动、进程管理、内存管理、网络管理、安全管理、文件管理等。4、OS通用目的的软件程序:用户<-->应用软件<-->操作系统<-->硬... 查看详情

btrfs的介绍与使用

...现还不是很明白,还需要研究,在此做个记号。Btrfs简介文件系统似乎是内核中比较稳定的部分,多年来,人们一直使用ext2/3,ext文件系统以其卓越的稳定性成为了事实上的Linux标准文件系统。 查看详情

#12btrfs文件系统

btrfs TechnicalPreview,技术预览版 BtrFS(B-tree文件系统,又称为ButterFS或BetterFS),2007由oracle开源后,得到了IBM、intel等厂商的大力支持,其目标计划是替代linux目前的ext3/4,成为下一代linux标准的文件系统。 运行在linux上,并遵循GPL... 查看详情

btrfs文件系统

文档:btrfs文件系统.note链接:http://note.youdao.com/noteshare?id=9a54dbb303a8e629147ee6d8da17e007&sub=40582DAB28DC42C5A6AD56F23867F681 查看详情

centos7相关命令

...但命令的语法与使用方法基本相同,因此读者只要掌握了CentOS7中常用的基础命令,就能熟悉其他Linux系统版本的命令了。本章通过分类方式来介绍常用基础命令的语法与使用方法。3.1系统管理命令3.1.1man命令1.功能说明man命令用... 查看详情

btrfs文件系统笔记

    发现一篇美文,先贴上链接,后续填坑。https://www.ibm.com/developerworks/cn/linux/l-cn-btrfs/index.html#ibm-pconhttp://www.ibm.com/developerworks/cn/linux/l-cn-btrfs/index.html#ibm-pcon本文出自“799540 查看详情

btrfs文件系统的简单使用方法

简单介绍btrfs文件系统的使用,包括创建、挂载、子卷的创建、挂载、快照、在线添加和移除物理设备、重新均衡数据btrfs的特性:    多块磁盘支持:btrfs可由多个底层磁盘组成,支持RAID,可以联机添加、移除、... 查看详情

btrfs

btrfs TechnicalPreview,技术预览版 BtrFS(B-tree文件系统,又称为ButterFS或BetterFS),2007由oracle开源后,得到了IBM、intel等厂商的大力支持,其目标计划是替代linux目前的ext3/4,成为下一代linux标准的文件系统。 运行在linux上,并遵循GPL... 查看详情