查看centos版本

cat /etc/redhat-release

#-> CentOS Linux release 7.4.1708 (Core)

查看自己内核版本

uname -r       #-> 3.10.0-693.el7.x86_64

 

 开始安装编译模块

yum install kernel-devel kernel-headers

cd /tmp

wget http://vault.centos.org/7.4.1708/os/Source/SPackages/kernel-3.10.0-693.el7.src.rpm

rpm -ihv kernel-3.10.0-693.el7.src.rpm  (这时会在/root/rpmbuild/SOURCES下生成tar.xz包)

cd ~/rpmbuild/SOURCES

tar Jxvf linux-3.10.0-693.el7.tar.xz -C/usr/src/kernels/

cd /usr/src/kernels/

mv $(uname -r) $(uname -r)-old

mv linux-3.10.0-693.el7 $(uname -r)

cd $(uname -r)

make mrproper

cp ../$(uname -r)-old/Module.symvers ./

cp /boot/config-$(uname -r) ./.config

make oldconfig

make prepare

make scripts

make CONFIG_BLK_DEV_NBD=m M=drivers/block

cp drivers/block/nbd.ko /lib/modules/$(uname -r)/kernel/drivers/block/

depmod -a

 

最后,modprobe nbd 启用nbd模块


期间会遇到错误,问题及解决办法如下:

1.  make scripts

错误:

Makefile:901: "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev or elfutils-libelf-devel"

解决:

yum install elfutils-libelf-devel


2.  make CONFIG_BLK_DEV_NBD=m M=drivers/block

错误:

drivers/block/nbd.c: 在函数‘__nbd_ioctl’中:
drivers/block/nbd.c:619:19: 错误:‘REQ_TYPE_SPECIAL’未声明(在此函数内第一次使用)
   sreq.cmd_type = REQ_TYPE_SPECIAL;
                   ^
drivers/block/nbd.c:619:19: 附注:每个未声明的标识符在其出现的函数内只报告一次
make[1]: *** [drivers/block/nbd.o] 错误 1
make: *** [_module_drivers/block] 错误 2

解决:

1、 REQ_TYPE_SPECIAL变量是在/usr/src/kernels/3.10.0-514.26.2.el7.x86_64/include/linux/blkdev.h文件中定义,由代码可知 REQ_TYPE_SPECIAL = 7:
/*
 * request command types
 */
enum rq_cmd_type_bits {
    REQ_TYPE_FS             = 1,    /* fs request */
    REQ_TYPE_BLOCK_PC,              /* scsi command */
    REQ_TYPE_SENSE,                 /* sense request */
    REQ_TYPE_PM_SUSPEND,            /* suspend request */
    REQ_TYPE_PM_RESUME,             /* resume request */
    REQ_TYPE_PM_SHUTDOWN,           /* shutdown request */
#ifdef __GENKSYMS__
    REQ_TYPE_SPECIAL,               /* driver defined type */
#else
    REQ_TYPE_DRV_PRIV,              /* driver defined type */
#endif
    /*
     * for ATA/ATAPI devices. this really doesn't belong here, ide should
     * use REQ_TYPE_DRV_PRIV and use rq->cmd[0] with the range of driver
     * private REQ_LB opcodes to differentiate what type of request this is
     */
    REQ_TYPE_ATA_TASKFILE,
    REQ_TYPE_ATA_PC,
};
2、修改drivers/block/nbd.c,在619行将sreq.cmd_type直接定义为7

//sreq.cmd_type = REQ_TYPE_SPECIAL;
sreq.cmd_type = 7;


GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