《LINUX學習:CentOS 7上配置Btrfs文件系統》要點:
本文介紹了LINUX學習:CentOS 7上配置Btrfs文件系統,希望對您有用。如果有疑問,可以聯系我們。
一,Btrfs文件系統簡介
Btrfs(通常念成Butter FS),由Oracle于2007年宣布并進行中的COW(copy-on-write式)文件系統.目標是取代Linux目前的ext3文件系統,改善ext3的限制,特別是單一文件大小的限制,總文件系統大小限制以及參加文件校驗和特性.參加目前ext3/4未支持的一些功能,例如可寫的磁盤快照(snapshots),以及支持遞歸的快照(snapshots of snapshots),內建磁盤陣列(RAID)支持,支持子卷(Subvolumes)的概念,允許在線調整文件系統大小.
二BTRFS核心特性
多物理卷支持:btrfs可由多個底層物理卷組成,支持RAID,以聯機“添加”,“移除”,“修改”
寫時復制更新機制(Cow) 復制,更新及替換指針,而非“就地”更新
數據及元數據查驗碼:checksum
子卷:sub_volume
快照:支持快照的快照
透明壓縮
三,設置裝備擺設BTRFS文件系統
? 添加三塊磁盤,每塊20GB.
[root@CentOS7 ~]# fdisk -l? ? ? ? ? ? #查看磁盤情況
磁盤 /dev/sdd:21.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/sdc:21.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/sdb:21.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/sda:21.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000b57bf
? 設備 Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/sda1? *? ? ? ? 2048? ? 1026047? ? ? 512000? 83? Linux
/dev/sda2? ? ? ? ? ? 1026048? ? 41943039? ? 20458496? 8e? Linux LVM
磁盤 /dev/mapper/centos-root:18.8 GB, 18756927488 字節,36634624 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@centos7 ~]# mkfs.btrfs -L mydata /dev/sdb /dev/sdc? ? ? ? ? ? #創建btrfs文件系統,總共40GB
Btrfs v3.16.2
See http://btrfs.wiki.kernel.org for more information.
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
adding device /dev/sdc id 2
fs created label mydata on /dev/sdb
? ? nodesize 16384 leafsize 16384 sectorsize 4096 size 40.00GiB
[root@centos7 ~]# btrfs filesystem show? ? ? ? ? #顯示btrfs詳細信息
Label: 'mydata'? uuid: 6dfeb558-63ca-43cb-ac46-a95ce7375511
? ? 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/sdc
? ? Btrfs v3.16.2
[root@centos7 ~]# blkid /dev/sdb? ? ? ? ? ? ? ? ? #查看btrfs文件系統,UUID相同, 子UUID不同
/dev/sdb: LABEL="mydata" UUID="6dfeb558-63ca-43cb-ac46-a95ce7375511" UUID_SUB="e306fe96-df9b-4911-be6b-3cd776b226bf" TYPE="btrfs"
[root@centos7 ~]# blkid /dev/sdc
/dev/sdc: LABEL="mydata" UUID="6dfeb558-63ca-43cb-ac46-a95ce7375511" UUID_SUB="1a7b3777-1c7e-414b-9670-17417c288bcf" TYPE="btrfs"
Last login: Tue Aug 23 17:01:48 2016 from 192.168.1.12
[root@centos7 ~]# btrfs filesystem show --all-devices? ? ? ? ? ? ? ? #查看btrfs文件系統
Label: 'mydata'? uuid: 6dfeb558-63ca-43cb-ac46-a95ce7375511
? ? 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/sdc
Btrfs v3.16.2
[root@centos7 ~]# btrfs filesystem show /dev/sdb? ? ? ? ? #查看btrfs文件系統
Label: 'mydata'? uuid: 6dfeb558-63ca-43cb-ac46-a95ce7375511
? ? 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/sdc
Btrfs v3.16.2
[root@centos7 ~]# btrfs filesystem label /dev/sdb? ? ? ? ? ? #查看卷標
mydata
[root@centos7 ~]# btrfs filesystem label /dev/sdc
mydata
[root@centos7 ~]# mkdir? /mydata? ? ? ? ? ? ? ? #新建mydata目錄
[root@centos7 ~]# mount -t btrfs /dev/sdb /mydata/? ? ? ? ? ? ? #掛載btrfs到mydata目錄下
[root@centos7 ~]# mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=491656k,nr_inodes=122914,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdb on /mydata type btrfs (rw,relatime,seclabel,space_cache)? ? ? ? ? ? ? ? #可以看見/dev/sdb 已掛載至mydata目錄下
[root@centos7 ~]# cd /mydata/? ? ? ? ? ? ? ? ? ? ? ? ? ? #進入mydata目錄
[root@centos7 mydata]# touch a.txt? ? ? ? ? ? ? ? ? ? ? #創建文件
[root@centos7 mydata]# cp /etc/grub2.cfg? ./? ? ? #拷貝文件到當前目錄下
[root@centos7 mydata]# ls
a.txt? grub2.cfg
[root@centos7 mydata]# cd? ? ? ? ? ? ? ? ? ? ? #返回到根目錄
[root@centos7 ~]# umount /dev/sdb? ? ? #卸載sdb磁盤
[root@centos7 ~]# ls /mydata/? ? ? ? ? ? ? ? #查看mydata目錄,已沒有數據
[root@centos7 ~]# mount -o compress=lzo /dev/sdb /mydata? ? ? #使用lzo方式進行透明壓縮,支持lzo zlib兩種壓縮類型
[root@centos7 ~]# cp /etc/rc.d/init.d/functions /mydata/? ? ? ? ? ? ? #文件壓縮后在拷貝到mydata目錄里
[root@centos7 ~]# cd /mydata/
[root@centos7 mydata]# ll -l
總用量 20
-rw-r--r--. 1 root root? ? 0 8月? 23 17:26 a.txt
-rw-r--r--. 1 root root 13430 8月? 23 17:38 functions
-rw-r--r--. 1 root root? 4028 8月? 23 17:26 grub2.cfg
[root@centos7 ~]# btrfs filesystem resize -10G /mydata/? ? ? ? ? ? ? ? ? #在線縮減btrfs文件系統大小,將mydata縮減10GB,
Resize '/mydata/' of '-10G'
[root@centos7 ~]# btrfs filesystem show /mydata
Label: 'mydata'? uuid: 6dfeb558-63ca-43cb-ac46-a95ce7375511
? ? Total devices 2 FS bytes used 904.00KiB
? ? devid? ? 1 size 10.00GiB used 2.03GiB path /dev/sdb
? ? devid? ? 2 size 20.00GiB used 2.01GiB path /dev/sdc
Btrfs v3.16.2
[root@centos7 ~]# df -lh
文件系統? ? ? ? ? ? ? ? 容量? 已用? 可用 已用% 掛載點
/dev/mapper/centos-root? 18G? 6.8G? 11G? 39% /
devtmpfs? ? ? ? ? ? ? ? 481M? ? 0? 481M? ? 0% /dev
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 80K? 490M? ? 1% /dev/shm
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 7.1M? 483M? ? 2% /run
tmpfs? ? ? ? ? ? ? ? ? ? 490M? ? 0? 490M? ? 0% /sys/fs/cgroup
/dev/sda1? ? ? ? ? ? ? ? 497M? 126M? 372M? 26% /boot
/dev/sdb? ? ? ? ? ? ? ? ? 30G? 1.1M? 18G? ? 1% /mydata
[root@centos7 ~]# ls /mydata/? ? ? ? ? ? ? ? ? ? ? ? ? ? #mydata目錄里的文件仍可??常拜訪
a.txt? functions? grub2.cfg
[root@centos7 ~]# cat /mydata/grub2.cfg? ? ? ? ? ? #mydata目錄里的文件仍可正常拜訪
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
[root@centos7 ~]# btrfs filesystem resize +5G /mydata/? ? ? ? #聯機將mydata大小擴容5GB
Resize '/mydata/' of '+5G'
[root@centos7 ~]# df -lh? #sdb的大小為35GB
文件系統? ? ? ? ? ? ? ? 容量? 已用? 可用 已用% 掛載點
/dev/mapper/centos-root? 18G? 6.8G? 11G? 39% /
devtmpfs? ? ? ? ? ? ? ? 481M? ? 0? 481M? ? 0% /dev
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 80K? 490M? ? 1% /dev/shm
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 7.1M? 483M? ? 2% /run
tmpfs? ? ? ? ? ? ? ? ? ? 490M? ? 0? 490M? ? 0% /sys/fs/cgroup
/dev/sda1? ? ? ? ? ? ? ? 497M? 126M? 372M? 26% /boot
/dev/sdb? ? ? ? ? ? ? ? ? 35G? 1.1M? 28G? ? 1% /mydata
[root@centos7 ~]# btrfs filesystem resize max /mydata/? ? ? ? ? #將btrfs文件系統調整至最大
Resize '/mydata/' of 'max'
[root@centos7 ~]# df -lh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #sdb 容量已達到40GB
文件系統? ? ? ? ? ? ? ? 容量? 已用? 可用 已用% 掛載點
/dev/mapper/centos-root? 18G? 6.8G? 11G? 39% /
devtmpfs? ? ? ? ? ? ? ? 481M? ? 0? 481M? ? 0% /dev
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 80K? 490M? ? 1% /dev/shm
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 7.1M? 483M? ? 2% /run
tmpfs? ? ? ? ? ? ? ? ? ? 490M? ? 0? 490M? ? 0% /sys/fs/cgroup
/dev/sda1? ? ? ? ? ? ? ? 497M? 126M? 372M? 26% /boot
/dev/sdb? ? ? ? ? ? ? ? ? 40G? 1.1M? 38G? ? 1% /mydata
[root@centos7 ~]# btrfs device add /dev/sdd /mydata? ? ? ? ? ? ? #將sdd 磁盤添加到btrfs文件系統里
[root@centos7 ~]# df -lh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #mydata目錄容量已達到60GB
文件系統? ? ? ? ? ? ? ? 容量? 已用? 可用 已用% 掛載點
/dev/mapper/centos-root? 18G? 6.8G? 11G? 39% /
devtmpfs? ? ? ? ? ? ? ? 481M? ? 0? 481M? ? 0% /dev
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 80K? 490M? ? 1% /dev/shm
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 7.1M? 483M? ? 2% /run
tmpfs? ? ? ? ? ? ? ? ? ? 490M? ? 0? 490M? ? 0% /sys/fs/cgroup
/dev/sda1? ? ? ? ? ? ? ? ? ? ? ? 497M? 126M? 372M? 26% /boot
/dev/sdb? ? ? ? ? ? ? ? ? 60G? 1.1M? 56G? ? 1% /mydata
[root@centos7 ~]# btrfs balance status /mydata/? ? ? ? ? ? ? ? #檢查 btrfs平衡的狀態信息
No balance found on '/mydata/'
[root@centos7 ~]# btrfs balance start /mydata/? ? ? ? ? ? ? ? ? #啟動 btrfs平衡的狀態,將數據平衡到磁盤上
Done, had to relocate 6 out of 6 chunks
[root@centos7 ~]# btrfs device delete /dev/sdb /mydata/? ? ? #在線將磁盤移除,系統默認會把所在磁盤上的數據移走
[root@centos7 ~]# df -lh? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #此時的mydata容量為40GB
文件系統? ? ? ? ? ? ? ? 容量? 已用? 可用 已用% 掛載點
/dev/mapper/centos-root? 18G? 6.8G? 11G? 39% /
devtmpfs? ? ? ? ? ? ? ? 481M? ? 0? 481M? ? 0% /dev
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 80K? 490M? ? 1% /dev/shm
tmpfs? ? ? ? ? ? ? ? ? ? 490M? 7.1M? 483M? ? 2% /run
tmpfs? ? ? ? ? ? ? ? ? ? 490M? ? 0? 490M? ? 0% /sys/fs/cgroup
/dev/sda1? ? ? ? ? ? ? ? ? ? ? ? 497M? 126M? 372M? 26% /boot
/dev/sdc? ? ? ? ? ? ? ? ? 40G? 1.1M? 38G? ? 1% /mydata
[root@centos7 ~]# btrfs filesystem show /mydata/
Btrfs v3.16.2
[root@centos7 ~]# ll -l /mydata/
總用量 20
-rw-r--r--. 1 root root? ? 0 8月? 23 17:26 a.txt
-rw-r--r--. 1 root root 13430 8月? 23 17:38 functions
-rw-r--r--. 1 root root? 4028 8月? 23 17:26 grub2.cfg
[root@centos7 ~]# cat /mydata/grub2.cfg? ? ? ? ? ? ? #mydata目錄里的文件照樣可以拜訪
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
if [ -s $prefix/grubenv ]; then
? load_env
fi
if [ "${next_entry}" ] ; then
[root@centos7 ~]# btrfs device add /dev/sdb /mydata/? ? ? ? ? ? ? ? ? #添加設備到btrfs系統里,下面要做rida5,需要3塊磁盤
[root@centos7 ~]# btrfs filesystem show /mydata/
Btrfs v3.16.2
[root@centos7 ~]# btrfs balance start -mconvert=raid5 /mydata/? ? ? ? #將元數據動態改成raid
Done, had to relocate 2 out of 3 chunks
[root@centos7 ~]# btrfs balance start -dconvert=raid5 /mydata/? ? ? ? ? #將數據動態改成raid5
Done, had to relocate 1 out of 3 chunks
[root@centos7 ~]# btrfs subvolume list /mydata/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #因為沒有創建子卷,所以沒有列表顯示
[root@centos7 ~]# btrfs subvolume create /mydata/logs? ? ? ? ? ? ? ? #在mydata下創建子卷,子卷名為logs
Create subvolume '/mydata/logs'
[root@centos7 ~]# btrfs subvolume list /mydata/? ? ? ? ? ? ? ? ? ? ? ? #顯示子卷列表為logs
ID 263 gen 92 top level 5 path logs
[root@centos7 ~]# btrfs subvolume create /mydata/cache
Create subvolume '/mydata/cache'
[root@centos7 ~]# btrfs subvolume list /mydata/
ID 263 gen 92 top level 5 path logs
ID 264 gen 93 top level 5 path cache
[root@centos7 ~]# umount /mydata/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #卸載mydata
[root@centos7 ~]# mount -o subvol=logs /dev/sdb /mnt? ? ? ? ? ? ? #需要掛載子卷,要先把父卷卸載,掛載logs子卷,掛載在mnt目錄下
?[root@centos7 ~]# ls /mnt
[root@centos7 ~]# cp /var/log/messages /mnt? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #將messages文件拷貝到logs掛載的mnt目錄下
[root@centos7 ~]# ls /mnt/
messages
[root@centos7 ~]# btrfs subvolume show /mnt? ? ? ? ? ? ? ? ? ? ? ? ? ? #顯示子卷的詳細信息
/mnt
? ? Name:? ? ? ? ? ? logs
? ? uuid:? ? ? ? ? ? f11b002b-db2f-a44c-a53a-ab37eaddfc8a
? ? Parent uuid:? ? ? ? -
? ? Creation time:? ? ? ? 2016-08-23 20:28:30
? ? Object ID:? ? ? ? 263
? ? Generation (Gen):? ? 96
? ? Gen at creation:? ? 92
? ? Parent:? ? ? ? 5
? ? Top Level:? ? ? ? 5
? ? Flags:? ? ? ? ? ? -
? ? Snapshot(s):
[root@centos7 ~]# umount /mnt/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #卸載子卷,掛載父卷
[root@centos7 ~]# mount /dev/sdb /mydata/? ? ? ? ? ? ? ? ? ? ? ? ? ? #掛載父卷
[root@centos7 ~]# ls /mydata/logs/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #掛載子卷時的文件,把子卷卸載了,掛載父卷數據依然存在 ,但是單獨掛載子卷,父卷就無法拜訪
messages
[root@centos7 ~]# btrfs subvolume delete /mydata/logs/? ? ? ? ? #刪除子卷,前提是要掛載父卷,才能刪除子卷
Transaction commit: none (default)
Delete subvolume '/mydata/logs'
[root@centos7 ~]# btrfs subvolume list /mydata? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #只顯示cache子卷
ID 264 gen 93 top level 5 path cache
[root@centos7 ~]# btrfs subvolume create /mydata/logs? ? ? ? ? ? ? ? #創建子卷
Create subvolume '/mydata/logs'
[root@centos7 ~]# cp /etc/grub2.cfg /mydata/logs/? ? ? ? ? ? ? ? ? ? #將文件拷貝到子卷里
[root@centos7 ~]# btrfs subvolume snapshot /mydata/logs/ /mydata/logs/_snapshot? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #給子卷創建快照,快照卷要與原卷必須 在同一個卷組中,子卷快照必須在父卷組中
Create a snapshot of '/mydata/logs/' in '/mydata/logs_snapshot'
[root@centos7 ~]# btrfs subvolume list /mydata/? ? ? ? ? ? ? ? ? #在列表中就多了一個子卷
ID 264 gen 93 top level 5 path cache
ID 265 gen 101 top level 5 path logs
ID 266 gen 101 top level 265 path logs_snapshot
[root@centos7 ~]# cd /mydata/logs_snapshot/? ? ? ? ? ? ? ? ? ? ? ? ? #進入到子卷快照中
[root@centos7 logs_snapshot]# ll? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #可以看到子卷里的文件
總用量 4
-rw-r--r--. 1 root root 4028 8月? 23 20:42 grub2.cfg
drwxr-xr-x. 1 root root? ? 0 8月? 23 20:47 _snapshot
[root@centos7 logs_snapshot]# cat grub2.cfg? ? ? ? ? ? ? ? #快照里的文件也可以正常拜訪
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
if [ -s $prefix/grubenv ]; then
? load_env
fi
if [ "${next_entry}" ] ; then
? set default="${next_entry}"
? set next_entry=
? save_env next_entry
? set boot_once=true
else
? set default="${saved_entry}"
fi
if [ x"${feature_menuentry_id}" = xy ]; then
? menuentry_id_option="--id"
else
? menuentry_id_option=""
fi
[root@centos7 logs_snapshot]# vim /mydata/logs/grub2.cfg? ? ? ? ? ? ? #在文件首行里添加新內容
# How are you!!!!
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
[root@centos7 logs_snapshot]# cat grub2.cfg? ? ? #快照子卷里并沒有剛才所添加的內容
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
[root@centos7 mydata]# btrfs subvolume delete /mydata/logs_snapshot/? ? #刪除子卷快照
Transaction commit: none (default)
Delete subvolume '/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 chunks
[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/? ? ? ? ? ? ? ? ? #拆除磁盤sdd
[root@centos7 ~]# fdisk /dev/sdd
歡迎使用 fdisk (util-linux 2.23.2).
更改將停留在內存中,直到您決定將更改寫入磁盤.
使用寫入命令前請三思.
Device does not contain a recognized partition table
使用磁盤標識符 0xc3fdf033 創建新的 DOS 磁盤標簽.
命令(輸入 m 獲取幫助):n
Partition type:
? p? primary (0 primary, 0 extended, 4 free)
? e? extended
Select (default p): p
分區號 (1-4,默認 1):
起始 扇區 (2048-41943039,默認為 2048):
將使用默認值 2048
Last 扇區, +扇區 or +size{K,M,G} (2048-41943039,默認為 41943039):+5G
分區 1 已設置為 Linux 類型,大小設為 5 GiB
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤.
[root@centos7 ~]# partx -a /dev/sdd
partx: /dev/sdd: error adding partition 1
[root@centos7 ~]# partx -a /dev/sdd
partx: /dev/sdd: error adding partition 1
[root@centos7 ~]# mke2fs -t ext4 /dev/sdd1? #格式化sdd1
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
? ? 32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成? ? ? ? ? ? ? ? ? ? ? ? ? ?
正在寫入inode表: 完成? ? ? ? ? ? ? ? ? ? ? ? ? ?
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@centos7 ~]# mount /dev/sdd1 /mnt/
[root@centos7 ~]# cp /etc/fstab? /mnt
[root@centos7 ~]# cat /mnt/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 31 21:49:05 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /? ? ? ? ? ? ? ? ? ? ? xfs? ? defaults? ? ? ? 0 0
UUID=51337a51-d4e3-4c36-bc23-e99029ea570b /boot? ? ? ? ? ? ? ? ? xfs? ? defaults? ? ? ? 0 0
/dev/mapper/centos-swap swap? ? ? ? ? ? ? ? ? ? swap? ? defaults? ? ? ? 0 0
[root@centos7 ~]# umount /mnt/? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #卸載mnt, 聯機將文件系統改成btrfs文件有風險,所以要先做卸載動作
[root@centos7 ~]# fsck -f /dev/sdd1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #對文件強制做檢測
fsck,來自 util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結構
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/sdd1: 12/327680 files (0.0% non-contiguous), 58463/1310720 blocks
[root@centos7 ~]# btrfs-convert /dev/sdd1? ? ? ? ? ? ? ? ? ? #將sdd1轉換成btrfs文件系統
creating btrfs metadata.
creating ext2fs image file.
cleaning up system chunk.
conversion complete.
[root@centos7 ~]# btrfs filesystem show? ? ? ? ? ? ? ? ? ? ? ? ? ? #新的文件系統sdd1出現了
Label: 'mydata'? uuid: 6dfeb558-63ca-43cb-ac46-a95ce7375511
? ? Total devices 2 FS bytes used 696.00KiB
? ? devid? ? 2 size 20.00GiB used 2.03GiB path /dev/sdc
? ? devid? ? 4 size 20.00GiB used 1.03GiB path /dev/sdb
Label: none? uuid: f6e6dddd-bec5-4884-a411-952d2ca7a72c
? ? Total devices 1 FS bytes used 228.42MiB
? ? devid? ? 1 size 5.00GiB used 5.00GiB path /dev/sdd1
Btrfs v3.16.2
[root@centos7 ~]# mount /dev/sdd1 /mnt? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #此時就可以掛載使用了
[root@centos7 ~]# cd /mnt/?
[root@centos7 mnt]# ls
ext2_saved? fstab? lost+found
[root@centos7 mnt]# cat fstab? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #文件可以正常拜訪
#
# /etc/fstab
# Created by anaconda on Thu Dec 31 21:49:05 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /? ? ? ? ? ? ? ? ? ? ? xfs? ? defaults? ? ? ? 0 0
UUID=51337a51-d4e3-4c36-bc23-e99029ea570b /boot? ? ? ? ? ? ? ? ? xfs? ? defaults? ? ? ? 0 0
/dev/mapper/centos-swap swap? ? ? ? ? ? ? ? ? ? swap? ? defaults? ? ? ? 0 0
[root@centos7 mnt]# umount /mnt? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #先卸載mnt目錄
[root@centos7 ~]# btrfs-convert -r /dev/sdd1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #將sdd1降級回去, 不加"-r",無法將文件系統轉換回"ext4"
rollback complete.
[root@centos7 ~]# blkid /dev/sdd1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #文件系統就降級回ext4
/dev/sdd1: UUID="ad08cf9d-24ff-49b8-8c54-78c9962d78e7" TYPE="ext4"
更多CentOS相關信息見CentOS 專題頁面 /topicnews.aspx?tid=14
本文永遠更新鏈接地址:
歡迎參與《LINUX學習:CentOS 7上配置Btrfs文件系統》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/9018.html