您的位置:首页 > 其它

Btrfs文件系统及应用

2015-12-20 13:29 344 查看
一、Btrfs文件系统简介 Btrfs透明压缩文件系统 (B-tree, Butter FS, Better FS)是一种COW(copy-on-write式)文件系统,有着传统文件系统(ext3/4)所没有的一些特性,如支持可写的磁盘快照(snapshots),以及支持递归的快照(snapshots of snapshots),支持内建磁盘阵列(RAID),支持子卷(Subvolumes)的概念,允许在线调整文件系统大小等。

二、核心特性及命令核心特性:1、多物理卷支持:btrfs可由多个底层物理卷组成;支持RAID,以联机“添加”、“移除”,“修改”;2、写时复制更新机制(CoW):复制、更新及替换指针,而非“就地”更新;3、数据及元数据校验码:checksum4、子卷:sub_volume,子卷实质上是一个保存文件和目录的命名的B树。它们的inode保存在树根之树中,可以为非根用户和组所有。子卷可选设定块配额。子卷内的所有块和文件区段都有引用计数以便做快照。和虚拟机存储的动态扩展相似,其只按需使用设备空间,消除了许多半满的分区。用户也可用不同的挂载选项挂载子卷,得到更灵活的安全性。5、快照:支持快照的快照; 命令:btrfs subvolume snapshot6、透明压缩:分区里的每个文件都被自动压缩,不仅减小了文件的大小,还提高了性能。7、Btrfs支持在线碎片整理。命令: btrfs filesystem defragment 相关命令:1、文件系统创建:命令: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; 2、文件系统命令管理,包括卷标管理,文件系统大小调整,及碎片管理命令:btrfs filesystem< subcommand> <args> 属性查看:btrfs filesystem show 3、挂载文件系统:命令:mount -t btrfs /dev/sdb MOUNT_POINT 4、透明压缩机制:命令:mount -o compress={lzo|zlib} DEVICE MOUNT_POINT 5、 管理子卷和快照命令命令:btrfs subvolume< subcommand> [<args>] 6、设备管理命令命令:btrfs device< subcommand> <args> 7、块组均衡管理命令:btrfs [filesystem] balance <subcommand>|<args> 三、实验1、创建btrfs文件系统 在vmware中新增两块20G磁盘,/dev/sdb与/dev/sdc[root@localhost ~]# mkfs.btrfs -L 'B-tree-fs' -f /dev/sd{b,c}[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 2 FS bytes used 112.00KiBdevid 1 size 20.00GiB used 2.03GiB path /dev/sdbdevid 2 size 20.00GiB used 2.01GiB path /dev/sdc 2、挂载文件系统[root@localhost ~]# mkdir /btrdata[root@localhost ~]# mount /dev/sdb /btrdata [root@localhost ~]# df -h | grep btrdata/dev/sdb 40G 1.0M 38G 1% /btrdata 3、建立子卷[root@localhost ~]# btrfs subvolume create /btrdata/mydataCreate subvolume '/btrdata/mydata'[root@localhost ~]# cp -r /root/* /btrdata/mydata # 复制数据[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 2 FS bytes used 735.67MiBdevid 1 size 20.00GiB used 2.03GiB path /dev/sdbdevid 2 size 20.00GiB used 2.01GiB path /dev/sdc 4、扩展文件系统[root@localhost ~]# btrfs device add /dev/sdd /btrdata[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 3 FS bytes used 735.67MiBdevid 1 size 20.00GiB used 2.03GiB path /dev/sdbdevid 2 size 20.00GiB used 2.01GiB path /dev/sdcdevid 3 size 20.00GiB used 0.00 path /dev/sdd[root@localhost ~]# df -h | grep btrdata/dev/sdb 60G 772M 56G 2% /btrdata 5、重新均衡文件系统[root@localhost ~]# btrfs balance start /btrdataDone, had to relocate 6 out of 6 chunks[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 3 FS bytes used 736.20MiBdevid 1 size 20.00GiB used 1.03GiB path /dev/sdbdevid 2 size 20.00GiB used 2.00GiB path /dev/sdcdevid 3 size 20.00GiB used 2.03GiB path /dev/sdd 6、移除硬盘 移除硬盘的时候会先把数据移动到其他盘,不需要像LVM那样需要手动移动数据[root@localhost ~]# btrfs device delete /dev/sdb /btrdata[root@localhost ~]# df -h | grep btrdata/dev/sdc 40G 772M 38G 2% /btrdata[root@localhost ~]# ls /btrdata/commdir mydata[root@localhost ~]# head /btrdata/mydata/anaconda-ks.cfg#version=RHEL7# System authorization informationauth --enableshadow --passalgo=sha512 # Use CDROM installation mediacdrom# Use graphical installgraphical# Run the Setup Agent on first bootfirstboot --enable 7、修改数据或元数据的RAID级别[root@localhost ~]# btrfs device add /dev/sdb /btrdata[root@localhost ~]# btrfs filesystem df /btrdataData, RAID0: total=2.00GiB, used=699.96MiBSystem, RAID1: total=32.00MiB, used=16.00KiBMetadata, RAID1: total=1.00GiB, used=35.98MiBGlobalReserve, single: total=16.00MiB, used=0.00 [root@localhost ~]# btrfs balance start -mconvert=raid5 /btrdata # 此处修改元数据RAID级别Done, had to relocate 2 out of 3 chunks[root@localhost ~]# btrfs filesystem df /btrdataData, RAID0: total=2.00GiB, used=700.21MiBSystem, RAID5: total=64.00MiB, used=16.00KiBMetadata, RAID5: total=1.00GiB, used=35.91MiBGlobalReserve, single: total=16.00MiB, used=0.00[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 3 FS bytes used 735.89MiBdevid 2 size 20.00GiB used 1.53GiB path /dev/sdcdevid 3 size 20.00GiB used 1.53GiB path /dev/sdddevid 4 size 20.00GiB used 544.00MiB path /dev/sdb 8、创建快照[root@localhost ~]# btrfs subvolume snapshot /btrdata/mydata /btrdata/mydata_snapshotCreate a snapshot of '/btrdata/mydata' in '/btrdata/mydata_snapshot'[root@localhost ~]# cat /btrdata/mydata/1.txt1[root@localhost ~]# echo 'just a test' >> /btrdata/mydata/1.txt[root@localhost ~]# cat /btrdata/mydata/1.txt1just a test[root@localhost ~]# cat /btrdata/mydata_snapshot/1.txt19、转换[root@localhost ~]# btrfs balance start -dconvert=single -mconvert=raid1 /btrdataDone, had to relocate 3 out of 3 chunks[root@localhost ~]# btrfs device delete /dev/sdd /btrdata[root@localhost ~]# fdisk /dev/sddWelcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them.Be careful before using the write command. Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0xadd41340. Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): 1First sector (2048-41943039, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5GPartition 1 of type Linux and of size 5 GiB is set Command (m for help): wThe partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.[root@localhost ~]# mke2fs -t ext4 /dev/sdd1mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310720 blocks65536 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done [root@localhost ~]# fsck -f /dev/sdd1fsck from util-linux 2.23.2e2fsck 1.42.9 (28-Dec-2013)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/sdd1: 12/327680 files (0.0% non-contiguous), 58463/1310720 blocks[root@localhost ~]# btrfs-convert /dev/sdd1 # 将ext4文件系统转换为btrfscreating btrfs metadata.creating ext2fs image file.cleaning up system chunk.conversion complete.[root@localhost ~]# btrfs filesystem showLabel: 'B-tree-fs' uuid: b254b565-0418-4601-8317-f9a5306c6f19Total devices 2 FS bytes used 735.81MiBdevid 2 size 20.00GiB used 2.03GiB path /dev/sdcdevid 4 size 20.00GiB used 1.03GiB path /dev/sdb Label: none uuid: 12170ec7-9847-4a5a-85ee-13215a478a3cTotal devices 1 FS bytes used 228.42MiBdevid 1 size 5.00GiB used 5.00GiB path /dev/sdd1 Btrfs v3.16.2[root@localhost ~]# btrfs-convert -r /dev/sdd1 # 将btrfs文件系统回滚原来的文件系统rollback complete.[root@localhost ~]# blkid /dev/sdd1/dev/sdd1: UUID="fbbd653f-fb3f-4715-8c42-8c942564c8f4" TYPE="ext4"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: