本文共 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
[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
[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
[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
[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
[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
[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
[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):
[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)
[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