博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
btrfs杂记
阅读量:5820 次
发布时间:2019-06-18

本文共 11186 字,大约阅读时间需要 37 分钟。

查看命令状态特性

[root@CentOS7 ~]# mkfs.btrfs -O list-allFilesystem features available at mkfs time:mixed-bg            - mixed data and metadata block groups (0x4)extref              - increased hardlink limit per file to 65536 (0x40, default)raid56              - raid56 extended format (0x80)skinny-metadata     - reduced-size metadata extent refs (0x100, default)no-holes            - no explicit hole extents for files (0x200

创建btrfs文件系统

[root@CentOS7 ~]# mkfs.btrfs -L mydata /dev/sdb /dev/sdcbtrfs-progs v3.19.1See http://btrfs.wiki.kernel.org for more information.Turning ON incompat feature 'extref': increased hardlink limit per file to 65536Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refsadding device /dev/sdc id 2fs created label mydata on /dev/sdb    nodesize 16384 leafsize 16384 sectorsize 4096 size 40.00GiB

显示btrfs文件系统信息,默认显示所有

[root@CentOS7 ~]# btrfs filesystem showLabel: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 112.00KiB    devid    1 size 20.00GiB used 2.03GiB path /dev/sdb    devid    2 size 20.00GiB used 2.01GiB path /dev/sdcbtrfs-progs v3.19.1

只显示指定btrfs文件系统

[root@CentOS7 ~]# btrfs filesystem show /dev/sdcLabel: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 112.00KiB    devid    1 size 20.00GiB used 2.03GiB path /dev/sdb    devid    2 size 20.00GiB used 2.01GiB path /dev/sdcbtrfs-progs v3.19.1

压缩挂载

[root@CentOS7 ~]# mount -o compress=lzo /dev/sdb /mydata[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  4.8M  114M   4% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdb         40G   18M   38G   1% /mydata

使用LABEL查看btrfs文件系统

[root@CentOS7 ~]# btrfs filesystem show /mydataLabel: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 912.00KiB    devid    1 size 20.00GiB used 2.02GiB path /dev/sdb    devid    2 size 20.00GiB used 2.01GiB path /dev/sdc

联机修改分区大小

[root@CentOS7 ~]# btrfs filesystem resize -10G /mydata/Resize '/mydata/' of '-10G'[root@CentOS7 ~]# btrfs filesystem show /mydataLabel: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 912.00KiB    devid    1 size 10.00GiB used 2.02GiB path /dev/sdb    devid    2 size 20.00GiB used 2.01GiB path /dev/sdc[root@CentOS7 ~]# btrfs filesystem  df /mydataData, RAID0: total=2.00GiB, used=784.00KiBSystem, RAID1: total=8.00MiB, used=16.00KiBSystem, single: total=4.00MiB, used=0.00BMetadata, RAID1: total=1.00GiB, used=112.00KiBMetadata, single: total=8.00MiB, used=0.00BGlobalReserve, single: total=16.00MiB, used=0.00B[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  4.7M  114M   4% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdb         30G   18M   18G   1% /mydata

增加5G空间大小

[root@CentOS7 ~]# btrfs filesystem resize +5G /mydata/Resize '/mydata/' of '+5G'[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  4.7M  114M   4% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdb         35G   18M   28G   1% /mydata[root@CentOS7 ~]# btrfs filesystem df /mydata/Data, RAID0: total=2.00GiB, used=784.00KiBSystem, RAID1: total=8.00MiB, used=16.00KiBSystem, single: total=4.00MiB, used=0.00BMetadata, RAID1: total=1.00GiB, used=112.00KiBMetadata, single: total=8.00MiB, used=0.00BGlobalReserve, single: total=16.00MiB, used=0.00B

添加到最大分区容量

[root@CentOS7 ~]# btrfs filesystem resize max /mydataResize '/mydata' of 'max'[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  8.7M  110M   8% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdb         40G   18M   38G   1% /mydata

添加一块硬进去,如果设置了max,会自动扩展

[root@CentOS7 ~]# btrfs device add /dev/sdd /mydata[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  8.7M  110M   8% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdb         60G   18M   56G   1% /mydata

将数据负载至各个磁盘

[root@CentOS7 ~]# btrfs balance start /mydata/Done, had to relocate 5 out of 5 chunks

从分区移除一个磁盘

[root@CentOS7 ~]# btrfs device delete /dev/sdb /mydata[root@CentOS7 ~]# btrfs filesystem show Label: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 912.00KiB    devid    2 size 20.00GiB used 2.03GiB path /dev/sdc    devid    3 size 20.00GiB used 2.03GiB path /dev/sdd

重新加入一个设备

[root@CentOS7 mydata]# btrfs device add /dev/sdb /mydata

将分区转换成RAID5

[root@CentOS7 mydata]# btrfs balance start -dconvert=raid5 /mydataDone, had to relocate 1 out of 3 chunks[root@CentOS7 mydata]# [root@CentOS7 mydata]# [root@CentOS7 mydata]# btrfs balance start -mconvert=raid5 /mydata

查看子卷信息

[root@CentOS7 mydata]# btrfs subvolume list /mydata/

创建并查看子卷

[root@CentOS7 mydata]# btrfs subvolume create /mydata/logsCreate subvolume '/mydata/logs'[root@CentOS7 mydata]# btrfs subvolume list /mydataID 265 gen 109 top level 5 path logs

取消挂载父卷,只挂载子卷

