Category Archives: Linux

Raspberry Pi – Send Mails

Hello everyone, today I want to show you how to setup your Raspberry Pi to send mails via Googles SMTP server (smtp.gmail.com). I struggled a bit with Googles security settings and wanted to let you know how to solve the problems I encountered easily.

Before we begin you should update your Raspberry Pi:

sudo apt-get update

Next install ssmtp and mailutils:

sudo apt-get install ssmtp
sudo apt-get install mailutils

Next we will save the current default ssmtp.conf Configuration file:

sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.old

Now we will create a new ssmtp.conf Configuration file:

sudo nano /etc/ssmtp/ssmtp.conf

Now have a look at the Configuration below and replace username and password with your Account data:

root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username@gmail.com
AuthPass=password
FromLineOverride=YES
UseTLS=YES

Important: If your password contains the character # your Configuration will not work since the character # is used to define comments in the Configuration file. (Source: http://ubuntuforums.org/showthread.php?t=1691878)

Now run the below command to send a mail via ssmtp:

ssmtp <RecipientMailAddress>
Subject: <YourSubject>
<YourMailText>

or you can use the below command to send a mail via mailutils:

echo "<YourMailText>" | mail -s "<YourSubject>" <RecipientMailAddress>

When you run the above ssmtp command to send your mail you will probably receive an error message like shown in the below screenshot:

send_mail_raspberry_authentication_failed

