Bcache, CentOS 7.1 (w/kernel >= 3.10)

Bcache is not enabled by default in CentOS 7.1. However, you do not need to recompile whole kernel.
It is sufficient to compile module and add it to existing kernel.

 
yum groupinstall "Development Tools" -y
yum install kernel-headers -y

Unfortunately, kernel headers do not include all you need.
You have to download adequate kernel sources from the CentOS site: http://vault.centos.org/N.N.YYMM/os/Source/SPackages/kernel-3.10.0-229.el7.src.rpm

In my case it was kernel-3.10.0-229.el7:

mkdir ~/kernel
cd ~/kernel
wget "http://vault.centos.org/7.1.1503/os/Source/SPackages/kernel-3.10.0-229.el7.src.rpm"
rpm2cpio - < kernel-3.10.0-229.el7.src.rpm
# OR
rpm2cpio ./kernel-3.10.0-327.el7.src.rpm  | cpio -idmv

Then, copy bcache directory from archive linux-3.10.0-229.el7.tar.xz into /usr/src/kernels/`uname -r`/drivers/md/.
You also need to copy files from block directory (from linux-3.10.0-229.el7.tar.xz):
cp linux-3.10.0-229/block/*.c /usr/src/kernels/3.10.0-229.11.1.el7.x86_64/block/
(I did it with Midnight Commander).
Now, you have to add the following lines to file "Makefile"

vi /usr/src/kernels/`uname -r`/drivers/md/bcache/Makefile
# set object type ("m" as module")
obj-m   += bcache.o
# add these instructions
all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:  
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
cd /usr/src/kernels/`uname -r`/drivers/md/bcache/
make
mkdir -p /usr/src/kernels/`uname -r`/drivers/md/bcache/
cp ./bcache.ko /usr/src/kernels/`uname -r`/drivers/md/bcache/
# or
cp /kernel/linux-3.10.0-327.el7/drivers/md/bcache/bcache.ko /lib/modules/3.10.0-327.36.1.el7.x86_64/kernel/drivers/md/
depmod -A
[root@db7 home]# modinfo bcache
filename:       /lib/modules/3.10.0-229.11.1.el7.x86_64/kernel/drivers/md/bcache/bcache.ko
author:         Kent Overstreet 
license:        GPL
license:        GPL
author:         Kent Overstreet 
rhelversion:    7.1
srcversion:     744AC1548F61C54B1445EF6
depends:        
vermagic:       3.10.0-229.11.1.el7.x86_64 SMP mod_unload modversions 

# Voila.

In case you are not able to compile only module you can compile the whole kernel (using .config of the existing kernel) and copy only bcache.ko file.

    • Alex
    • March 27th, 2016

    Thanks!

    • Roman
    • November 29th, 2016

    Thank you, man, that was helpful.
    Successfully built bcache with 4.8.11 from elrepo/kernel-ml.

    • Terry
    • January 19th, 2017

    Getting errors when I run make in /usr/src/kernels/3.10.0-514.el7.x86_64drivers/md/bcache/

    I simply added the make instructions to the bottom of the Make file before I ran make.

    Errors:

    from /usr/src/kernels/3.10.0-514.el7.x86_64/drivers/md/bcache/request.c:9:
    /usr/src/kernels/3.10.0-514.el7.x86_64/drivers/md/bcache/request.c:1217:34: error: ‘struct task_struct’ has no member named ‘sequential_io’
    if (cutoff task->sequential_io,

    • Terry
    • January 23rd, 2017

    I followed the above steps to the letter on CentOS_7.3 3.10.0-514.el7.x86_64 and ran into insurmountable errors. I don’t believe the steps are correct and my challenge to those who wrote this to follow them to a successful outcome.

    I fully expect the moderator to delete my comments because this is post as shown totally bogus.

  1. Hi,
    As I wrote at the bottom of the post – if you ran into problems you could try to compile the whole kernel.
    I did it successfully with kernel you mentioned.

    wget “http://vault.centos.org/7.3.1611/os/Source/SPackages/kernel-3.10.0-514.el7.src.rpm”
    rpm2cpio ./kernel-3.10.0-514.el7.src.rpm | cpio -idmv
    sudo sh -c ‘yes “” | make oldconfig’
    # now enable with the following option: CONFIG_BCACHE=m
    make

    # After comilation is completed you need to add the bcache to the actual kernel modules (uname -r)
    cp ./YOUR_BUILD/your-bcache_path/ /usr/lib/modules/3.10.0-514.2.2.el7.x86_64/kernel/drivers/md/bcache.ko
    # and load the module
    modprobe -f bcache

    • earl
    • June 24th, 2017

    @Przemysław Budny
    Can you provide more clarification on how you got this to compile on centos 7. I tried and get the error No rule to make target ‘oldconfig’. What directory are you running this command in? I was in the ~/kernel folder after i ran the rpm2cpio. if this works where will the bcache.ko be located and where/ what file do you modify to add config_bcache=…

  2. Probably you cannot find the file with existing configuration. Try to install kernel-devel and kernel-headers.x86_64.
    You should find this file in such manner:

    find /usr/src/kernels/$(uname -r) -name '.config'

    There are my steps

    cd /home/
    wget "http://vault.centos.org/7.3.1611/os/Source/SPackages/kernel-3.10.0-514.el7.src.rpm"
    http://evilpiepirate.org/git/linux-bcache.git
    rpm2cpio ./kernel-3.10.0-514.el7.src.rpm | cpio -idmv
    tar xf linux-3.10.0-514.el7.tar.xz
    yum groupinstall "Development Tools" -y
    find ./linux-3.10.0-514.el7/drivers/md/bcache/ ./linux-bcache/drivers/md/bcache/ -name '*.c' -or -name '*.h' | sort -t'/' -k 5 | xargs -n 1 md5sum
    # find ./linux-3.10.0-514.el7/drivers/md/bcache/ -name '*.c' -or -name '*.h' | xargs -n 1 md5sum| awk '{print "echo " $1 "; basename " $2" | xargs find ./linux-bcache/drivers/md/bcache/ "}'
    make oldconfig
    # in .config you have to uncomment variable CONFIG_BCACHE and set it as bellow:

    CONFIG_BCACHE=m
    make
    find ./ -name ‘bcache.ko’ | xargs -n1 -I'{}’ echo cp {} /usr/lib/modules/$(uname -r)/kernel/drivers/md/
    # Important – you have to be in the directory in which the compilation occured
    depmod -A
    modinfo bcache
    modprobe –force-vermagic –force-modversion -vvvv bcache

    However, you can use elrepo – counterpart kernel for CentOS – it contains the module for bcache and works find.

    • jerry
    • March 31st, 2019

    Hi @Przemysław Budny
    I am compiling bcache error on centos7.6 (1810), can you check it for me?

    This is the process:

    Wget http://vault.centos.org/7.6.1810/os/Source/SPackages/kernel-3.10.0-957.el7.src.rpm
    Rpm2cpio ./kernel-3.10.0-957.el7.src.rpm | cpio -idmv
    Tar -xf linux-3.10.0-957.el7.tar.xz
    Cd linux-3.10.0-957.el7
    Cp /boot/config-3.10.0-957.el7.x86_64 .config
    Modify .config to CONFIG_BCACHE=m
    Make -j `grep processor /proc/cpuinfo | wc -l`

    This is an error:

    LD kernel/built-in.o
    CC [M] drivers/md/bcache/request.o
    drivers/md/bcache/request.c: In function ‘bio_complete’:
    drivers/md/bcache/request.c:675:3: error: passing argument 1 of ‘part_round_stats’ makes pointer from integer without a cast [-Werror]
    part_round_stats(cpu, &s->d->disk->part0);
    ^
    In file included from include/linux/blkdev.h:9:0,
    from include/linux/blktrace_api.h:4,
    from drivers/md/bcache/bcache.h:181,
    from drivers/md/bcache/request.c:9:
    include/linux/genhd.h:408:13: note: expected ‘struct request_queue *’ but argument is of type ‘int’
    extern void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part);
    ^
    drivers/md/bcache/request.c:675:3: error: passing argument 2 of ‘part_round_stats’ makes integer from pointer without a cast [-Werror]
    part_round_stats(cpu, &s->d->disk->part0);
    ^
    In file included from include/linux/blkdev.h:9:0,
    from include/linux/blktrace_api.h:4,
    from drivers/md/bcache/bcache.h:181,
    from drivers/md/bcache/request.c:9:
    include/linux/genhd.h:408:13: note: expected ‘int’ but argument is of type ‘struct hd_struct *’
    extern void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part);
    ^
    drivers/md/bcache/request.c:675:3: error: too few arguments to function ‘part_round_stats’
    part_round_stats(cpu, &s->d->disk->part0);
    ^
    In file included from include/linux/blkdev.h:9:0,
    from include/linux/blktrace_api.h:4,
    from drivers/md/bcache/bcache.h:181,
    from drivers/md/bcache/request.c:9:
    include/linux/genhd.h:408:13: note: declared here
    extern void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part);
    ^
    cc1: all warnings being treated as errors
    make[3]: *** [drivers/md/bcache/request.o] Error 1
    make[2]: *** [drivers/md/bcache] Error 2
    make[1]: *** [drivers/md] Error 2
    make: *** [drivers] Error 2

  3. @jerry – can you try using http://elrepo.org/tiki/tiki-index.php – it contains the bcache module compiled.

    • jerry
    • March 31st, 2019

    @Przemysław Budny

    Thank you for your reply.

    I have installed the yum install https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm source. How do I install bcache next?

    Can you provide a simple document?

  1. No trackbacks yet.