bcache
entos7的内核3.10安装后没有/sys/fs/bcache/register,升级后4.4自动出现这个目录
下载
[root@localhost mnt]# git clone https://github.com/g2p/bcache-tools.git
Cloning into 'bcache-tools'...
remote: Counting objects: 498, done.
remote: Total 498 (delta 0), reused 0 (delta 0), pack-reused 498
Receiving objects: 100% (498/498), 106.14 KiB | 89.00 KiB/s, done.
Resolving deltas: 100% (257/257), done.
[root@localhost mnt]# ls
bcache-tools
[root@localhost mnt]# cd bcache-tools/
[root@localhost bcache-tools]# ls
69-bcache.rulesbcache.hbcache-super-show.8bcache-test.cdracutinitramfsmake-bcache.cprobe-bcache.8README
bcache.cbcache-register.cbcache-super-show.cCOPYINGinitcpiomake-bcache.8Makefileprobe-bcache.c
[root@localhost bcache-tools]#
编译
root@localhost bcache-tools]# make
cc -O2 -Wall -g `pkg-config --cflags uuid blkid`-c -o bcache.o bcache.c
cc -O2 -Wall -g `pkg-config --cflags uuid blkid`make-bcache.c bcache.o`pkg-config --libs uuid blkid` -o make-bcache
cc -O2 -Wall -g `pkg-config --cflags uuid blkid`probe-bcache.c`pkg-config --libs uuid blkid` -o probe-bcache
cc -O2 -Wall -g -std=gnu99bcache-super-show.c bcache.o`pkg-config --libs uuid` -o bcache-super-show
cc -O2 -Wall -g-c -o bcache-register.o bcache-register.c
ccbcache-register.o-o bcache-register
[root@localhost bcache-tools]# make install
install -m0755 make-bcache bcache-super-show/usr/sbin/
install -m0755 probe-bcache bcache-register/lib/udev/
install -m0644 69-bcache.rules/lib/udev/rules.d/
install -m0644 -- *.8 /usr/share/man/man8/
install -D -m0755 initramfs/hook/usr/share/initramfs-tools/hooks/bcache
install -D -m0755 initcpio/install/usr/lib/initcpio/install/bcache
install -D -m0755 dracut/module-setup.sh /lib/dracut/modules.d/90bcache/module-setup.sh
注:make时候会报blkid.h: No such file
解决 yum install libblkid-devel
因为我的sdb有数据所以要做一下这一步
[root@localhost bcache-tools]# wipefs -a /dev/sdb /dev/sdc
/dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x4fffffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioclt to re-read partition table: Success
【bcache】将sdb作为backing device,也就是HDD的盘符。
[root@localhost bcache-tools]# make-bcache -B /dev/sdb
UUID:1e957d89-9d85-4011-a582-09a21a320784
Set UUID:2959a329-b79c-4488-9006-ea3b2143477a
version:1
block_size:1
data_offset:16
将sdc作为cache device,也就是SSD的盘符。后面三个参数可以不要
[root@localhost bcache-tools]# make-bcache -C /dev/sdc -w4k -b1M --writeback
UUID:cf262569-b799-4e8f-9d06-7a27813005c1
Set UUID:5049fd85-0353-4177-b8b5-139446e14a49
version:0
nbuckets:20480
block_size:8
bucket_size:2048
nr_in_set:1
nr_this_dev:0
first_bucket:1
注:
参数意义:
-B: 设置backing device
-C: 设置cache device
-w: block size (hard sector size of SSD),默认是2K,可使用--block=4K代替
-b: bucket size,可以使用--bucket=1M代替
设备注册
格式化完成后需要完成设备的注册,使内核获取设备,可能由于内核版本的问题,在实际配置中发现,会报错,提示无法向register节点写入信息,但是并不影响使用。
[root@localhost bcache]# echo /dev/sdb > /sys/fs/bcache/register
-bash: echo: write error: Invalid argument
[root@localhost bcache]# echo /dev/sdc > /sys/fs/bcache/register
-bash: echo: write error: Invalid argument
设备绑定
完成注册的backing device需要在使用之前绑定到bchache,否则功能无法启用。首先找到完成注册的backing device设备的
[root@localhost bcache]# ls /sys/fs/bcache/
5049fd85-0353-4177-b8b5-139446e14a49registerregister_quiet
那么UUID= 5049fd85-0353-4177-b8b5-139446e14a49
[root@localhost bcache]# echo 5049fd85-0353-4177-b8b5-139446e14a49 > /sys/block/bcache0/bcache/attach
其中使用sdb作为backing device也就是HDD盘,sdc是SSD硬盘
[root@localhost ~]#lsblk
NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT
sdb8:16020G0 disk
└─bcache0252:0020G0 disk
sr011:01680M0 rom
sdc8:32020G0 disk
sda8:0020G0 disk
├─sda28:2019G0 part
│ ├─cl-swap 253:102G0 lvm[SWAP]
│ └─cl-root 253:0017G0 lvm/
└─sda18:101G0 part /boot
[root@localhost ~]#
格式化
[root@localhost ~]# mkfs.ext4 /dev/bcache0
挂载
[root@localhost ~]# mount /dev/bcache0 /mnt
[root@localhost ~]# df
Filesystem1K-blocksUsed Available Use% Mounted on
devtmpfs1002136010021360% /dev
tmpfs1013960010139600% /dev/shm
tmpfs1013960874410052161% /run
tmpfs1013960010139600% /sys/fs/cgroup
/dev/mapper/cl-root17811456 54066401240481631% /
/dev/sda1103833626617677216026% /boot
tmpfs20279602027960% /run/user/0
/dev/bcache02051130445080194012681% /mnt
完成 其中使用sdb作为backing device,sdc是SSD硬盘
[root@localhost ~]# lsblk
NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT
sdb8:16020G0 disk
└─bcache0252:0020G0 disk /mnt
sr011:01680M0 rom
sdc8:32020G0 disk
sda8:0020G0 disk
├─sda28:2019G0 part
│ ├─cl-swap 253:102G0 lvm[SWAP]
│ └─cl-root 253:0017G0 lvm/
└─sda18:101G0 part /boot
bcache device状态查看
[root@localhost ~]# bcache-super-show -f /dev/sdc
sb.magicok
sb.first_sector8 [match]
sb.csumC4ECE29EDDF45C24 [match]
sb.version3 [cache device]dev.label(empty)
dev.uuidcf262569-b799-4e8f-9d06-7a27813005c1
dev.sectors_per_block8
dev.sectors_per_bucket2048
dev.cache.first_sector2048
dev.cache.cache_sectors41940992
dev.cache.total_sectors41943040
dev.cache.orderedyes
dev.cache.discardno
dev.cache.pos0
dev.cache.replacement0 [lru]cset.uuid5049fd85-0353-4177-b8b5-139446e14a49
[root@localhost ~]# bcache-super-show -f /dev/sdb
sb.magicok
sb.first_sector8 [match]
sb.csumADE4CA9B43970BA5 [match]
sb.version1 [backing device]dev.label(empty)
dev.uuid1e957d89-9d85-4011-a582-09a21a320784
dev.sectors_per_block1
dev.sectors_per_bucket1024
dev.data.first_sector16
dev.data.cache_mode0 [writethrough]
dev.data.cache_state0 [detached]cset.uuid2959a329-b79c-4488-9006-ea3b2143477a
[root@localhost ~]#
停用设备
注销设备:
echo 1 >/sys/fs/bcache//unregister
停用bcache:
echo 1 >/sys/block/bcache0/bcache/stop
擦除磁盘残留数据:
wipefs -a /dev/sdc
wipefs -a /dev/sdb
工作模式
bcache有四种不同工作模式:
writethrough、writeback、writearouond、none
工作模式切换:
echo writeback > /sys/block/sdr/bcache/cache_mode
推荐阅读
- 热闹中的孤独
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 放屁有这三个特征的,请注意啦!这说明你的身体毒素太多
- 一个人的旅行,三亚
- 布丽吉特,人生绝对的赢家
- 慢慢的美丽
- 尽力
- 一个小故事,我的思考。
- 家乡的那条小河
- 《真与假的困惑》???|《真与假的困惑》??? ——致良知是一种伟大的力量