If you ever needed to build openvswitch for Centos 7 (including kernel module) this post may help you.
Commands to build a RPM:
Download openvswitch source. I’ve tested with 2.7.x and 2.9.x series. So I recommend you to do the same. It can be found at (if link becomes absolute look for a newer one, if newer one fails, look for this one)
http://openvswitch.org/releases/openvswitch-2.7.0.tar.gz
wget can be used to download it:
wget http://openvswitch.org/releases/openvswitch-2.7.0.tar.gz wget http://openvswitch.org/releases/openvswitch-2.9.0.tar.gz
we’ll be using some build tools, so install them to the system with the following command.
yum install gcc make python-devel openssl-devel kernel-devel graphviz ernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool python-six checkpolicy selinux-policy-devel
Then prepare the directories for rpmbuild.
mkdir -p rpmbuild/SOURCES/ mkdir -p rpmbuild/SPECS/
copy source to rpmbuild/SOURCES
cp openvswitch-2.7.0.tar.gz rpmbuild/SOURCES/
Now we have two copies of openvswitch source, one in SOURCES directory the other in the directory where we executed wget. Now navigate to the latter, and extract it.
tar xzf openvswitch-2.7.0.tar.gz
We’ll copy all spec files related to rhel to rpmbuild/SPECS/ from the directory that we extracted.
cp openvswitch-2.7.0/rhel/*.spec rpmbuild/SPECS/
We also need some files to be in SOURCES, so copy them as well,
cp openvswitch-2.7.0/rhel/* rpmbuild/SOURCES/
Now, it’s time to check our kernel version:
uname -a
3.10.0-514.el7.x86_64
yours may be different, so note your kernel version.
And finally time to build our kernel module for openvswitch:
rpmbuild -bb --without check -D "kversion 3.10.0-514.el7.x86_64" rpmbuild/SPECS/openvswitch-kmod-fedora.spec
If you updated your operating system, or had a kernel update, some of your links may be broken. To be more precise, link to build directory may be broken. You can check it with:
ls -la /lib/modules/3.10.0-514.el7.x86_64/build
This path should point to a directory, and if it is broken then we have to fix it.
Fixing broken build link (note that if you have this link with contents, do not run commands to fix this issue (4 command listed just below)):
rm /lib/modules/3.10.0-514.el7.x86_64/build cd /lib/modules/3.10.0-514.el7.x86_64/ ln -s /usr/src/kernels/3.10.0-514.el7.x86_64/ build ls build/
if contents of build are listed, we’re good to go.
After you fix previously mentioned broken link, go ahead and run same rpmbuild command again to build kernel module:
rpmbuild -bb --without check -D "kversion 3.10.0-514.el7.x86_64" rpmbuild/SPECS/openvswitch-kmod-fedora.spec
if it’s completed succesfully then run rpmbuild again to build user space programs (ovs-*)
rpmbuild -bb --without check -D "kversion 3.10.0-514.el7.x86_64" rpmbuild/SPECS/openvswitch.spec
If both of these commands successfully completed, you can install your openvswitch using generated rpms. Rpms can installed with:
rpm -ivh rpmbuild/RPMS/x86_64/openvswitch-kmod-2.7.0-1.el7.centos.x86_64.rpm rpm -ivh rpmbuild/RPMS/x86_64/openvswitch-2.7.0-1.x86_64.rpm
Either reboot, or modprobe to load kernel module and make some tests to check openvswitch.
Get OVS Version #ovs-vsctl -V
List bridge configuration #ovs-vsctl show
Create a new bridge #ovs-vsctl add-br ovs-br0
Add port to the bridge #ovs-vsctl add-port ovs-br0 eth1 #ovs-vsctl show