The error “ssmtp: Authorization failed (534 5.7.14 …” means that the security settings of your Google Mail Account do not allow ssmtp to send mails.

To solve this problem you need to alter the security settings of your Google Mail Account by turning on the “Access for less secure apps” setting.

You can find this setting here: https://www.google.com/settings/security/lesssecureapps

The settings page should now look like this:

send_mail_raspberry_access_less_secure_apps

Now try again to send a mail and it should work now without problems.
Well, that´s it. You should now be able to send mails from your Raspberry Pi.

I hope you liked my post and I hope to see you again next time 🙂

Sources:

http://www.raspberry-projects.com/pi/software_utilities/email/ssmtp-to-send-emails

http://ozzmaker.com/2012/12/03/send-email-from-the-raspberry-pi-or-linux-command-line-with-attachments/

http://ubuntuforums.org/showthread.php?t=1691878

https://support.google.com/accounts/answer/6010255?hl=en

https://www.google.com/settings/security/lesssecureapps

Advertisements
Tagged , ,

Nagios – Use UTC

Hello everyone, today I want to show you how you can configure your Nagios server to use UTC time format. This is useful to prevent confusion if you have people from multiple time zones looking at your web interface and it makes reports from your web interface much more useful since you do not need to convert times to UTC first. Ok, let´s do this 🙂 (I did this on Ubuntu 14.04.2 – Btw the server was configured to use CEST as default time zone)

First we will open the nagios.cfg file by running the following command:

sudo nano /usr/local/nagios/etc/nagios.cfg

Now search for “use_timezone” and add the following line of code:

use_timezone=UTC

To configure the Nagios web interface to use UTC too we will need to do the following to:

First open the nagios.conf file by running the following command:

sudo nano /etc/apache2/sites-available/nagios.conf

And add this line of code to the “/usr/local/nagios/sbin” section:

SetEnv TZ "UTC"

Your nagios.conf file should now look like this:


# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
SetEnv TZ "UTC"
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

Now you need to restart the Nagios and Apache services to apply the changes.

Run the following command to restart Nagios:

sudo service nagios restart

And run this command to restart Apache:

sudo service apache2 restart

And that´s it.

Here is a screenshot before we applied our changes:

nagios_web_interface_before_utc

And here is a screenshot after we applied our changes:

nagios_web_interface_utc

Well, that´s it. Now your Nagios server will use UTC.

I hope you liked my today´s post and I hope to see you again next time 🙂

Sources:

http://scratching.psybermonkey.net/2011/04/nagios-time-within-nagios-is-incorrect.html

https://ihazem.wordpress.com/2012/03/14/changing-timezone-on-nagios-core-web-interface/

Tagged ,

Nagios – Change date format

Hello everyone, today a customer asked me to change the default date format for the Nagios web interface since he wanted an international date format instead of the default us date format. I thought I should share the procedure so here is how to do it (I did this on Ubuntu 14.04.2):

This is how the web interface looked before:

nagios_date_format_default

Ok. First open the nagios.cfg file by running the following command:

sudo nano /usr/local/nagios/etc/nagios.cfg

nagios_change_date_format

Next search for “date_format” and change it from:

date_format=us

to:

date_format=iso8601

Save and then restart the Nagios service by running:

sudo service nagios restart

After the Nagios service has successfully restarted your web interface will look like this:

nagios_date_format_iso8601

Well, that´s it. Now all dates will be displayed in the international ISO8601 date format on your Nagios web interface. (Btw this does not change the log file format.)

I hope you liked my today´s post and I hope to see you again next time 🙂

Sources:

http://forums.meulie.net/t/nagios-log-format/2978

Tagged ,

Ubuntu 14.04 QEMU/KVM Gaming Virtual Machine

Hello everyone. Today I want to show you a little project I have been working on for quite a while now. I found this great post a while ago and was pretty amazed by the fact that it is possible to play Current Gen 3D games inside of virtual machines! So I decided to try it on my own to get this working as well with my own setup. I gathered some hardware from ebay and Amazon and started building my test environment. Lets go:

Here is my setup:

Hardware:

Software:

  • Operating System: Ubuntu 14.0.4.1 LTS
  • Kernel: 3.13.0 – generic
  • Qemu: 2.0.0

Virtual Machine:

  • Operating System: Windows 8.1 Enterprise 64bit
  • Driver: AMD Catalyst Packages Omega (14.12) – (Display Driver ver. 14.501.1003)
  • Game: Left 4 Dead 2 (I admit that it is not really Current Gen but you know what I mean)

Prerequisites:

Before you start with the below instructions you need to enable IOMMU in your BIOS. Please make sure that this setting is working. I read that there are motherboards out there with faulty BIOS versions which will not allow you to enable this setting. (Maybe you will need to update your BIOS version so you can use this setting.)

Here is what I did to enable IOMMU on my Asrock 970 Extreme3 2.0 motherboard:

I entered the BIOS/UEFI by hitting DEL and found the setting in Advanced -> North Bridge Configuration -> IOMMU where I enabled it. (This setting will be disabled by default on the most motherboards.) Then I clicked on Exit -> Save Changes and Exit to complete this step.

After you have successfully enabled IOMMU in your BIOS you can proceed by installing Ubuntu.

You can check your Ubuntu and kernel version with the following command:

uname -a

Here are my Ubuntu and kernel version:

Linux test-desktop 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

As you can see I am currently using Ubuntu 14.04.1 LTS and my kernel version is 3.13.0 generic. (I know that 14.04.2 LTS is already out but I haven´t updated my system so far.)

I also installed an OpenSSH Server on my system so I can access my system remotely if I need to. (This step is completely optional.)

sudo apt-get install openssh-server

Installation QEMU/KVM

Now for the real deal. The first thing we need to do is to install QEMU and KVM. Simply run the below command to do so:

sudo apt-get install qemu-kvm

To check which version of QEMU got installed you can run this command:

kvm --version

The QEMU version I have installed at the moment is version 2.0.0 .

Edit modules and bootloader

The next thing you need to do is to edit the file “/etc/modules“. Simply add the modules listed below:


# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

lp
rtc
pci_stub
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_amd

Important: If you are using an Intel CPU you need to replace kvm_amd with kvm_intel.

Ok. Now you need to edit the file “/etc/default/grub“. There you need to find the line below and edit it to look like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1"

Important: If you are using an Intel CPU you need to replace amd_iommu with intel_iommu.

After you have edited the file it should look like this:


# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Now update Grub by running:

sudo update-grub

After the above command has finished reboot your computer to apply the changes:

sudo reboot

Blacklist Graphics Card

The next thing we need to do is to blacklist the graphics card we want to pass through to our virtual machine so that the host system will not use it for itself.

To get a list of PCI devices run the following command:

lspci -nn

Here is a list of my PCI devices:

00:00.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD/ATI] RD890 PCI to PCI bridge (external gfx0 port B) [1002:5a14] (rev 02)
00:00.2 IOMMU [0806]: Advanced Micro Devices, Inc. [AMD/ATI] RD990 I/O Memory Management Unit (IOMMU) [1002:5a23]
00:02.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] RD890 PCI to PCI bridge (PCI express gpp port B) [1002:5a16]
00:04.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] RD890 PCI to PCI bridge (PCI express gpp port D) [1002:5a18]
00:09.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] RD890 PCI to PCI bridge (PCI express gpp port H) [1002:5a1c]
00:11.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 SATA Controller [AHCI mode] [1002:4391] (rev 40)
00:12.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller [1002:4397]
00:12.2 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller [1002:4396]
00:13.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller [1002:4397]
00:13.2 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller [1002:4396]
00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 SMBus Controller [1002:4385] (rev 42)
00:14.1 IDE interface [0101]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 IDE Controller [1002:439c] (rev 40)
00:14.2 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 Azalia (Intel HDA) [1002:4383] (rev 40)
00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 LPC host controller [1002:439d] (rev 40)
00:14.4 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 PCI to PCI Bridge [1002:4384] (rev 40)
00:14.5 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI2 Controller [1002:4399]
00:15.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] SB700/SB800/SB900 PCI to PCI bridge (PCIE port 0) [1002:43a0]
00:15.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] SB900 PCI to PCI bridge (PCIE port 3) [1002:43a3]
00:16.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller [1002:4397]
00:16.2 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller [1002:4396]
00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 0 [1022:1600]
00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 1 [1022:1601]
00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 2 [1022:1602]
00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 3 [1022:1603]
00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 4 [1022:1604]
00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 15h Processor Function 5 [1022:1605]
01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Caicos [Radeon HD 6450/7450/8450 / R5 230 OEM] [1002:6779]
01:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Caicos HDMI Audio [Radeon HD 6400 Series] [1002:aa98]
02:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Caicos [Radeon HD 6450/7450/8450 / R5 230 OEM] [1002:6779]
02:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Caicos HDMI Audio [Radeon HD 6400 Series] [1002:aa98]
03:00.0 USB controller [0c03]: Etron Technology, Inc. EJ188/EJ198 USB 3.0 Host Controller [1b6f:7052]
06:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 06)

As you can see I have 2 identical graphics cards in my system which have the same identifier (This is normal). The strange thing is even after I had blacklisted them the GUI of my Ubuntu system would still continue working. The resolution dropped and windows started to open slower than before but nothing else. I´m not sure if this will cause issues in the future or not. (If you can use 2 different graphics cards. This will avoid possible issues.)

Ok. All you need to do here is to write down the addresses (02:00.0 and 02:00.1) and the identifiers (1002:6779 and 1002:aa98) of the graphics card you want to blacklist for your host and to pass through to your virtual machine.

Now you need to edit the file “/etc/initramfs-tools/modules” and add the identifiers of your graphics card. It should look like this:

# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax: module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
pci_stub ids=1002:6779,1002:aa98

After you have done this you need to run the below command to rebuild initramfs:

sudo update-initramfs -u

And of course you need to reboot your computer after the above command has finished:

sudo reboot