[root@CentOS7 ~]# umount /mydata/[root@CentOS7 ~]# mount -o subvol=logs /dev/sdb /mnt[root@CentOS7 ~]# df -lhFilesystem      Size  Used Avail Use% Mounted on/dev/sda6        23G   56M   23G   1% /devtmpfs        109M     0  109M   0% /devtmpfs           119M     0  119M   0% /dev/shmtmpfs           119M  8.7M  110M   8% /runtmpfs           119M     0  119M   0% /sys/fs/cgroup/dev/sda5        30G  1.2G   29G   4% /usr/dev/sda2        79G  152M   78G   1% /var/dev/sda3        40G   33M   40G   1% /usr/local/dev/sda7        10G   33M   10G   1% /home/dev/sda9       6.9G   33M  6.8G   1% /tmp/dev/md0        3.9G   16M  3.7G   1% /backup/dev/sda1       197M  108M   90M  55% /boottmpfs            24M     0   24M   0% /run/user/0/dev/sdc         60G   17M   58G   1% /mnt

查看子卷详细信息

[root@CentOS7 ~]# btrfs subvolume show /mnt/mnt    Name:           logs    uuid:           757e5898-97be-8942-a9bb-a1bd3bc01506    Parent uuid:        -    Creation time:      2016-07-18 10:30:13    Object ID:      265    Generation (Gen):   109    Gen at creation:    109    Parent:         5    Top Level:      5    Flags:          -    Snapshot(s):

通过卷id挂载子卷

[root@CentOS7 ~]# btrfs subvolume list /mydataID 265 gen 112 top level 5 path logsID 266 gen 110 top level 5 path cache[root@CentOS7 ~]# mount -o subvolid=266 /dev/sdb /mnt

删除子卷,需要父卷也有挂载

[root@CentOS7 ~]# btrfs subvolume delete /mydata/logsDelete subvolume (no-commit): '/mydata/logs'[root@CentOS7 ~]# btrfs subvolume list /mydata/[root@CentOS7 ~]#

创建快照

Create a snapshot of '/mydata/logs' in '/mydata/logs_snapshot'[root@CentOS7 ~]# btrfs subvolume list /mydataID 265 gen 118 top level 5 path logsID 266 gen 118 top level 5 path logs_snapshot

删除快照

[root@CentOS7 logs_snapshot]# cd [root@CentOS7 ~]# btrfs subvolume delete /mydata/logs_snapshotDelete subvolume (no-commit): '/mydata/logs_snapshot'

什么意思,得查一下,马哥说是对一个文件做快照

[root@CentOS7 logs]# cp --reflink grub2.cfg grub2.cfg_snap

拆除文件系统

[root@CentOS7 logs]# btrfs balance start -dconvert=single /mydata #更改数据类型Done, had to relocate 1 out of 3 [root@CentOS7 logs]# btrfs balance start -mconvert=raid1 /mydata #更改元数据类型Done, had to relocate 2 out of 3 chunks[root@CentOS7 logs]# btrfs device delete /dev/sdd /mydata/   #拆除文件系统

转换文件系统

[root@CentOS7 ~]# umount /mnt/                       #先卸载文件系统[root@CentOS7 ~]# fsck -f /dev/sdd1                  #强制检查文件系统是否正常fsck 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@CentOS7 ~]# btrfs-convert /dev/sdd1            #文件系统转换成btrfscreating btrfs metadata.copy inodes [o] [         0/        12]creating ext2fs image file.cleaning up system chunk.conversion complete.[root@CentOS7 ~]# btrfs filesystem show              #查看文件系统,发现/dev/sdd1已经变成btrfs文件系统           Label: 'mydata'  uuid: af9a4b5a-8c4e-4cde-91ef-bb62c5662969    Total devices 2 FS bytes used 672.00KiB    devid    2 size 20.00GiB used 2.03GiB path /dev/sdc    devid    4 size 20.00GiB used 1.03GiB path /dev/sdbLabel: none  uuid: 42290a33-9e06-4cfb-89a4-6fb660e30915    Total devices 1 FS bytes used 228.50MiB    devid    1 size 5.00GiB used 5.00GiB path /dev/sdd1btrfs-progs v3.19.1[root@CentOS7 ~]# [root@CentOS7 ~]# mount /dev/sdd1 /mnt/               #重新挂载文件系统[root@CentOS7 ~]# mount/dev/sdd1 on /mnt type btrfs (rw,relatime,seclabel,space_cache)

从btrfs文件系统转换回原来的系统

[root@CentOS7 ~]# umount /mnt[root@CentOS7 ~]# btrfs-convert -r /dev/sdd1[root@CentOS7 ~]# blkid /dev/sdd1/dev/sdd1: UUID="6ef58403-3584-413e-bc11-6f5281917caa" TYPE="ext4"

转载于:https://blog.51cto.com/zhongle21/2086911

你可能感兴趣的文章
Android Service组件
查看>>
FTPUtil工具类
查看>>
[Android 新特性] 谷歌发布Android Studio开发工具1.0正式版(组图) 2014-12-09 09:35:40
查看>>
选数 2002年NOIP全国联赛普及组
查看>>
js 显示当前系统时间
查看>>
python基础—基本数据类型—数字,字符串,列表,元组,字典
查看>>
ui主线程控件的更新就让这个activity的异步任务做完整
查看>>
SQLite用法
查看>>
芯嵌stm32开发板配套入门教程--目录
查看>>
验证码
查看>>
第1讲 微信小程序概述
查看>>
根据name获取控件
查看>>
django_filter,Search_Filter,Order_Filter,分页
查看>>
Oracle 中MERGE语句的用法
查看>>
Greenplum 查看连接与锁信息数据字典
查看>>
《伟大的计算原理》一云计算
查看>>
动态语句创建临时表权限不足
查看>>
hdu 1026 Ignatius and the Princess I
查看>>
进程互斥与同步
查看>>
使用TortoiseGit对android studio工程进行代码版本控制
查看>>