什么是btrfs?
Btrfs(B-tree文件系统,通常念成Butter FS,Better FS或B-tree FS),linux文件系统,具有写时复制COW(copy-on-write),改善ext3文件系统单文件大小限制,并加入其他特性,如可写快照,快照的快照,内建RAID,子卷(subvloume),专注于容错,修复和易于管理。单文件可达16EB,最大文件数量2^64,最大卷容量16EB,等。
btrfs功能特性
1,COW:写时复制,每次写入数据时,先将数据写入到新的block,写入成功后,更改旧数据块指针到新数据块,而非更改本身。 2,多物理卷支持,btrfs内建raid,可在线增删磁盘设备,可在线扩展和缩减磁盘空间。 3,数据和元数据校验码,checksum 4,子卷,可单独挂载子卷 5,可写快照,快照的快照,单个文件快照。 6,透明压缩 7,ext3/4和btrfs无痛互转
btrfs 基本用法:
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- usage: btrfs [--help] [--version] <group> [<group>...] <command> [<args>]
- btrfs subvolume create [-i <qgroupid>] [<dest>/]<name>
- Create a subvolume
- btrfs subvolume delete [options] <subvolume> [<subvolume>...]
- Delete subvolume(s)
- btrfs subvolume list [options] [-G [+|-]value] [-C [+|-]value] [--sort=gen,ogen,rootid,path] <path>
- List subvolumes (and snapshots)
- btrfs subvolume snapshot [-r] [-i <qgroupid>] <source> <dest>|[<dest>/]<name>
- Create a snapshot of the subvolume
- btrfs subvolume get-default <path>
- Get the default subvolume of a filesystem
- btrfs subvolume set-default <subvolid> <path>
- Set the default subvolume of a filesystem
- btrfs subvolume find-new <path> <lastgen>
- List the recently modified files in a filesystem
- btrfs subvolume show <subvol-path>
- Show more information of the subvolume
- btrfs subvolume sync <path> [<subvol-id>...]
- Wait until given subvolume(s) are completely removed from the filesystem.
- btrfs filesystem df [options] <path>
- Show space usage information for a mount point
- btrfs filesystem show [options] [<path>|<uuid>|<device>|label]
- Show the structure of a filesystem
- btrfs filesystem sync <path>
- Force a sync on a filesystem
- btrfs filesystem defragment [options] <file>|<dir> [<file>|<dir>...]
- Defragment a file or a directory
- btrfs filesystem resize [devid:][+/-]<newsize>[kKmMgGtTpPeE]|[devid:]max <path>
- Resize a filesystem
- btrfs filesystem label [<device>|<mount_point>] [<newlabel>]
- Get or change the label of a filesystem
- btrfs filesystem usage [options] <path> [<path>..]
- Show detailed information about internal filesystem usage .
- btrfs balance start [options] <path>
- Balance chunks across the devices
- btrfs balance pause <path>
- Pause running balance
- btrfs balance cancel <path>
- Cancel running or paused balance
- btrfs balance resume <path>
- Resume interrupted balance
- btrfs balance status [-v] <path>
- Show status of running or paused balance
- btrfs device add [options] <device> [<device>...] <path>
- Add a device to a filesystem
- btrfs device delete <device> [<device>...] <path>
- Remove a device from a filesystem
- btrfs device scan [(-d|--all-devices)|<device> [<device>...]]
- Scan devices for a btrfs filesystem
- btrfs device ready <device>
- Check device to see if it has all of its devices in cache for mounting
- btrfs device stats [-z] <path>|<device>
- Show current device IO stats. -z to reset stats afterwards.
- btrfs device usage [options] <path> [<path>..]
- Show detailed information about internal allocations in devices.
btrfs文件系统管理
为分区创建btrfs文件系统
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
- Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
- Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
- Disk /dev/sde: 21.5 GB, 21474836480 bytes, 41943040 sectors
- Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors
创建单分区btrfs并查看
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- btrfs-progs v3.19.1
- See http://btrfs.wiki.kernel.org for more information.
- Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
- Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
- fs created label btrfs on /dev/sdb
- nodesize 16384 leafsize 16384 sectorsize 4096 size 20.00GiB
- [root@localhost ~]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 1 FS bytes used 112.00KiB
- devid 1 size 20.00GiB used 2.04GiB path /dev/sdb
- btrfs-progs v3.19.1
- [root@localhost ~]
- [root@localhost ~]
- Data, single: total=8.00MiB, used=256.00KiB
- System, DUP: total=8.00MiB, used=16.00KiB
- System, single: total=4.00MiB, used=0.00B
- Metadata, DUP: total=1.00GiB, used=112.00KiB
- Metadata, single: total=8.00MiB, used=0.00B
- GlobalReserve, single: total=16.00MiB, used=0.00B
再添加一块磁盘
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- [root@localhost ~]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 2 FS bytes used 384.00KiB
- devid 1 size 20.00GiB used 2.04GiB path /dev/sdb
- devid 2 size 20.00GiB used 0.00B path /dev/sdc
- btrfs-progs v3.19.1
- [root@localhost ~]
在线增加或缩减空间,在线改变空间,可以让lvm坐冷板凳了。
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- Resize '/btrfs/' of '-10G'
- [root@localhost ~]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 2 FS bytes used 384.00KiB
- devid 1 size 10.00GiB used 2.04GiB path /dev/sdb
- devid 2 size 20.00GiB used 0.00B path /dev/sdc
- btrfs-progs v3.19.1
- [root@localhost ~]
- Resize '/btrfs/' of '+7G'
- [root@localhost ~]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 2 FS bytes used 384.00KiB
- devid 1 size 17.00GiB used 2.04GiB path /dev/sdb
- devid 2 size 20.00GiB used 0.00B path /dev/sdc
- btrfs-progs v3.19.1
- [root@localhost ~]
在线更改数据和元数据的结构
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- Data, single: total=8.00MiB, used=256.00KiB
- System, DUP: total=8.00MiB, used=16.00KiB
- System, single: total=4.00MiB, used=0.00B
- Metadata, DUP: total=1.00GiB, used=112.00KiB
- Metadata, single: total=8.00MiB, used=0.00B
- GlobalReserve, single: total=16.00MiB, used=0.00B
- [root@localhost ~]
- Done, had to relocate 4 out of 5 chunks
- [root@localhost ~]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 2 FS bytes used 192.00KiB
- devid 1 size 17.00GiB used 296.00MiB path /dev/sdb
- devid 2 size 20.00GiB used 288.00MiB path /dev/sdc
- btrfs-progs v3.19.1
- [root@localhost ~]
- Data, single: total=8.00MiB, used=64.00KiB
- System, RAID1: total=32.00MiB, used=16.00KiB
- Metadata, RAID1: total=256.00MiB, used=112.00KiB
- GlobalReserve, single: total=16.00MiB, used=0.00B
- [root@localhost ~]
- Done, had to relocate 1 out of 3 chunks
- [root@localhost ~]
- Data, RAID1: total=1.00GiB, used=320.00KiB
- System, RAID1: total=32.00MiB, used=16.00KiB
- Metadata, RAID1: total=256.00MiB, used=112.00KiB
- GlobalReserve, single: total=16.00MiB, used=0.00B
- [root@localhost ~]
显示当前文件系统使用信息
bash/shell Code复制内容到剪贴板
- [root@localhost btrfs]
- Overall:
- Device size: 37.00GiB
- Device allocated: 2.56GiB
- Device unallocated: 34.44GiB
- Device missing: 0.00B
- Used: 896.00KiB
- Free (estimated): 18.22GiB(min: 18.22GiB)
- Data ratio: 2.00
- Metadata ratio: 2.00
- Global reserve: 16.00MiB(used: 0.00B)
- Data,RAID1: Size:1.00GiB, Used:320.00KiB
- /dev/sdb 1.00GiB
- /dev/sdc 1.00GiB
- Metadata,RAID1: Size:256.00MiB, Used:112.00KiB
- /dev/sdb 256.00MiB
- /dev/sdc 256.00MiB
- System,RAID1: Size:32.00MiB, Used:16.00KiB
- /dev/sdb 32.00MiB
- /dev/sdc 32.00MiB
- Unallocated:
- /dev/sdb 15.72GiB
- /dev/sdc 18.72GiB
- [root@localhost btrfs]
- [/dev/sdb].write_io_errs 0
- [/dev/sdb].read_io_errs 0
- [/dev/sdb].flush_io_errs 0
- [/dev/sdb].corruption_errs 0
- [/dev/sdb].generation_errs 0
- [/dev/sdc].write_io_errs 0
- [/dev/sdc].read_io_errs 0
- [/dev/sdc].flush_io_errs 0
- [/dev/sdc].corruption_errs 0
- [/dev/sdc].generation_errs 0
- [root@localhost btrfs]
- /dev/sdb, ID: 1
- Device size: 20.00GiB
- Data,RAID1: 1.00GiB
- Metadata,RAID1: 256.00MiB
- System,RAID1: 32.00MiB
- Unallocated: 15.72GiB
- /dev/sdc, ID: 2
- Device size: 20.00GiB
- Data,RAID1: 1.00GiB
- Metadata,RAID1: 256.00MiB
- System,RAID1: 32.00MiB
- Unallocated: 18.72GiB
- 压缩测试
- [root@localhost btrfs22]
- 5.1G/btrfs
- 5.1G/btrfs22
- [root@localhost btrfs22]
- Label: 'btrfs' uuid: 2a9f0d3d-f8a0-4757-9f4e-d1efa04a683a
- Total devices 2 FS bytes used 178.63MiB
- devid 1 size 17.00GiB used 1.28GiB path /dev/sdb
- devid 2 size 20.00GiB used 1.28GiB path /dev/sdc
- Label: 'btrfs22' uuid: d4da4497-b82e-4846-b51c-cd7127ff5c74
- Total devices 2 FS bytes used 5.01GiB
- devid 1 size 20.00GiB used 4.04GiB path /dev/sdd
- devid 2 size 20.00GiB used 4.00GiB path /dev/sde
- btrfs-progs v3.19.1
子卷和快照的管理
bash/shell Code复制内容到剪贴板
- btrfs subvolume
- [root@localhost btrfs22]
- Create subvolume '/btrfs/btrfs.sub'
- [root@localhost btrfs22]
- ID 259 gen 43 top level 5 path btrfs.sub
- [root@localhost btrfs22]
- [root@localhost ~]
- [root@localhost ~]
- /btrfs.sub
- Name: btrfs.sub
- uuid: 811deb2f-764f-6440-899c-cddb2b9867e2
- Parent uuid: -
- Creation time: 2016-05-11 08:43:51
- Object ID: 259
- Generation (Gen): 43
- Gen at creation: 43
- Parent: 5
- Top Level: 5
- Flags: -
- Snapshot(s):
子卷删除
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- [root@localhost ~]
-
-
- [root@localhost ~]
-
- ID 260 gen 45 top level 5 path btrfs.sub22
子卷快照,类似创建子卷
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- ID 260 gen 45 top level 5 path btrfs.sub22
- [root@localhost ~]
- Create a snapshot of '/btrfs/btrfs.sub22/' in '/btrfs/btrfs.sub22_snapshot'
- [root@localhost ~]
- ID 260 gen 50 top level 5 path btrfs.sub22
- ID 262 gen 50 top level 5 path btrfs.sub22_snapshot
单个文件快照
bash/shell Code复制内容到剪贴板
- [root@localhost btrfs]
- cp: unrecognized option '--relink'
- Try 'cp --help' for more information.
- [root@localhost btrfs]
- [root@localhost btrfs]
- [root@localhost btrfs]
- [root@localhost btrfs]
- localhost.localdomain
- magedu.com
- [root@localhost btrfs]
- localhost.localdomain
- [root@localhost btrfs]
ext文件系统转换为btrfs
bash/shell Code复制内容到剪贴板
- [root@localhost ~]
- [root@localhost ~]
- [root@localhost sdf]
- ks-script-OqV4Gb lost+found yum.log
- [root@localhost ~]
- [root@localhost ~]
- fsck from util-linux 2.23.2
- e2fsck 1.42.9 (28-Dec-2013)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/sdf: 13/1310720 files (0.0% non-contiguous), 126323/5242880 blocks
- [root@localhost ~]
- creating btrfs metadata.
- copy inodes [o] [ 0/ 13]
- creating ext2fs image file.
- cleaning up system chunk.
- conversion complete.
- [root@localhost ~]
- [root@localhost ~]
- [root@localhost sdf]
- ext2_saved ks-script-OqV4Gb lost+found yum.log
- [root@localhost sdf]
- restorecon -ir /etc/sysconfig/network-scripts /var/lib /etc/lvm \
- /dev /etc/iscsi /var/lib/iscsi /root /var/lock /var/log \
- /etc/modprobe.d /etc/sysconfig /var/cache/yum
-
- restorecon -ir /var/roothome /var/home /var/opt /var/srv /var/media /var/mnt
- restorecon -i /etc/rpm/macros /etc/dasd.conf /etc/zfcp.conf /lib64 /usr/lib64 \
- /etc/blkid.tab* /etc/mtab /etc/fstab /etc/resolv.conf \
- /etc/modprobe.conf* /var/log/*tmp /etc/crypttab \
- /etc/mdadm.conf /etc/sysconfig/network /root/install.log* \
- /etc/*shadow* /etc/dhcp/dhclient-*.conf /etc/localtime \
- /etc/hostname /root/install.log*
- if [ -e /etc/zipl.conf ]; then
- restorecon -i /etc/zipl.conf
- fi
- [root@localhost sdf]
- /dev/sdf: UUID="20bd2176-28d9-49fb-88e9-b746f5ea2736" UUID_SUB="9076e700-22a2-420e-81df-feb79449ab7c" TYPE="btrfs"
- btrfs转回ext3
- [root@localhost ~]
- [root@localhost ~]
- rollback complete.
- [root@localhost ~]
- /dev/sdf: UUID="8d6c4b81-9602-428a-a340-f01b176fa82b" SEC_TYPE="ext2" TYPE="ext3"
- [root@localhost ~]
总结:初步了解btrfs,首先,扩展性基于B-tree架构,单个文件,磁盘,文件个数,大大超过现在对扩展性的要求,其次,数据一致性,基于COW和checksum确保数据正常(btrfs的数据检测,修复,恢复相关的命令操作后面补充),再次,设备管理功能强大,内建raid,联机raid调整,联机空间扩展和缩减,联机物理卷增删,快照,子卷,可脱离raid和lvm.
以上个人总结,不足之处欢迎指正,谢谢。
|
请发表评论