After your computer is up and running again run the following command to make sure that your graphics card was successfully blacklisted:

dmesg | grep pci-stub

The command should return something like that:

[ 1.473148] pci-stub: add 1002:6779 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[ 1.473174] pci-stub 0000:01:00.0: claimed by stub
[ 1.473193] pci-stub 0000:02:00.0: claimed by stub
[ 1.473199] pci-stub: add 1002:AA98 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[ 1.473206] pci-stub 0000:01:00.1: claimed by stub
[ 1.473215] pci-stub 0000:02:00.1: claimed by stub

As I have mentioned before I use 2 graphics cards with the same identifiers which is the reason why there are 4 addresses listed in the above example. If you use 2 different graphics cards with different identifiers there will only be 2 addresses listed if you blacklist one of them.

If the command does not deliver an output like the above example or nothing at all it means that your attempt at blacklisting your graphics card failed and you need to find out why. Unfortunately I can not give you advice how to troubleshoot this issue since I could not reproduce an issue like this.

Create VFIO config file

Now we will create a file containing the addresses of our graphics card we want to pass through to our virtual machine. To do so we create a new file called “/etc/vfio-pci1.cfg” and enter our addresses.

Important: You need to add “0000:” at the beginning of your addresses to make it work. Unfortunately I do not know why.

Here is an example how this file should look:

0000:02:00.0
0000:02:00.1

Ok. That´s it. Our graphics card is now ready to use.

Create disk for the virtual machine

This step is really simple. We need a virtual disk where we can install our virtual machine. Simply run the below command to create one:

dd if=/dev/zero of=windows1.img bs=1M seek=120000 count=0

This will create a disk with 120GB storage. More than enough for our tests I think.

Create a script for the virtual machine

The next step is to create a script which will allow us to run our virtual machine. I simply used the script I found here and altered it a bit to match my system. You will need to do the same. You will need to replace the addresses and identifiers in the script to make it work. And you will need to alter the paths for the virtual disk we created in the step before and the path for your image file.

Here is my version of the script:


#!/bin/bash

configfile=/etc/vfio-pci1.cfg

vfiobind() {
dev="$1"
vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
device=$(cat /sys/bus/pci/devices/$dev/device)
if [ -e /sys/bus/pci/devices/$dev/driver ]; then
echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
fi
echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id

}

modprobe vfio-pci

cat $configfile | while read line;do
echo $line | grep ^# >/dev/null 2>&1 && continue
vfiobind $line
done

sudo qemu-system-x86_64 -enable-kvm -M q35 -m 4096 -cpu host \
-smp 4,sockets=1,cores=4,threads=1 \
-bios /usr/share/qemu/bios.bin -vga none \
-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
-device vfio-pci,host=02:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
-device vfio-pci,host=02:00.1,bus=root.1,addr=00.1 \
-drive file=/home/test/windows1.img,id=disk,format=raw -device ide-hd,bus=ide.0,drive=disk \
-drive file=/home/test/Downloads/Windows.iso,id=isocd -device ide-cd,bus=ide.1,drive=isocd \
-usb -usbdevice host:093a:2510 -usbdevice host:046d:c316 \
-boot menu=on

exit 0

After you have altered the script to match your system you need to run the below command to make the script executable:

sudo chmod 755 /usr/vm1

As you may have noticed I added some USB devices to my virtual machine. A mouse (093a:2510) and a keyboard (046d:c316). So that I will be able to work with the machine properly.

I would advise you to do the same since I tought that this is the easiest way to add USB devices. To find out the identifiers of your USB devices simply run:

lsusb

Here is an example of how the output will look like:

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 003: ID 046d:c316 Logitech, Inc. HID-Compliant Keyboard
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 009 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 008 Device 002: ID 1058:1021 Western Digital Technologies, Inc. Elements 2TB
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

You can use the mouse and keyboard of your host system like I did. It will not cause errors to pop up but it will make the devices unavailable for the host system. (That´s also one of the reasons why I installed an OpenSSH Server)

After I completed these steps I decided to reboot my system one last time just to be sure that everything works:

sudo reboot

After my computer was up and running again I logged on to my GUI and run the following command in a terminal window on the GUI:

sudo /usr/vm1

Important: I pointed out that I ran the above command on the GUI because I ran into problems when trying to run the command from an SSH session. I got the following error message “Could not initialize SDL (No available video device) – exiting“. I was not able to solve this so far so I decided to start the script on the GUI.

Right after I ran the script a black QEMU window popped up and my mouse and keyboard were passed through to the virtual machine.

The next thing I did was to connect a VGA cable to the VGA port of the graphics card I passed through to the virtual machine. And I was greeted by the Windows 8 Logo right after plugging in the cable.

Virtual Machine Installation

The installation of Windows 8.1 on my virtual machine was exactly the same as installing it on a normal physical computer. I just went through the steps and created a Local Account for my tests.

Driver Installation

Ok. After the virtual machine was up and running I decided to install my graphics card drivers so that I can play games. But first I verified that my graphics card got passed through correctly. So I installed GPU-Z to make sure that the model of my graphics card was recognized correctly. It was. The next step for me was to download the drivers from here. Next I needed some extra steps to get the drivers running.

Here are the steps how I got my drivers running:

  • First I opened Settings -> Control Panel -> System and Security -> Administrative Tools -> Computer Management -> Device Manager -> Display Adapters and right clicked on the Microsoft Basic Display Adapter and clicked on Update Driver Software… -> Search automatically for updated driver software -> This resulted in Windows downloading some drivers and my graphics card was recognized as Radeon HD6450 after the download and installation completed. After that I rebooted the virtual machine.
  • Next I started the exe I downloaded and canceled it after it finished extracting files. Then I returned to Display Adapters in the Device Manager and right clicked on Radeon HD6450 and clicked on Update Driver Software… -> Browse my computer for driver software and I chose the Path where the Driver files were extracted. After the installation my graphics card was recognized as Radeon HD7450. That was not so strange since the description of the graphics card also got messed when I used it on a normal physical computer. Then I rebooted the virtual machine.
  • And finally I started the exe one last time and went through the whole installation like I would do it on a normal physical computer and rebooted one last time.

