红联Linux门户
Linux帮助

CentOS6编译装载nbd模块

发布时间:2015-09-05 15:07:06来源:linux网站作者:CasonChan

今天突然发现CentOS系统没有nbd模块,只能重新装下,下面记录下整个编译过程:

系统:CentOS6.5

内核:2.6.32-431.el6.x86_64


[root@localhost ~]# yum install -y kernel-headers kernel-devel

[root@localhost ~]# wget ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6ComputeNode/en/os/SRPMS/kernel-2.6.32-431.el6.src.rpm

[root@localhost ~]# rpm -ivh kernel-2.6.32-431.el6.src.rpm

[root@localhost ~]# cd ~/rpmbuild/SOURCES/

[root@localhost SOURCES]# tar jxf linux-2.6.32-431.el6.tar.bz2 -C /usr/src/kernels/

[root@localhost SOURCES]# cd /usr/src/kernels/

[root@localhost kernels]# mv $(uname -r) $(uname -r)-old

[root@localhost kernels]# mv  linux-2.6.32-431.el6 $(uname -r)

[root@localhost kernels]# cd $(uname -r)

[root@localhost 2.6.32-431.el6.x86_64]# make mrproper

[root@localhost 2.6.32-431.el6.x86_64]# cp ../$(uname -r)-old/Module.symvers .

[root@localhost 2.6.32-431.el6.x86_64]# cp /boot/config-$(uname -r) ./.config

[root@localhost 2.6.32-431.el6.x86_64]# make oldconfig

[root@localhost 2.6.32-431.el6.x86_64]# make prepare

[root@localhost 2.6.32-431.el6.x86_64]# make scripts

[root@localhost 2.6.32-431.el6.x86_64]# make CONFIG_BLK_DEV_NBD=m M=drivers/block

[root@localhost 2.6.32-431.el6.x86_64]# cp drivers/block/nbd.ko /lib/modules/$(uname -r)/kernel/drivers/block/

[root@localhost 2.6.32-431.el6.x86_64]# depmod -a


至此,nbd模块已经成功编译。

下面加载nbd模块并查看成功装载后的情况:


[root@localhost image]# modprobe nbd max_part=8
[root@localhost image]# ll /dev/nbd*
brw-rw---- 1 root disk 43,   0 Nov 20 21:24 /dev/nbd0
brw-rw---- 1 root disk 43,  16 Nov 20 21:24 /dev/nbd1
brw-rw---- 1 root disk 43, 160 Nov 20 21:24 /dev/nbd10
brw-rw---- 1 root disk 43, 176 Nov 20 21:24 /dev/nbd11
brw-rw---- 1 root disk 43, 192 Nov 20 21:24 /dev/nbd12
brw-rw---- 1 root disk 43, 208 Nov 20 21:24 /dev/nbd13
brw-rw---- 1 root disk 43, 224 Nov 20 21:24 /dev/nbd14
brw-rw---- 1 root disk 43, 240 Nov 20 21:24 /dev/nbd15
brw-rw---- 1 root disk 43,  32 Nov 20 21:24 /dev/nbd2
brw-rw---- 1 root disk 43,  48 Nov 20 21:24 /dev/nbd3
brw-rw---- 1 root disk 43,  64 Nov 20 21:24 /dev/nbd4
brw-rw---- 1 root disk 43,  80 Nov 20 21:24 /dev/nbd5
brw-rw---- 1 root disk 43,  96 Nov 20 21:24 /dev/nbd6
brw-rw---- 1 root disk 43, 112 Nov 20 21:24 /dev/nbd7
brw-rw---- 1 root disk 43, 128 Nov 20 21:24 /dev/nbd8
brw-rw---- 1 root disk 43, 144 Nov 20 21:24 /dev/nbd9
[root@localhost image]#