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

本文发布时间: 2019-Mar-22
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>]orblkid [DEVICE]管理命令介绍:btrfs文件系统管理命令使用子命令的方式进行管理,具体了命令的功能可通过man SUBCOMMEND来查看。btrfs命令的常用子命令:filesystem, device, balance, subvolumebtrfs:NAME btrfs - control a btrfs filesystemSYNOPSIS btrfs <command> [<args>]COMMANDSbalance 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 filesystemSYNOPSIS btrfs filesystem <subcommand> <args>SUBCOMMANDdf [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 devicesSYNOPSIS 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. SUBCOMMANDadd [-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 filesystemSYNOPSIS btrfs balance <subcommand> <args> SUBCOMMANDcancel <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 integritystatus [-v] <path> Show status of running or paused balance. If -v option is given, output will be verbose.FILTERSconvertConvert 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.SUBCOMMANDcreate [-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 subvolumelist <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_POINTbtrfs文件系统管理实例:(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/创建子卷,结果类似于在父卷下创建子目录:#btrfssubvolumecreate/mydata/binID269gen133toplevel5pathbin//ID269为该子卷的ID号单独挂载子卷,如果挂载父卷,则父卷下的所有子卷都会自动挂载:1) # umount /mydata///首先卸载父卷2) # mount -o subvol=logs /dev/sdb /mnt///使用子卷名挂载or# mount -o subvolid=269 /dev/sdb /mnt///使用子卷ID挂载查看子卷的详细信息:#btrfssubvolumeshow/mnt删除子卷:#btrfssubvolumedelete/mydata/bin/(9)、btrfs文件系统中子卷和文件快照的管理和使用;创建子卷快照:# btrfs subvolume snapshot /mydata/logs/ /mydata/logs_snapshot//子卷的快照必须和该子卷在同一父卷下。查看子卷是否生成:# btrfs subvolume list /mydata/挂载/删除btrfs文件系统子卷快照的方法和挂载/删除子卷一致:挂载子卷:#mount-osubvolid=269/dev/sdb/mnt/删除子卷快照:#btrfssubvolumedelete/mydata/logs_snapshot/创建文件快照:#cp--reflink/mydata/fstab/mydata/fstab_snap(10)、ext4和btrfs文件系统转换;ext4 to btrfs:1) 首先卸载原ext4文件系统的磁盘,并强制检测:#umount/mnt/;fsck-f/dev/sdd12) 使用btrfs-convert转换文件系统:#btrfs-convert/dev/sdd1creatingbtrfsmetadata.copyinodes[o][0/12]creatingext2fsimagefile.cleaningupsystemchunk.conversioncomplete.3) 检查btrfs文件系统是否完成转换:#btrfsfilesystemshow4) 挂载使用:#mount/dev/sdd1/mnt/btrfs to ext4:1) 卸载文件系统:# umount /mnt/2)btrfs降级为ext4:#btrfs-convert-r/dev/sdd1rollbackcomplete.3) 检查:#blkid/dev/sdd1/dev/sdd1:UUID="af904001-4dac-4b10-87b5-8ff9c06f9e36"TYPE="ext4"(11)、拆除btrfs文件系统;1) 拆除前首先需要确认当前数据和无数据的RAID是否满足RAID的最少设备限制,若不满足修改之。若全部拆除可修改为single。查看当前设备卷的RAID状态:#btrfsfilesystemdf/mydata/Data,RAID5:total=2.00GiB,used=788.00KiBSystem,RAID5:total=64.00MiB,used=16.00KiBMetadata,RAID5:total=1.00GiB,used=144.00KiBGlobalReserve,single:total=16.00MiB,used=0.00B修改数据和元数据的RAID级别:#btrfsbalancestart-mconvert=single/mydata/#btrfsbalancestart-f-mconvert=single/mydata/检查:#btrfsfilesystemdf/mydata/Data,single:total=1.00GiB,used=532.00KiBSystem,single:total=32.00MiB,used=16.00KiBMetadata,single:total=1.00GiB,used=144.00KiBGlobalReserve,single:total=16.00MiB,used=0.00B2) 删除btrfs卷中的磁盘卷:#btrfsdevicedelete/dev/sdd/mydata/


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2020-Jul-13 01:12am
栏目列表