After all the above steps I had AMD Catalyst installed correctly and I was able to unplug the VGA cable and replace it with an HDMI cable. Now everything worked as I wanted. Now it was testing time.

Important: The installation process of your drivers may differ from mine so don´t be frustrated if the above steps don´t work for you.

Game Installation

Now I needed a game to test this whole setup. So I installed Steam and started to download Left 4 Dead 2 (I thought this game should do a good job for testing). After the download and installation both finished I started the game right away. There was no trouble at all with the game. It started and behaved normally. Sound and Video both worked as expected and as far as I can judge there was no noticeable delay. The only tiny delay I felt was from my mouse and keyboard. The reacted a split second slower than normally I would say but maybe this is because I used the hosts devices or maybe because I did not pass through an USB Controller for the virtual machine. I don´t know for sure why it behaved like this. All in all I was surprised that it all worked quite well.

Summary

Well, this was indeed an interesting project which consumed quite a lot of my time and was sometimes a bit troublesome but I enjoyed working on it and I´m quite happy that I got it running. But I will not simply drop this project as it is now. No. I want to work on it a bit more and I will try to make screenshots for each step as well as a video of the gaming experience (If possible I want to try different graphic cards too). And I would be happy if some of you could post some of their experiences with KVM and QEMU in the comment section if you have tried this too. And I would be happy if you have a look at this awesome post and give these guys some credit for their awesome work.

Well, that´s it for this post. Sorry that this post got quite long this time but I hope it was interesting for you and I hope that I see you again next time 🙂

Sources:

http://www.pugetsystems.com/labs/articles/Multiheaded-NVIDIA-Gaming-using-Ubuntu-14-04-KVM-585/

http://www.howtogeek.com/117635/how-to-install-kvm-and-create-virtual-machines-on-ubuntu/

http://ubuntuforums.org/showthread.php?t=2262280

http://apurv.me/vga-passthrough-using-kvm-in-ubuntu-14-04/

http://www.gitztalk.com/posts/2014/06/30/gaming-in-a-vm/

Tagged , , , ,

Raspberry Pi – Turn your Raspberry Pi into a Webcam Server

Hello everyone. Today I will show you how you can turn your Raspberry Pi into a webcam server by using your Raspberry Pi and the Raspi cam.

Install your Raspi Cam:

Make sure that you place the cable correctly into its socket and start your Raspberry Pi.

Raspberry_Pi_camera

Important:

I used wheezy as Operating System. So the following commands might be a bit different on other Operating Systems.

Update your Pi:

The first step is to update your Pi. Do this by executing the following commands:

sudo apt-get update
sudo apt-get upgrade

Enable your camera:

This step is very important. You need to enable your camera first otherwise you will receive “Operation not permitted” errors later. To enable your camera do the following:

sudo raspi-config

Search for Enable Camera and choose Enable. If you are asked to reboot choose Yes.

Raspberry_Pi_enable_camera

Install video driver for Raspi cam:

Now we need to install a video driver so we can use our Raspi cam with motion. But before we can do that we need to add a new source into sources.list to get the video driver.

Open up sources.list:

sudo nano /etc/apt/sources.list

And add the following line:

deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main

Now you must add the key so you can use your newly added source. Do this by running the following command:

wget http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc && sudo apt-key add ./lrkey.asc

Next run an Update to make sure you get the newest driver version.

sudo apt-get update

Now run the below command to install the video driver:

sudo apt-get install uv4l uv4l-raspicam

To load the driver at boot you need to install the following extras:

sudo apt-get install uv4l-raspicam-extras

Now reboot.

sudo reboot

Install motion:

Next you need to install motion. Do this by running:

sudo apt-get install motion

Next we need to create a custom motion.conf file in our home directory:

nano motion.conf

Copy the following code into your motion.conf file: (You can download the file from here)

# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 3.2.12

############################################################
# Daemon
############################################################

# Start in daemon (background) mode and release terminal (default: off)
daemon off

# File to store the process ID, also called pid file. (default: not defined)
process_id_file /var/run/motion/motion.pid 

############################################################
# Basic Setup Mode
############################################################

# Start in Setup-Mode, daemon disabled. (default: off)
setup_mode off

###########################################################
# Capture device options
############################################################

# Videodevice to be used for capturing  (default /dev/video0)
# for FreeBSD default is /dev/bktr0
videodevice /dev/video0

# v4l2_palette allows to choose preferable palette to be use by motion
# to capture from those supported by your videodevice. (default: 8)
# E.g. if your videodevice supports both V4L2_PIX_FMT_SBGGR8 and
# V4L2_PIX_FMT_MJPEG then motion will by default use V4L2_PIX_FMT_MJPEG.
# Setting v4l2_palette to 1 forces motion to use V4L2_PIX_FMT_SBGGR8
# instead.
#
# Values :
# V4L2_PIX_FMT_SN9C10X : 0  'S910'
# V4L2_PIX_FMT_SBGGR8  : 1  'BA81'
# V4L2_PIX_FMT_MJPEG   : 2  'MJPEG'
# V4L2_PIX_FMT_JPEG    : 3  'JPEG'
# V4L2_PIX_FMT_RGB24   : 4  'RGB3'
# V4L2_PIX_FMT_UYVY    : 5  'UYVY'
# V4L2_PIX_FMT_YUYV    : 6  'YUYV'
# V4L2_PIX_FMT_YUV422P : 7  '422P'
# V4L2_PIX_FMT_YUV420  : 8  'YU12'

# For the UV4L raspicam driver valid values are 2 and 8 (8 for higher fps)
v4l2_palette 8

# Tuner device to be used for capturing using tuner as source (default /dev/tuner0)
# This is ONLY used for FreeBSD. Leave it commented out for Linux
; tunerdevice /dev/tuner0

# The video input to be used (default: 8)
# Should normally be set to 0 or 1 for video/TV cards, and 8 for USB cameras
#input 8
input 8

# The video norm to use (only for video capture and TV tuner cards)
# Values: 0 (PAL), 1 (NTSC), 2 (SECAM), 3 (PAL NC no colour). Default: 0 (PAL)
norm 0

# The frequency to set the tuner to (kHz) (only for TV tuner cards) (default: 0)
frequency 0

# Rotate image this number of degrees. The rotation affects all saved images as
# well as mpeg movies. Valid values: 0 (default = no rotation), 90, 180 and 270.
rotate 0

# Image width (pixels). Valid range: Camera dependent, default: 352
width 640

# Image height (pixels). Valid range: Camera dependent, default: 288
height 480

# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 100

# Minimum time in seconds between capturing picture frames from the camera.
# Default: 0 = disabled - the capture rate is given by the camera framerate.
# This option is used when you want to capture images at a rate lower than 2 per second.
minimum_frame_time 0

# URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// or file:///)
# Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined
; netcam_url value

# Username and password for network camera (only if required). Default: not defined
# Syntax is user:password
; netcam_userpass value

# The setting for keep-alive of network socket, should improve performance on compatible net cameras.
# 1.0:         The historical implementation using HTTP/1.0, closing the socket after each http request.
# keep_alive:  Use HTTP/1.0 requests with keep alive header to reuse the same connection.
# 1.1:         Use HTTP/1.1 requests that support keep alive as default.
# Default: 1.0
; netcam_http 1.0

# URL to use for a netcam proxy server, if required, e.g. "http://myproxy".
# If a port number other than 80 is needed, use "http://myproxy:1234".
# Default: not defined
; netcam_proxy value 

# Set less strict jpeg checks for network cameras with a poor/buggy firmware.
# Default: off
netcam_tolerant_check off

# Let motion regulate the brightness of a video device (default: off).
# The auto_brightness feature uses the brightness option as its target value.
# If brightness is zero auto_brightness will adjust to average brightness value 128.
# Only recommended for cameras without auto brightness
auto_brightness off

# Set the initial brightness of a video device.
# If auto_brightness is enabled, this value defines the average brightness level
# which Motion will try and adjust to.
# Valid range 0-255, default 0 = disabled
brightness 0

# Set the contrast of a video device.
# Valid range 0-255, default 0 = disabled
contrast 0

# Set the saturation of a video device.
# Valid range 0-255, default 0 = disabled
saturation 0

# Set the hue of a video device (NTSC feature).
# Valid range 0-255, default 0 = disabled
hue 0

############################################################
# Round Robin (multiple inputs on same video device name)
############################################################

# Number of frames to capture in each roundrobin step (default: 1)
roundrobin_frames 1

# Number of frames to skip before each roundrobin step (default: 1)
roundrobin_skip 1

# Try to filter out noise generated by roundrobin (default: off)
switchfilter off

############################################################
# Motion Detection Settings:
############################################################

# Threshold for number of changed pixels in an image that
# triggers motion detection (default: 1500)
threshold 1500

# Automatically tune the threshold down if possible (default: off)
threshold_tune off

# Noise threshold for the motion detection (default: 32)
noise_level 32

# Automatically tune the noise threshold (default: on)
noise_tune on

# Despeckle motion image using (e)rode or (d)ilate or (l)abel (Default: not defined)
# Recommended value is EedDl. Any combination (and number of) of E, e, d, and D is valid.
# (l)abeling must only be used once and the 'l' must be the last letter.
# Comment out to disable
despeckle EedDl

# Detect motion in predefined areas (1 - 9). Areas are numbered like that:  1 2 3
# A script (on_area_detected) is started immediately when motion is         4 5 6
# detected in one of the given areas, but only once during an event.        7 8 9
# One or more areas can be specified with this option. (Default: not defined)
; area_detect value

# PGM file to use as a sensitivity mask.
# Full path name to. (Default: not defined)
; mask_file value

# Dynamically create a mask file during operation (default: 0)
# Adjust speed of mask changes from 0 (off) to 10 (fast)
smart_mask_speed 0

# Ignore sudden massive light intensity changes given as a percentage of the picture
# area that changed intensity. Valid range: 0 - 100 , default: 0 = disabled
lightswitch 0

# Picture frames must contain motion at least the specified number of frames
# in a row before they are detected as true motion. At the default of 1, all
# motion is detected. Valid range: 1 to thousands, recommended 1-5
minimum_motion_frames 1

# Specifies the number of pre-captured (buffered) pictures from before motion
# was detected that will be output at motion detection.
# Recommended range: 0 to 5 (default: 0)
# Do not use large values! Large values will cause Motion to skip video frames and
# cause unsmooth mpegs. To smooth mpegs use larger values of post_capture instead.
pre_capture 0

# Number of frames to capture after motion is no longer detected (default: 0)
post_capture 0

# Gap is the seconds of no motion detection that triggers the end of an event
# An event is defined as a series of motion images taken within a short timeframe.
# Recommended value is 60 seconds (Default). The value 0 is allowed and disables
# events causing all Motion to be written to one single mpeg file and no pre_capture.
gap 60

