1.查看磁盤狀況:
[root@network ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
├─sdb2 8:18 0 5G 0 part
├─sdb3 8:19 0 5G 0 part
└─sdb4 8:20 0 5G 0 part
sr0 11:0 1 4G 0 rom
node
2.
[root@network ~]# mkfs.btrfs -L mydata /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 #設置卷標格式化爲btrfs文件系統
btrfs-progs v3.19.1
See http://btrfs.wiki.kernel.org for more information.
centos
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
adding device /dev/sdb2 id 2
adding device /dev/sdb3 id 3
adding device /dev/sdb4 id 4
fs created label mydata on /dev/sdb1
nodesize 16384 leafsize 16384 sectorsize 4096 size 20.00GiB
app
-
[root@network ~]# man btrfs #發現有filesystem這個命令ide
[root@network ~]# man btrfs-filesystem
BTRFS-FILESYSTEM(8) Btrfs Manual BTRFS-FILESYSTEM(8)
ui
NAME
btrfs-filesystem - control btrfs filesystem
url
SYNOPSIS
btrfs filesystem <subcommand> <args>
spa
-
[root@network ~]# btrfs filesystem show #查看製做的btrfs文件系統
Label: 'mydata' uuid: ddbcaabe-8e2d-4254-8e02-5fd310927cd9
Total devices 4 FS bytes used 112.00KiB
devid 1 size 5.00GiB used 1.52GiB path /dev/sdb1
devid 2 size 5.00GiB used 1.50GiB path /dev/sdb2
devid 3 size 5.00GiB used 519.94MiB path /dev/sdb3
devid 4 size 5.00GiB used 519.94MiB path /dev/sdb4
.net
btrfs-progs v3.19.13d
5.
[root@network ~]# btrfs filesystem show --mounted #顯示全部掛載
btrfs-progs v3.19.1
[root@network ~]# btrfs filesystem show --all-devices #顯示全部的設備
Label: 'mydatas' uuid: 6507eecb-29fb-4b33-a5aa-b3d39b4f36b9
Total devices 2 FS bytes used 112.00KiB
devid 1 size 20.00GiB used 2.03GiB path /dev/sdc
devid 2 size 20.00GiB used 2.01GiB path /dev/sdd
code
Label: 'mydata' uuid: ddbcaabe-8e2d-4254-8e02-5fd310927cd9
Total devices 4 FS bytes used 200.00KiB
devid 1 size 1.00GiB used 531.94MiB path /dev/sdb1
devid 2 size 5.00GiB used 519.94MiB path /dev/sdb2
devid 3 size 5.00GiB used 783.94MiB path /dev/sdb3
devid 4 size 5.00GiB used 783.94MiB path /dev/sdb4
btrfs-progs v3.19.1
6.
[root@network ~]# btrfs filesystem show /dev/sdc #輸出一個磁盤就兩個都顯示
Label: 'mydatas' uuid: 6507eecb-29fb-4b33-a5aa-b3d39b4f36b9
Total devices 2 FS bytes used 112.00KiB
devid 1 size 20.00GiB used 2.03GiB path /dev/sdc
devid 2 size 20.00GiB used 2.01GiB path /dev/sdd
btrfs-progs v3.19.1
[root@network ~]# btrfs filesystem show /dev/sdd
Label: 'mydatas' uuid: 6507eecb-29fb-4b33-a5aa-b3d39b4f36b9
Total devices 2 FS bytes used 112.00KiB
devid 1 size 20.00GiB used 2.03GiB path /dev/sdc
devid 2 size 20.00GiB used 2.01GiB path /dev/sdd
btrfs-progs v3.19.1
7.
或者最直接對磁盤:
[root@network ~]# mkfs.btrfs -L mydatas /dev/sdc /dev/sdd
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
adding device /dev/sdd id 2
fs created label mydatas on /dev/sdc
nodesize 16384 leafsize 16384 sectorsize 4096 size 40.00GiB
8.
[root@network ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="mydata" UUID="ddbcaabe-8e2d-4254-8e02-5fd310927cd9" UUID_SUB="01609da4-e282-4aa3-91fb-45dfd4573831" TYPE="btrfs"
[root@network ~]# blkid /dev/sdb2
/dev/sdb2: LABEL="mydata" UUID="ddbcaabe-8e2d-4254-8e02-5fd310927cd9" UUID_SUB="88e06cb6-0fbc-4257-b264-31e9f782731c" TYPE="btrfs"
9.
[root@network ~]# btrfs filesystem label /dev/sdb1 #查看卷標
mydata
[root@network ~]# btrfs filesystem label /dev/sdb2
mydata
[root@network ~]# btrfs filesystem label /dev/sdb3
mydata
[root@network ~]# btrfs filesystem label /dev/sdb4
mydata
10.
[root@network ~]# mount -t btrfs /dev/sdb1 /mydata #掛載使用
11.
[root@network ~]# mount -o compress=lzo /dev/sdb1 /mydata #實現自動的壓縮
[root@network ~]# cp /etc/rc.d/init.d/
functions netconsole network README
[root@network ~]# cp /etc/rc.d/init.d/functions /mydata/
[root@network ~]# cd /mydata/
[root@network mydata]# ls
functions
12.
[root@network mydata]# man btrfs-device
13.
[root@network mydata]# btrfs filesystem resize -3G /mydata/ #resize子命令減容
Resize '/mydata/' of '-3G'
14
[root@network ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 5.6G 12G 32% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 108M 390M 22% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb 80G 18M 78G 1% /mydata
[root@network ~]# btrfs filesystem df /mydata/ #btrfs 自帶的命令 df命令查看
Data, RAID0: total=4.00GiB, used=1.25MiB
System, RAID1: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, RAID1: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
[root@network ~]#
15
[root@network ~]# btrfs filesystem resize max /mydata/ #擴展到最大空間 max
Resize '/mydata/' of 'max'
16
[root@network ~]# btrfs device delete /dev/sdc /mydata/ #從磁盤挪出那一部分,若是是添加就add
[root@network ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 5.6G 12G 32% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 108M 390M 22% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb 60G 18M 57G 1% /mydata
17
BTRFS-BALANCE(8) Btrfs Manual BTRFS-BALANCE(8)
NAME
btrfs-balance - balance btrfs filesystem
SYNOPSIS
btrfs balance <subcommand> <args>
18
[root@network ~]# btrfs balance status /mydata
No balance found on '/mydata'
[root@network ~]# btrfs balance start /mydata #開啓balance
Done, had to relocate 5 out of 5 chunks
19
[root@network ~]# man btrfs-balance
他有子命令
pause <path>
Pause running balance.
resume <path> Resume interrupted balance. start [options] <path> -d[<filters>] act on data chunks. See FILTERS section for details about <filters>. -m[<filters>] act on metadata chunks. See FILTERS section for details about <filters>. -s[<filters>] act on system chunks (only under -f). See FILTERS section for details about <filters>. convert Convert each selected block group to the given profile name identified by parameters.
20
[root@network ~]# btrfs balance start -dconvert=raid5 /mydata/ #修改成raid5級別
Done, had to relocate 1 out of 3 chunks
或者
[root@network ~]# btrfs balance start -mconvert=raid5 /mydata/
Done, had to relocate 2 out of 3 chunks
21
[root@network ~]# man btrfs-subvolume
BTRFS-SUBVOLUME(8) Btrfs Manual BTRFS-SUBVOLUME(8)
NAME
btrfs-subvolume - control btrfs subvolume(s)
SYNOPSIS
btrfs subvolume <subcommand> [<args>]
22
[root@network ~]# btrfs subvolume list /mydata/ #列出子卷
23
SUBCOMMAND
create [-i <qgroupid>] [<dest>]<name>
Create a subvolume <name> in <dest>. #建立子卷
[root@network ~]# btrfs subvolume create /mydata/logs #建立子卷
Create subvolume '/mydata/logs'
[root@network ~]# btrfs subvolume list /mydata/ #列出子卷
ID 264 gen 65 top level 5 path logs
24
掛載子卷,掛載父卷之後子卷就自動掛載,如今單獨掛載子卷
[root@network ~]# umount /mydata #先卸載父卷
[root@network ~]# mount -o subvol=logs /dev/sde /mnt #掛載子卷,也能夠不用logs用卷ID來掛載
[root@network ~]# cp /var/log/messages /mnt
[root@network ~]# ll /mnt
total 848
-rw------- 1 root root 866759 Aug 4 13:41 messages
[root@network ~]# btrfs subvolume show /mnt #查看子卷的詳細信息
/mnt
Name: logs
uuid: a87a7495-22cb-4644-b1a9-5ecd353af544
Parent uuid: -
Creation time: 2020-08-04 13:36:04
Object ID: 264
Generation (Gen): 67
Gen at creation: 65
Parent: 5
Top Level: 5
Flags:
[root@network ~]# umount /mnt
[root@network ~]# mount /dev/sdd /mydata/ #卸載子卷從新掛載父卷,發現子卷裏面的東西依然存在
[root@network ~]# ls /mydata/logs/
messages
25刪除子卷
[root@network ~]# btrfs subvolume delete /mydata/logs/
Delete subvolume (no-commit): '/mydata/logs'
26.對卷建立快照
[root@network ~]# btrfs subvolume create /mydata/logs.logs 1.先建立子卷
Create subvolume '/mydata/logs.logs'
[root@network ~]# cp /etc/grub2.cfg /mydata/logs.logs/ 2.複製內容到子卷裏面
[root@network ~]# btrfs subvolume snapshot /mydata/logs.logs/ /mydata/logs.logs_sanpshot 3.創造快照卷與子卷必須同一父卷下
Create a snapshot of '/mydata/logs.logs/' in '/mydata/logs.logs_sanpshot'
[root@network ~]# btrfs subvolume list /mydata/
ID 264 gen 73 top level 5 path logs.logs
ID 265 gen 73 top level 5 path logs.logs_sanpshot #展開發現父卷下多了快照卷
[root@network ~]# cd /mydata/logs.logs_sanpshot/ #發現快照卷裏面也有和子卷如出一轍的東西
[root@network logs.logs_sanpshot]# ls
grub2.cfg #修改子卷中的grub2.cfg,快照卷grub2.cfg不發生變化
27刪除快照
[root@network logs.logs_sanpshot]# btrfs subvolume delete /mydata/logs.logs_sanpshot/
28
單獨對子卷的某一文件快照
[root@network mydata]# ls
logs.logs logs.logs_sanpshot
[root@network mydata]# cd logs.logs
[root@network logs.logs]# ls
grub2.cfg
[root@network logs.logs]# cp --reflink grub2.cfg grub2.cfg_snap #此時修改grub2.cfg 不會影響到grub2.cfg_snap
29
如何將ext系列文件系統轉化爲btrfs毫無損壞
[root@network logs.logs]# btrfs balance start -dconvert=single /mydata/
Done, had to relocate 1 out of 3 chunks
[root@network logs.logs]# btrfs balance start -mconvert=raid1 /mydata/
Done, had to relocate 2 out of 3 chunks
[root@network logs.logs]# btrfs device delete /dev/sde /mydata/ 1.挪走一塊盤即/dev/sde
[root@network logs.logs]# fdisk /dev/sde 2.對這塊盤分區
[root@network logs.logs]# mke2fs -t ext4 /dev/sde 3.格式化爲ext4類型文件系統
[root@network logs.logs]# mount /dev/sde /mnt #掛載寫入數據
[root@network logs.logs]# cp /etc/fstab /mnt
[root@network logs.logs]# umount /mnt #文件系統相互轉化危險,因此轉化以前要先卸載
[root@network logs.logs]# fsck -f /dev/sde 4.檢查此文件系統
[root@network logs.logs]# btrfs-convert /dev/sde 5.裝換爲btrfs
[root@network logs.logs]# btrfs filesystem show
Label: 'mydata' uuid: b689a89b-3a4a-4258-8412-e3d2180056a9
Total devices 3 FS bytes used 680.00KiB
devid 1 size 20.00GiB used 1.00GiB path /dev/sdb
devid 3 size 20.00GiB used 1.03GiB path /dev/sdd
devid 5 size 20.00GiB used 1.03GiB path /dev/sdc
Label: none uuid: 55a1c30b-62b3-4728-ba7d-138cff575bcd #此時已經被轉換了
Total devices 1 FS bytes used 493.57MiB
devid 1 size 20.00GiB used 20.00GiB path /dev/sde
btrfs-progs v3.19.1
[root@network logs.logs]# mount /dev/sde /mnt #從新掛載裏面數據有丟失
[root@network logs.logs]# ll /mnt
total 20
drwxr-xr-x 1 root root 10 Aug 4 14:38 ext2_saved
-rw-r--r-- 1 root root 559 Aug 4 14:37 fstab
drwx------ 1 root root 0 Aug 4 14:35 lost+found
30.相互轉化[root@network logs.logs]# umount /mnt 卸載[root@network logs.logs]# btrfs-convert -r /dev/sde -r:裝換爲ext4rollback complete.[root@network logs.logs]# blkblkdeactivate blkdiscard blkid blkmapd [root@network logs.logs]# blkid /dev/sde/dev/sde: UUID="8007b2ad-cde4-48c3-8d2a-ce236d0f7eb6" TYPE="ext4" [root@network logs.logs]# btrfs-convert /dev/sde #無-r從新轉化爲btrfs系列creating btrfs metadata.copy inodes [o] [ 0/ 12]creating ext2fs image file.cleaning up system chunk.conversion complete.[root@network logs.logs]# blkid /dev/sde/dev/sde: UUID="9a37e348-40cf-44a2-a4e3-52868c913be1" UUID_SUB="f3088659-df3a-4a0c-a6a9-b8d7e6f0aae4" TYPE="btrfs" [root@network logs.logs]#