未安装nbd模块
[zhaojq@localhost ~]$ modprobe nbd
modprobe: FATAL: Module nbd not found.
查看linux版本
[zhaojq@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[zhaojq@localhost ~]$ uname -r
3.10.0-514.26.2.el7.x86_64
安装
[root@localhost tmp]# yum install kernel-devel kernel-headers
注意: wget的地址需要根据自身的系统版本设定
[root@localhost tmp]# cd /tmp/
[root@localhost tmp]# wget http://vault.centos.org/7.3.1611/os/Source/SPackages/kernel-3.10.0-514.el7.src.rpm
在/root/rpmbuild/SOURCES下生成linux-3.10.0-514.el7.tar.xz
[root@localhost SOURCES]# rpm -ihv kernel-3.10.0-123.el7.src.rpm
[root@localhost SOURCES]# cd ~/rpmbuild/SOURCES
[root@localhost SOURCES]# tar Jxvf linux-3.10.0-123.el7.tar.xz -C /usr/src/kernels/
[root@localhost SOURCES]# cd /usr/src/kernels/
/usr/src/kernels/ 路径下出现 3.10.0-514.26.2.el7.x86_64 和linux-3.10.0-514.el7两个文件夹
[root@localhost kernels]# mv $(uname -r) $(uname -r)-old
[root@localhost kernels]# mv linux-3.10.0-123.el7 $(uname -r)
[root@localhost kernels]# cd $(uname -r)
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make mrproper
[root@localhost 3.10.0-514.26.2.el7.x86_64]# cp ../$(uname -r)-old/Module.symvers ./
[root@localhost 3.10.0-514.26.2.el7.x86_64]# cp /boot/config-$(uname -r) ./.config
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make oldconfig
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make prepare
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make scripts
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make CONFIG_BLK_DEV_NBD=m M=drivers/block
[root@localhost 3.10.0-514.26.2.el7.x86_64]# cp drivers/block/nbd.ko /lib/modules/$(uname -r)/kernel/drivers/block/
[root@localhost 3.10.0-514.26.2.el7.x86_64]# depmod -a
错误处理
make scripts
- 错误:
Makefile:901: "Cannot use CONFIG_STACK_VALIDATION,please install libelf-dev or elfutils-libelf-devel"
- 解决办法:
yum install elfutils-libelf-devel
make CONFIG_BLK_DEV_NBD=m M=drivers/block
- 错误:
make[1]: *** 没有规则可以创建“drivers/block/floppy.o”需要的目标“tools/objtool/objtool”。 停止。
- 解决办法:
首先查看make scripts时是否出错,解决后,从make prepare命令开始重新执行
[root@localhost 3.10.0-514.26.2.el7.x86_64]# make prepare
scripts/kconfig/conf --silentoldconfig Kconfig
make[1]: 对“all”无需做任何事。
ke[1]: 对“relocs”无需做任何事。
▽ CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: “arch/x86/purgatory/kexec-purgatory.c”是最新的。
CALL scripts/checksyscalls.sh
DESCEND objtool
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/fixdep.o
LD /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/fixdep-in.o
LINK /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/fixdep
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/exec-cmd.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/help.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/pager.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/parse-options.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/run-command.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/sigchain.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/subcmd-config.o
LD /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/libsubcmd-in.o
AR /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/libsubcmd.a
GEN /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/arch/x86/insn/inat-tables.c
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/arch/x86/decode.o
LD /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/arch/x86/objtool-in.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/builtin-check.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/elf.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/special.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/objtool.o
CC /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/libstring.o
LD /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/objtool-in.o
LINK /usr/src/kernels/3.10.0-514.26.2.el7.x86_64/tools/objtool/objtool
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
- 解决办法:
bug已提交: https://bugs.centos.org/view.php?id=12248
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,将sreq.cmd_type直接定义为7
//sreq.cmd_type = REQ_TYPE_SPECIAL;
sreq.cmd_type = 7;
3、重新执行 make CONFIG_BLK_DEV_NBD=m M=drivers/block
运行
[zhaojq@localhost ~]$ modinfo nbd
filename: /lib/modules/3.10.0-514.26.2.el7.x86_64/kernel/drivers/block/nbd.ko
license: GPL
description: Network Block Device
rhelversion: 7.3
srcversion: EDE909A294AC5FE08E81957
depends:
vermagic: 3.10.0 SMP mod_unload modversions
parm: nbds_max:number of network block devices to initialize (default: 16) (int)
parm: max_part:number of partitions per device (default: 0) (int)
parm: debugflags:flags for controlling debug output (int)
原文链接:https://www.f2er.com/centos/376619.html