# Maximum length in seconds of an mpeg movie
# When value is exceeded a new mpeg file is created. (Default: 0 = infinite)
max_mpeg_time 0

# Always save images even if there was no motion (default: off)
output_all off

############################################################
# Image File Output
############################################################

# Output 'normal' pictures when motion is detected (default: on)
# Valid values: on, off, first, best, center
# When set to 'first', only the first picture of an event is saved.
# Picture with most motion of an event is saved when set to 'best'.
# Picture with motion nearest center of picture is saved when set to 'center'.
# Can be used as preview shot for the corresponding movie.
output_normal off

# Output pictures with only the pixels moving object (ghost images) (default: off)
output_motion off

# The quality (in percent) to be used by the jpeg compression (default: 75)
quality 75

# Output ppm images instead of jpeg (default: off)
ppm off

############################################################
# FFMPEG related options
# Film (mpeg) file output, and deinterlacing of the video input
# The options movie_filename and timelapse_filename are also used
# by the ffmpeg feature
############################################################

# Use ffmpeg to encode mpeg movies in realtime (default: off)
ffmpeg_cap_new off

# Use ffmpeg to make movies with only the pixels moving
# object (ghost images) (default: off)
ffmpeg_cap_motion off

# Use ffmpeg to encode a timelapse movie
# Default value 0 = off - else save frame every Nth second
ffmpeg_timelapse 0

# The file rollover mode of the timelapse video
# Valid values: hourly, daily (default), weekly-sunday, weekly-monday, monthly, manual
ffmpeg_timelapse_mode daily

# Bitrate to be used by the ffmpeg encoder (default: 400000)
# This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled)
ffmpeg_bps 500000

# Enables and defines variable bitrate for the ffmpeg encoder.
# ffmpeg_bps is ignored if variable bitrate is enabled.
# Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps,
# or the range 2 - 31 where 2 means best quality and 31 is worst.
ffmpeg_variable_bitrate 0

# Codec to used by ffmpeg for the video compression.
# Timelapse mpegs are always made in mpeg1 format independent from this option.
# Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.
# mpeg1 - gives you files with extension .mpg
# mpeg4 or msmpeg4 - gives you files with extension .avi
# msmpeg4 is recommended for use with Windows Media Player because
# it requires no installation of codec on the Windows client.
# swf - gives you a flash film with extension .swf
# flv - gives you a flash video with extension .flv
# ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
# mov - QuickTime ( testing )
ffmpeg_video_codec swf

# Use ffmpeg to deinterlace video. Necessary if you use an analog camera
# and see horizontal combing on moving objects in video or pictures.
# (default: off)
ffmpeg_deinterlace off

############################################################
# Snapshots (Traditional Periodic Webcam File Output)
############################################################

# Make automated snapshot every N seconds (default: 0 = disabled)
snapshot_interval 0

############################################################
# Text Display
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second, %T = HH:MM:SS,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level, \n = new line,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event - do not use with text_event!
# You can put quotation marks around the text to allow
# leading spaces
############################################################

# Locate and draw a box around the moving object.
# Valid values: on, off and preview (default: off)
# Set to 'preview' will only draw a box in preview_shot pictures.
locate off

# Draws the timestamp using same options as C function strftime(3)
# Default: %Y-%m-%d\n%T = date in ISO format and time in 24 hour clock
# Text is placed in lower right corner
text_right %Y-%m-%d\n%T-%q

# Draw a user defined text on the images using same options as C function strftime(3)
# Default: Not defined = no text
# Text is placed in lower left corner
; text_left CAMERA %t

# Draw the number of changed pixed on the images (default: off)
# Will normally be set to off except when you setup and adjust the motion settings
# Text is placed in upper right corner
text_changes off

# This option defines the value of the special event conversion specifier %C
# You can use any conversion specifier in this option except %C. Date and time
# values are from the timestamp of the first image in the current event.
# Default: %Y%m%d%H%M%S
# The idea is that %C can be used filenames and text_left/right for creating
# a unique identifier for each event.
text_event %Y%m%d%H%M%S

# Draw characters at twice normal size on images. (default: off)
text_double off

############################################################
# Target Directories and filenames For Images And Films
# For the options snapshot_, jpeg_, mpeg_ and timelapse_filename
# you can use conversion specifiers
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event
# Quotation marks round string are allowed.
############################################################

# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /home/pi

# File path for snapshots (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-snapshot
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-snapshot
# File extension .jpg or .ppm is automatically added so do not include this.
# Note: A symbolic link called lastsnap.jpg created in the target_dir will always
# point to the latest snapshot, unless snapshot_filename is exactly 'lastsnap'
snapshot_filename %v-%Y%m%d%H%M%S-snapshot

# File path for motion triggered images (jpeg or ppm) relative to target_dir
# Default: %v-%Y%m%d%H%M%S-%q
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H/%M/%S-%q
# File extension .jpg or .ppm is automatically added so do not include this
# Set to 'preview' together with best-preview feature enables special naming
# convention for preview shots. See motion guide for details
jpeg_filename %v-%Y%m%d%H%M%S-%q

# File path for motion triggered ffmpeg films (mpeg) relative to target_dir
# Default: %v-%Y%m%d%H%M%S
# Default value is equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d/%H%M%S
# File extension .mpg or .avi is automatically added so do not include this
# This option was previously called ffmpeg_filename
movie_filename %v-%Y%m%d%H%M%S

# File path for timelapse mpegs relative to target_dir
# Default: %Y%m%d-timelapse
# Default value is near equivalent to legacy oldlayout option
# For Motion 3.0 compatible mode choose: %Y/%m/%d-timelapse
# File extension .mpg is automatically added so do not include this
timelapse_filename %Y%m%d-timelapse

