DRBD Notes (1)

· 768 words · 2 minute read

最近开始接触 DRBD,具体来说,DRDB 9 - 这是一个 CentOS 7.2 还没有第三方 rpm 的版本,也就是说要自己编译。呵呵,C, Makefile, autotools, Kernel Module,十年前就磨练过的技能。

编译环境 🔗

为了加快时间,充分利用本机 SSD,本地装了一个 CentOS 7.2 的系统。

yum install kernel-devel rpm-build gcc
curl -O http://oss.linbit.com/drbd/9.0/drbd-9.0.1-1.tar.gz

然后注意到安装的 kernel-devel 是版本 3.10.0-514,而不是已有的3.10.0-327。出于谨慎,重新启动,保证 uname -rkernel-devel 的版本是一致的。

西湖的水 🔗

我的泪!然后就开始了折腾。

make kmp-rpm 报错 🔗

In file included from /root/rpmbuild/BUILD/drbd-9.0.1-1/obj/default/drbd_int.h:50:0,
                 from /root/rpmbuild/BUILD/drbd-9.0.1-1/obj/default/drbd_bitmap.c:35:
/root/rpmbuild/BUILD/drbd-9.0.1-1/obj/default/drbd-kernel-compat/drbd_wrappers.h:1516:8: error: redefinition of 'struct ib_cq_init_attr'
 struct ib_cq_init_attr {
        ^

心里一凉。研究了一下,改了点代码成功绕过。后来发现 OpenSuSE 也有一个几乎一样的补丁。叹了口气,又多了点信心 - 就像长途奔袭后终于找到组织。

安装 kmod-drbd 失败 🔗

还没来得及高兴,就得到一个安装失败:

# rpm -i rpmbuild/RPMS/x86_64/kmod-drbd-9.0.1_3.10.0_514.10.2-1.el7.centos.x86_64.rpm
error: Failed dependencies:
        ksym(kfree_skb) = 0x195c9f2c is needed by kmod-drbd-9.0.1_3.10.0_514.10.2-1.el7.centos.x86_64
        ksym(nla_put_nohdr) = 0x1ca25ace is needed by kmod-drbd-9.0.1_3.10.0_514.10.2-1.el7.centos.x86_64
        ksym(__vmalloc) = 0xa9bd2676 is needed by kmod-drbd-9.0.1_3.10.0_514.10.2-1.el7.centos.x86_64

加载内核模块CRC 校验 失败!

Module versioning is enabled by the CONFIG_MODVERSIONS tag, and is used as a simple ABI consistency check. A CRC value of the full prototype for an exported symbol is created. When a module is loaded/used, the CRC values contained in the kernel are compared with similar values in the module; if they are not equal, the kernel refuses to load the module as it indicates that the module is built with reference to a different version of the Linux kernel source.

搜索发现 RedHat bugzillabug 767738,看起来也是一样的问题。但那是 RHEL 6.2,而我现在是 CentOS 7.2,相隔将近 5 年,理论上来说,早就该修复了。

重建环境 🔗

CentOS 7.2 DVD 重建了一个纯 7.2 环境:

mkdir /media/CentOS
mount /dev/cdrom /media/CentOS
yum --disablerepo=* --enablerepo=c7-media install gcc kernel-devel

然后重新走了以上步骤。几乎吐血:

  1. make kmp-rpm 不再有 ib_cq_init_attr 重复定义的报错;
  2. 编译出来的 rpm 包顺利安装没毛病!

接下来编译drdb-utils,过程中除了 xsltproc 很慢之外也没啥好说的,一切顺利。然而安装的时候暴露出本来面目:

# rpm -i rpmbuild/RPMS/x86_64/drbd-utils-8.9.6-1.el7.centos.x86_64.rpm
        file /usr/sbin/drbdadm conflicts between attempted installs of drbd-utils-8.9.6-1.el7.centos.x86_64 and drbd-utils-8.9.6-1.el7.centos.x86_64
        file /usr/sbin/drbdmeta conflicts between attempted installs of drbd-utils-8.9.6-1.el7.centos.x86_64 and drbd-utils-8.9.6-1.el7.centos.x86_64
        file /usr/sbin/drbdsetup conflicts between attempted installs of drbd-utils-8.9.6-1.el7.centos.x86_64 and drbd-utils-8.9.6-1.el7.centos.x86_64

还好在 drdb-user 邮件列表中,维护者之一 Lars 给出了答案。解决办法就是修改drbd.spec.in

--- a/drbd.spec.in
+++ b/drbd.spec.in
@@ -31,6 +31,7 @@
 # conditionals may not contain "-" nor "_", hence "bashcompletion"
 %bcond_without bashcompletion
 %bcond_without sbinsymlinks
+%undefine with_sbinsymlinks
 # --with xen is ignored on any non-x86 architecture
 %bcond_without xen
 %bcond_without 83support

有的教程会直接告诉你怎么改,但是没有像 Lars 一样解释原因。

comments powered by Disqus