btrfs文件系统
Btrfs (B-tree, Butter FS, Better FS), GPL, Oracle, 2007, CoW;
ext3/ext4, xfs
核心特性:
多物理卷支持: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
挂载文件系统:
mount -t btrfs /dev/sdb MOUNT_POINT
透明压缩机制:
mount -o compress={lzo|zlib} DEVICE MOUNT_POINT
子命令:filesystem, device, balance, subvolume
相关命令演示:
1、创建btrfs文件系统
[root@localhost ~]
btrfs-progs v4.9.1
See http://btrfs.wiki.kernel.org for more information.
Label: mydata
UUID: 0dd940fb-accf-49be-b07f-df11f03dd16f
Node size: 16384
Sector size: 4096
Filesystem size: 10.00GiB
Block group profiles:
Data: RAID0 1.00GiB
Metadata: RAID1 1.00GiB
System: RAID1 8.00MiB
SSD detected: no
Incompat features: extref, skinny-metadata
Number of devices: 2
Devices:
ID SIZE PATH
1 5.00GiB /dev/sdc
2 5.00GiB /dev/sdd
[root@localhost ~]
Label: 'mydata' uuid: 0dd940fb-accf-49be-b07f-df11f03dd16f
Total devices 2 FS bytes used 112.00KiB
devid 1 size 5.00GiB used 1.51GiB path /dev/sdc
devid 2 size 5.00GiB used 1.51GiB path /dev/sdd
2、挂载
[root@localhost btrfs1]
3、透明压缩功能
[root@localhost ~]
[root@localhost ~]
4、重置 btrfs 的大小,在线联机调整大小,逻辑大小
[root@localhost ~]
Resize '/mnt/btrfs1' of '-500M'
[root@localhost ~]
Resize '/mnt/btrfs1' of 'max'
5、增加 btrfs 的物理大小
[root@localhost ~]
6、平衡存储的数据
[root@localhost ~]
WARNING:
Full balance without filters requested. This operation is very
intense and takes potentially very long. It is recommended to
use the balance filters to narrow down the balanced data.
Use 'btrfs balance start --full-balance' option to skip this
warning. The operation will start in 10 seconds.
Use Ctrl-C to stop it.
10 9 8 7 6 5 4 3 2 1
Starting balance without any filters.
Done, had to relocate 3 out of 3 chunks
// balance 还有pause、resume等子命令
7、对于 btrfs 来说,在拆除硬盘时会先将数据移到其他设备上,然后在执行
[root@localhost ~]
8、修改数据或元数据的级别
[root@localhost ~]
Done, had to relocate 2 out of 3 chunks
[root@localhost ~]
Data, RAID0: total=1.00GiB, used=332.00KiB
System, RAID5: total=64.00MiB, used=16.00KiB
Metadata, RAID5: 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
9、子卷管理
[root@localhost ~]
Create subvolume '/mnt/btrfs1/logs'
[root@localhost ~]
ID 265 gen 93 top level 5 path logs
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
/mnt
Name: logs
UUID: 36540370-0cb8-e44c-a3f6-9fbc169211a7
Parent UUID: -
Received UUID: -
Creation time: 2021-09-10 16:49:08 +0800
Subvolume ID: 265
Generation: 94
Gen at creation: 93
Parent ID: 5
Top level ID: 5
Flags: -
Snapshot(s):
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
Delete subvolume (no-commit): '/mnt/btrfs1/logs'
注:单独挂载某一个子卷时,需要先卸载父卷,只能够访问子卷上的内容,无法访问父卷;当父卷挂载时,子卷会自动挂载到父卷下
10、子卷创建快照
[root@localhost ~]
[root@localhost ~]
Create a snapshot of '/mnt/btrfs1/logs/' in '/mnt/btrfs1/logs_snap'
[root@localhost ~]
ID 266 gen 100 top level 5 path logs
ID 267 gen 100 top level 5 path logs_snap
[root@localhost ~]
Delete subvolume (no-commit): '/mnt/btrfs1/logs_snap'
[root@localhost logs]
[root@localhost logs]
grub2.cfg grub2.cfg_snapshot
11、将ext4文件系统转换成btrfs(sdb2为准备好的ext4设备)
[root@localhost ~]
fsck,来自 util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/sdb2: 11/65536 files (0.0% non-contiguous), 12955/262144 blocks
[root@localhost ~]
create btrfs filesystem:
blocksize: 4096
nodesize: 16384
features: extref, skinny-metadata (default)
creating ext2 image file
creating btrfs metadatacopy inodes [o] [ 1/ 11]
conversion complete[root@localhost ~]
Label: 'mydata' uuid: 0dd940fb-accf-49be-b07f-df11f03dd16f
Total devices 3 FS bytes used 620.00KiB
devid 2 size 5.00GiB used 928.00MiB path /dev/sdd
devid 3 size 5.00GiB used 928.00MiB path /dev/sde
devid 4 size 5.00GiB used 928.00MiB path /dev/sdc
Label: none uuid: 09a9260d-3062-4212-93c3-16f6f7be651a
Total devices 1 FS bytes used 50.25MiB
devid 1 size 1.00GiB used 227.00MiB path /dev/sdb2
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
压缩工具
压缩、解压缩及归档工具
compress/uncompress: .Z
gzip/gunzip: .gz
bzip2/bunzip2: .bz2
xz/unxz: .xz
zip/unzip
tar, cpio
1、gzip/gunzip
gzip [OPTION]… FILE …
-d: 解压缩,相当于gunzip
-c: 将结果输出至标准输出;
-#:1-9,指定压缩比;
zcat:不显式展开的前提下查看文本文件内容;
实例:
[root@localhost tmp]
[root@localhost tmp]
total 336K
-rw-------. 1 root root 336K Sep 11 09:11 messages
[root@localhost tmp]
[root@localhost tmp]
total 52K
-rw-------. 1 root root 49K Sep 11 09:11 messages.gz
[root@localhost tmp]
[root@localhost tmp]
[root@localhost tmp]
[root@localhost tmp]
messages messages.gz
2、bzip2/bunzip2/bzcat
bzip2 [OPTION]… FILE …
-k: keep, 保留原文件;
-d:解压缩
-#:1-9,压缩比,默认为6;
bzcat:不显式展开的前提下查看文本文件内容;
实例:
[root@localhost tmp]
[root@localhost tmp]
messages.bz2
[root@localhost tmp]
[root@localhost tmp]
messages messages.bz2
3、xz/unxz/xzcat
xz [OPTION]… FILE …
-k: keep, 保留原文件
-d:解压缩
-#:1-9,压缩比,默认为6
xzcat: 不显式展开的前提下查看文本文件内容
4、tar
tar [OPTION]…
(1) 创建归档
tar -c -f /PATH/TO/SOMEFILE.tar FILE…
tar -cf /PATH/TO/SOMEFILE.tar FILE…
(2) 查看归档文件中的文件列表
tar -t -f /PATH/TO/SOMEFILE.tar
(3) 展开归档
tar -x -f /PATH/TO/SOMEFILE.tar
tar -x -f /PATH/TO/SOMEFILE.tar -C /PATH/TO/DIR
结合压缩工具实现:归档并压缩
-j: bzip2, -z: gzip, -J: xz
实例:
[root@localhost tmp]
[root@localhost tmp]
messages messages.bz2 messages.xz pam.d pam.d.tar
[root@localhost tmp]
[root@localhost tmp]
pam.d
[root@localhost tmp]
[root@localhost tmp]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)