Openvswitch RPM build on Centos 7

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 series. So I recommend you to do same. It can be found at (at the moment, 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

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, and 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 is listed, we’re good to go.

After you fix 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 complete, 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

 

 

System Sleep States

When you put your computer to suspend, it will turn some of its devices to power saving mode to preserve energy consumption. But computers have many sleep states from deeper to shallow just like humans. The most shallow one is the freeze (or S0-idle) which only puts CPU to idle and if possible turn other devices to less power consuming mode. The most deeper one is the “Sleep-to-Memory” (or S3) in which CPU is turned off, and nearly only memory and some critical devices uses energy. It is also possible to suspend-to-disk (S4, S5), with STD current state of computer saved to disk. STD is called hibernate. In hibernate cold reboot will be performed so, it will take longer to restore the state.

Continue reading

SysReq, Raising Elephants Is So Utterly Boring

SysRq keyboard key is very magical. You can perform a safe reboot a locked up computer with this key.

To achieve this remember mnemonics: “Raising Elephants Is So Utterly Boring”

To use SysRq:

  • Press Alt and SysRq (Print Screen) keys at the same time (but do NOT release them)
  • While holding Alt and SysRq keys down, press the key: R, wait few seconds
  • While holding Alt and SysRq keys down, press the key: E, wait few seconds
  • While holding Alt and SysRq keys down, press the key: I, wait few seconds
  • While holding Alt and SysRq keys down, press the key: S, wait few seconds
  • While holding Alt and SysRq keys down, press the key: U, wait few seconds
  • While holding Alt and SysRq keys down, press the key: B, wait few seconds

Computer will reboot now!

Reclaim empty space from, Shrink disk of qcow2 disk file

To reclaim disk space (in other words to shrink disk space) of qcow2 disk file you need to run following steps.

1. Fill guest disk with empty file

This is required since disk does not really hold its configured size, instead it has a sparse file format in creation time. After a while disk gets writes, temporary file creations/deletions that result non zero blocks in qcow2 file which are useless in reality (i.e. temporarily created file and deleted later). So to gain this space we’ll create a file that takes all space available in backing store (here qcow2 file). This file will only contain zeros. That way qemu-img will skip copying zeros and it will only mark the meta-data of zero sequence (for example length of it).

To do this, turn on virtual machine and in virtual machine’s terminal (you can use ssh to connect):

dd if=/dev/zero of=/tempzerofile
 dd will read from /dev/zero and write to /tempzerofile until all disk space is full. Now remove the file:
 rm /tempzerofile

2. Reclaim unused disk space from qcow2 file

Now turn virtual machine off, and run below command in your host machine to reclaim unused space back. Remember this space is marked with zeros and these type of files are called “sparse file”.

qemu-img convert -O qcow2 image.qcow2 shrinked_image.qcow2

where image is the original image whose size is big and we want to shrink it. shrinked_image is the destination image we want to create.