############################################################
# Live Webcam Server
############################################################

# The mini-http server listens to this port for requests (default: 0 = disabled)
webcam_port 8081

# Quality of the jpeg (in percent) images produced (default: 50)
webcam_quality 100

# Output frames at 1 fps when no motion is detected and increase to the
# rate given by webcam_maxrate when motion is detected (default: off)
webcam_motion on

# Maximum framerate for webcam streams (default: 1)
webcam_maxrate 30

# Restrict webcam connections to localhost only (default: on)
webcam_localhost off

# Limits the number of images per connection (default: 0 = unlimited)
# Number can be defined by multiplying actual webcam rate by desired number of seconds
# Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
webcam_limit 0

############################################################
# HTTP Based Control
############################################################

# TCP/IP port for the http server to listen on (default: 0 = disabled)
control_port 8080

# Restrict control connections to localhost only (default: on)
control_localhost off

# Output for http server, select off to choose raw text plain (default: on)
control_html_output on

# Authentication for the http based control. Syntax username:password
# Default: not defined (Disabled)
; control_authentication username:password

############################################################
# Tracking (Pan/Tilt)
############################################################

# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo)
# The generic type enables the definition of motion center and motion size to
# be used with the conversion specifiers for options like on_motion_detected
track_type 0

# Enable auto tracking (default: off)
track_auto off

# Serial port of motor (default: none)
; track_port value

# Motor number for x-axis (default: 0)
track_motorx 0

# Motor number for y-axis (default: 0)
track_motory 0

# Maximum value on x-axis (default: 0)
track_maxx 0

# Maximum value on y-axis (default: 0)
track_maxy 0

# ID of an iomojo camera if used (default: 0)
track_iomojo_id 0

# Angle in degrees the camera moves per step on the X-axis
# with auto-track (default: 10)
# Currently only used with pwc type cameras
track_step_angle_x 10

# Angle in degrees the camera moves per step on the Y-axis
# with auto-track (default: 10)
# Currently only used with pwc type cameras
track_step_angle_y 10

# Delay to wait for after tracking movement as number
# of picture frames (default: 10)
track_move_wait 10

# Speed to set the motor to (stepper motor option) (default: 255)
track_speed 255

# Number of steps to make (stepper motor option) (default: 40)
track_stepsize 40

############################################################
# External Commands, Warnings and Logging:
# You can use conversion specifiers for the on_xxxx commands
# %Y = year, %m = month, %d = date,
# %H = hour, %M = minute, %S = second,
# %v = event, %q = frame number, %t = thread (camera) number,
# %D = changed pixels, %N = noise level,
# %i and %J = width and height of motion area,
# %K and %L = X and Y coordinates of motion center
# %C = value defined by text_event
# %f = filename with full path
# %n = number indicating filetype
# Both %f and %n are only defined for on_picture_save,
# on_movie_start and on_movie_end
# Quotation marks round string are allowed.
############################################################

# Do not sound beeps when detecting motion (default: on)
# Note: Motion never beeps when running in daemon mode.
quiet on

# Command to be executed when an event starts. (default: none)
# An event starts at first motion detected after a period of no motion defined by gap
; on_event_start value

# Command to be executed when an event ends after a period of no motion
# (default: none). The period of no motion is defined by option gap.
; on_event_end value

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
; on_picture_save value

# Command to be executed when a motion frame is detected (default: none)
; on_motion_detected value

# Command to be executed when motion in a predefined area is detected
# Check option 'area_detect'.   (default: none)
; on_area_detected value

# Command to be executed when a movie file (.mpg|.avi) is created. (default: none)
# To give the filename as an argument to a command append it with %f
; on_movie_start value

# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)
# To give the filename as an argument to a command append it with %f
; on_movie_end value

# Command to be executed when a camera can't be opened or if it is lost
# NOTE: There is situations when motion doesn't detect a lost camera!
# It depends on the driver, some drivers don't detect a lost camera at all
# Some hang the motion thread. Some even hang the PC! (default: none)
; on_camera_lost value

############################################################
# Common Options For MySQL and PostgreSQL database features.
# Options require the MySQL/PostgreSQL options to be active also.
############################################################

# Log to the database when creating motion triggered image file  (default: on)
sql_log_image on

# Log to the database when creating a snapshot image file (default: on)
sql_log_snapshot on

# Log to the database when creating motion triggered mpeg file (default: off)
sql_log_mpeg off

# Log to the database when creating timelapse mpeg file (default: off)
sql_log_timelapse off

# SQL query string that is sent to the database
# Use same conversion specifiers has for text features
# Additional special conversion specifiers are
# %n = the number representing the file_type
# %f = filename with full path
# Default value:
# insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')

############################################################
# Database Options For MySQL
############################################################

# Mysql database to log to (default: not defined)
; mysql_db value

# The host on which the database is located (default: localhost)
; mysql_host value

# User account name for MySQL database (default: not defined)
; mysql_user value

# User password for MySQL database (default: not defined)
; mysql_password value

############################################################
# Database Options For PostgreSQL
############################################################

# PostgreSQL database to log to (default: not defined)
; pgsql_db value

# The host on which the database is located (default: localhost)
; pgsql_host value

# User account name for PostgreSQL database (default: not defined)
; pgsql_user value

# User password for PostgreSQL database (default: not defined)
; pgsql_password value

# Port on which the PostgreSQL database is located (default: 5432)
; pgsql_port 5432

############################################################
# Video Loopback Device (vloopback project)
############################################################

# Output images to a video4linux loopback device
# The value '-' means next available (default: not defined)
; video_pipe value

# Output motion images to a video4linux loopback device
# The value '-' means next available (default: not defined)
; motion_video_pipe value

##############################################################
# Thread config files - One for each camera.
# Except if only one camera - You only need this config file.
# If you have more than one camera you MUST define one thread
# config file for each camera in addition to this config file.
##############################################################

# Remember: If you have more than one camera you must have one
# thread file for each camera. E.g. 2 cameras requires 3 files:
# This motion.conf file AND thread1.conf and thread2.conf.
# Only put the options that are unique to each camera in the
# thread config files.
; thread /usr/local/etc/thread1.conf
; thread /usr/local/etc/thread2.conf
; thread /usr/local/etc/thread3.conf
; thread /usr/local/etc/thread4.conf

Next adjust the permissions of your motion.conf file:

sudo chmod 777 motion.conf

Run motion at Boot:

To automatically start motion when you reboot your Pi you need to create a custom script. I called mine “start_motion.sh”. Do the following:

Create a new file called “start_motion.sh” in your home directory:

nano start_motion.sh

Add the following code to your “start_motion.sh” file:

#!/bin/bash
unset LD_PRELOAD
export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so
exec motion -c ./motion.conf

And adjust the permissions of your script:

sudo chmod 777 start_motion.sh

Next you need to use crontab to run your script at boot. Run the following command:

crontab -e

And add the following line at the end of the file:

@reboot /home/pi/start_motion.sh

Next you need to enable crontab by running the following command:

sudo update-rc.d cron defaults

Now reboot your Raspberry Pi once more:

sudo reboot

When your Pi has rebooted successfully you will notice that the LED of your Raspi cam has turned on. Your webcam server is now ready to use.

To access your Pi´s video stream open up your Browser (I used Firefox. It did not work on Chrome and Internet Explorer for me.) and enter the following:

http://<IP address of your Raspberry Pi>:8081

You will now see what your Raspi cam sees. You can tune the video stream by altering the motion.conf file we created earlier.

That´s it. You now have a simple webcam server you can use to monitor your flat, etc.

I hope my post was interesting for you and I hope to see you next time.

And as always you can download the scripts I used in this post from here.

Sources:

http://www.karesyk.de/raspicam-webcam-server/ (german)

http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14

http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=16

https://bbs.archlinux.org/viewtopic.php?id=81295

http://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

http://stackoverflow.com/questions/17131249/how-to-solve-bad-interpreter-no-such-file-or-directory

http://programmaticponderings.wordpress.com/2013/01/01/remote-motion-activated-web-based-video-surveillance-with-raspberry-pi/

Tagged ,

Linux on Windows – With Putty & XMing

Hello everyone. Today I will show you how you can run Linux applications with a GUI on Windows by using Putty and XMing.

What operating systems you need:

  • A machine running a Linux operating system (for example: Ubuntu)
  • A machine running a Windows operating system (I used Windows 7)

What software you need:

Both will be run from your Windows machine. The only prerequisite you need to fulfill on your Linux machine is a running SSH server. When you use a debian system you can achieve this by simply running the following command:

sudo apt-get install openssh-server

Now log on to your Windows machine and install XMing. Simply click through the wizard and keep the default settings.

XMing_Finished_Installation

After the installation finished you need to allow XMing to bypass your firewall. To do so simply click on “Allow Access” when you run XMing.

XMing_Firewall

Now you need to configure Putty. Run Putty and enter the IP address or hostname of your Linux Machine and the number of the SSH Port you are using on this machine (The Default Port is 22). Enter a name for this Session in the textbox below “Saved Sessions” and click on Save.

Putty_Session

The next step is to configure the X11 forwarding. Go to Connection -> SSH -> X11. Check the checkbox next to “Enable X11 forwarding” and check the radio button next to MIT-Magic-Cookie-1 below Remote X11 authentication protocol. Now go back to Session and click on Save.

Now start the session by clicking on Open.

Putty_SSH

To test if everything is working you can run the following command:

xclock

Now this window will open up.

XMing_XClock

Important: If you try this and nothing happens, make sure that XMing is running and it can bypass your firewall.

That´s it. Now you can run Linux applications with a GUI via SSH on Windows.

Sources:

http://anotherdatabaseblog.blogspot.co.at/2012/10/putty-x11-proxy-wrong-authorisation.html

http://www.liberiangeek.net/2012/03/enable-ssh-secure-shell-in-ubuntu-12-04-precise-pangolin/

Tagged

Clone Virtual Machine – Linux (debian) – eth0 missing

Today I found a solution for a problem which was bugging me for a while now.  (I encountered this error when I tried to clone my WanEm virtual machine.)

If you clone a virtual machine (created via Hyper-V, Virtualbox, VMWare, …) which is using Linux as an operating system you will notice that the cloned machine is missing the eth0 network interface. That´s strange because you added a network adapter during it´s creation.

If you run the following command in the terminal:

ifconfig eth0 up

You will receive the following error message:

eth0: ERROR while getting interface flags: No such device

So what could have gone wrong? The answer is quite simple: You added a new network adapter with a different MAC address and Linux was not able to detect this change. What can you do to solve this problem? The solution is also quite simple.

Here it is:

Run the following commands:


sudo rm /etc/udev/rules.d/z25-persistent-net.rules
sudo reboot

After the operating system successfully rebooted your problem will be solved.

If you now run

ifconfig -a

you will see that there is an eth0 interface now.

Sources:

http://fl3x.us/blog/2013/08/30/eth0-error-while-getting-interface-flags-no-such-device/

http://chris.dziemborowicz.com/blog/2010/07/25/fix-missing-eth0-when-cloning-ubuntu-vmware-virtual-machines/

http://lostechies.com/derickbailey/2009/06/20/cloning-or-converting-linux-vm-from-vmware-workstation-to-esx-server-eth0-gone-eth1-available/

Tagged , ,