Automation of everything …

Automation of everything …

July, 2017

now browsing by month


VirtualBox install/update Guest Additions

1. Make guest additions iso available on host server
VBoxManage storageattach "" --storagectl IDE --port 0 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso

2. Mount cdrom and install/update guest additions in guest
sudo mount /dev/cdrom /media/cdrom
sudo bash /media/cdrom/
sudo umount /media/cdom

3. Reboot guest to ensure everything is loaded.
sudo reboot now

4. Remove CD iso
VBoxManage storageattach "" --storagectl IDE --port 0 --device 0 --medium "none"

VirtualBox headless VM autostart

1. Modify the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings.

echo 'VBOXAUTOSTART_DB=/etc/vbox' | sudo tee -a /etc/default/virtualbox
echo 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg' | sudo tee -a /etc/default/virtualbox

2. Create the autostart.cfg file
NB: You may need to change the username or add others, depending on your installation.

echo '# Default policy is to deny starting a VM, the other option is "allow".' | sudo tee /etc/vbox/autostart.cfg
echo 'default_policy = deny' | sudo tee -a /etc/vbox/autostart.cfg
echo '# Create an entry for each user allowed to run autostart' | sudo tee -a /etc/vbox/autostart.cfg
echo 'vbox = {' | sudo tee -a /etc/vbox/autostart.cfg
echo 'allow = true' | sudo tee -a /etc/vbox/autostart.cfg
echo '}' | sudo tee -a /etc/vbox/autostart.cfg

If you are the only user you can just add the line default_policy = allow to the autostart.cfg file.

3. Clean up permissions
Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

Add each of the users to the vboxusers group.
sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the username)
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions.

4. Create start/stop files
cd /etc/vbox
sudo touch vbox.start
sudo touch vbox.stop

And change owner with:
sudo chown vbox:vboxusers vbox.start
sudo chown vbox:vboxusers vbox.stop

4. Enable autostart/autostop
Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

VBoxManage setproperty autostartdbpath /etc/vbox

and enable autostart/autostop for an individual VM with
NB: The VM needs to be shut down for this command
VBoxManage modifyvm gitlab --autostart-enabled on --autostop-type acpishutdown

NB: autostopo types: disabled, savestate, poweroff, acpishutdown
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
sudo service vboxautostart-service restart

5. Reboot and test
Reboot your system and your VM(s) should start

VirtualBox admin using phpvirtualbox

1 Add a vbox user
sudo adduser vbox
Now we must add the user to the vboxusers group:
sudo adduser vbox vboxusers

2 Start VirtualBox Web Services
Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=vbox in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user vbox):

echo '# virtualbox defaults file' | sudo tee /etc/default/virtualbox
echo 'VBOXWEB_USER=vbox' | sudo tee -a /etc/default/virtualbox

Next create the system startup links for vboxwebsrv and start it:
sudo systemctl enable vboxweb-service
sudo systemctl start vboxweb-service

3 Install Apache2
We need a web server with PHP support to serve phpVirtualBox. Install Apache and PHP as follows:
sudo apt-get -y install apache2 libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php7.0-common php7.0-mysql php7.0-soap php-pear wget

Restart Apache:
sudo systemctl restart apache2.service

4 Download and install phpvirtualbox
I want to serve phpVirtualBox from Apache’s default virtual host with the document root /var/www/html (I will install it in /var/www/html/phpvirtualbox):
cd /var/www/html

sudo wget

Ensure zip/unzip are installed:
sudo apt install -y zip unzip

Unzip phpVirtualBox and rename the phpvirtualbox-5.0-5 to phpvirtualbox for ease of use:
sudo unzip

Create a link to our served directory so we preserve original packaging for easier upgrades
sudo ln -s phpvirtualbox-5.0-5 phpvirtualbox

Next go to the /var/www/phpvirtualbox/ directory…
cd /var/www/html/phpvirtualbox/

… and create the file config.php by copying it from config.php-example:
sudo cp config.php-example config.php

Open config.php and fill in the password you created earlier for the vbox system user:
sudo vi config.php

/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'pass';

Clean up Apache2 file privileges:
sudo chown www-data:www-data -R .

4. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean -y

sudo reboot now

5. Check the system
That’s it already – you can now open a browser and access phpVirtualBox as follows:
or By IP:

Default logon is admin:admin

Raspberry Pi Nukkit

sudo mkdir /home/nukkit

sudo adduser nukkit

sudo chown -R nukkit:nukkit /home/nukkit/

su – nukkit


java -jar nukkit-1.0-SNAPSHOT.jar

And follow through the initial setup.

test it ..

sudo update-rc.d nukkit defaults


Raspberry PI Mini DLNA Server

how to make a raspberry pi media server using MiniDLNA. This will allow you to stream your photos, videos and music around your network.

Step 1: What you will need

  • Raspberry pi (I’m using a model A)
  • Another computer if you want to SSH into your pi
  • Hard drive with your media
  • SD card for the raspberry pi operating system
  • Raspberry pi wifi dongle (you can also use Ethernet)\
  • A power supply for the raspberry pi (a minimum of 1 AMP and 5 Volts for the Raspberry Pi model B)
  • A powered USB hub

Step 2: Updating and Installing

To begin we can SSH into our raspberry pi by using a program like putty. After we have done this I recommend updating and upgrading your raspberry pi. You can do this by using the following commands.

sudo apt-get update

sudo apt-get upgrade

Once this is finished we can install the media server software. Use the next command to do this.

sudo apt-get install minidlna

After you enter this command you will probably be asking if you want to continue. Just press y and then enter. Once that has finished installing it is time for the next step.

Step 3: Connecting the hard drive

Before we can start our media server we need some media of course. So what we are going to do is make it so that our media hard drive is mounted on start-up.

To do this the first thing we need to do is plug in our media drive. Make sure you plug it into the powered USB hub and not directly into the raspberry pi because sometimes that can cause problems. Once you have done this we need to go back to putty or whatever SSH client you are using and type in:

sudo fdisk -l

What this does is it shows use important information about the drives that are connected to our raspberry pi. In the picture I have circled the name of my drive in white. In my case it was /dev/sda1. I know this because where I have circled in green says that the drive /dev/sda has 1000 GB which is the size of my drive. In red I have circled the format of the drive which we will need in the next step. You are going to need to know the name of your drive and the format of your drive in the following steps so it is probably a good idea to write them down somewhere.

Step 4: Mounting the drive on startup

We need to have our media drive to be mounted on startup so that we can access its contents. To do this we are going to need to make a folder to mount it to. You can do that by using this command:

sudo mkdir /media/HDD

What this command does is makes a folder called HDD in the media directory. So once we have made this folder we need to give it read write permissions. We can do this by using this command:

sudo chmod 777 /media/HDD

This command command tells the folder HDD that it has all permission. This means that it has read and write permissions which is what we wanted.

Now we need to edit the fstab file. This is the file that the raspberry pi operating system refers to when it is looking to see which dives to mount at startup so we need to put our media drive in that file. We can do that by using the command:

sudo nano /etc/fstab

Once in this file you will notice that it is not the same as Microsoft Word which you might be familiar to. You need to use the arrow keys to navigate around. So go to the bottom of this file and you are going to add this line:

/dev/sda1    /media/HDD   vfat    defaults     0        2

Ok so the line that you just added might be a bit confusing so I will try to explain it. The first part where is says /dev/sda1 is the is the name of the hard drive that you want to add. Remember from the previous step. The next part is the place where you are going to mount it to. Then we have the format of the hard drive. In this case it is fat32. And finally the 0 and 2 at the end are permissions.

Now it you reboot the raspberry pi:

sudo reboot

and move into the directory /media/HDD

cd /media/HDD

And run this command:


You should be able to see all the files on your hard drive.

Step 5: Configuring MiniDLNA

To start configuring MiniDLNA we need to edit the config file. This can be done by using this command:

sudo nano /etc/minidlna.conf

Once you have that file open we are going to need to change that part that looks like this:

# * “A” for audio (eg. media_dir=A,/var/lib/minidlna/music)
# * “P” for pictures (eg. media_dir=P,/var/lib/minidlna/pictures)
# * “V” for video (eg. media_dir=V,/var/lib/minidlna/videos)

to this:


and this:

# Name that the DLNA server presents to clients.

to this:

# Name that the DLNA server presents to clients.
friendly_name=RASPI MINIDLNA

and this:



to this:



In the line above where I have put RASPI MINIDLNA can be whatever you want.

Then press control x to exit and press y if it asks if you want to “save modified buffers” then press enter to confirm.

Now that we have configured MiniDLNA we have to refresh it. To do this you can run the following commands:

sudo service minidlna restart
sudo service minidlna force-reload

Now if you hop back onto a windows computer or any Upnp compatible device you should be able to see your server. On window if you click on start then computer then on the left hand side click on network you should be able to see your raspberry pi Minidlna server called RASPI MINIDLNA under the media devices section.

Step 6: Your done!

Congratulations you have successfully created a raspberry pi MiniDLNA server.


Raspberry PI RDP

How to Setup Remote Desktop from a Windows Machine to your Raspberry Pi – Step by Step Guide

As I mentioned in the previous post I recently found the need to be able to remote desktop to my Raspberry Pi.  This is a step by step guide on how to set it up.

What does this guide help me do?

It will let you control your Raspberry Pi from another machine.  Meaning that the Raspberry Pi will not need to be connected to a monitor, keyboard or mouse.

Before we get started a few clarifications:

  • This guide is to set up remote desktop from another computer on your home network to your Raspberry Pi.
  • It does not explain how to connect to your Pi from outside your home network.
  • The instructions are for connecting from a windows machine.

What do I need before I get started?

  1. A Raspberry Pi running the latest Raspbian “wheezy” image (at time of writing  It should work with other Linux versions too, but that is the one I have tested with.
  2. The Raspberry Pi should be connected to your home network and have a internet connection.
  3. A second machine running windows that you want to use connect from which is connected to the same home network.

The Steps

Raspberry Pi Setup

So first we need to install some software on the Raspberry Pi, but don’t worry it is very easy!
  1. Start up your Pi to the terminal prompt.
  2. Type the following command “sudo apt-get install xrdp”
  3. If promoted enter your password (the default is “raspberry”)
  4. Type “Y” and press enter.
  5. This is now installing xrdp onto your Pi which is the software we are going to use for the remote desktop connection.  Wait for it to complete.
  6. Restart your Pi.  We are going to check that xrdp is going to start up automatically.
  7. When your Pi has booted to the command prompt look for [ ok ] Starting Remote Desktop Protocol server : xrdp sesman.  This shows you that xrdp is installed and automatically starting up on start up of your Pi
  8. The last step is to make a note of the IP address of your Pi which should also be displayed on the start up screen.  In my case below it is  This is the address of your Pi on your network and what we will use to connect to your Pi from the second machine.

Second Machine Setup

1. Launch Remote Desktop Connection which can be found at Start->All Programs->Accessories->Remote Desktop Connection
2. Type in the IP Address for your Pi which you noted above.
3. Click Connect (you may get a security warning at this stage just click OK if you do.  After all it is your Pi on your network so nothing to worry about security wise).
4. Leave the Module on the default of sesman-Xvnc and enter your username and password for your Pi.  (The default is pi and raspberry if you haven’t changed them).
5. Click OK and after a few moments you should be greeted my your Raspberry Pi’s desktop!
6.  When you are finished simply log-out from the Pi’s desktop.


Raspberry PI NAT (for WiFi Router)

Configure Network Address Translation

Setting up NAT will allow multiple clients to connect to the WiFi and have all the data ‘tunneled’ through the single Ethernet IP. (But you should do it even if only one client is going to connect)


sudo vi /etc/sysctl.conf

uncomment this line (or scroll to the bottom and add if it is not there!)


Save the file. This will start IP forwarding on boot up.

To reload the file without rebooting .. 
sudo sysctl -p

Run the following commands to create the network translation between the ethernet port eth0 and the wifi port wlan0

sudo iptables t nat A POSTROUTING o eth0 j MASQUERADE

sudo iptables A FORWARD i eth0 o wlan0 m state state RELATED,ESTABLISHED j ACCEPT

sudo iptables A FORWARD i wlan0 o eth0 j ACCEPT

You can check to see whats in the tables with

sudo iptables -t nat -S
sudo iptables -S

To make this happen on reboot (so you don’t have to type it every time) run

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”


sudo vi /etc/network/interfaces

and add

up iptables-restore < /etc/iptables.ipv4.nat

to the very end

Raspberry PI WiFi Router (hostapd)

Check WLAN drivers

Check that your Pi sees your USB WiFi dongle


If it is a Realtek chipset RTL8192EU, you will see something like:

Bus 001 Device 004: ID 0bda:818b Realtek Semiconductor Corp.

the 818b indicates the RTL8192EU chipset.

Unfortunately this chipset is currently not ‘officially’ supported by Rasbian, but MrEngman over at maintains a good library of drivers (


First be sure of the kernel version you are running:

uname -a

resulted, for me in,

4.4.13-v7+ #894

So i grabbed the driver and installed it with:

tar xzf 8192eu-4.4.13-v7-894.tar.gz sudo 

sudo apt-get install hostapd


Set up wlan0 for static IP

If you happen to have wlan0 active because you set it up, run

sudo ifdown wlan0

Next we will set up the wlan0 connection to be static and incoming. run

sudo vi /etc/network/interfaces to edit the file

Find the line auto wlan0 and add a # in front of the line, and in front of every line afterwards. If you don’t have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old wlan0 configuration settings, we’ll be changing them up

Depending on your existing setup/distribution there might be more or less text and it may vary a little bit

Add the lines

allow-hotplug wlan0
iface wlan0 inet static
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

Any other lines afterwards should have a # in front to disable them.

After that, re-enable the wlan0 interface and check if you have your IP set it up on interface

sudo ifup wlan0

sudo ifconfig wlan0
pi@nissanpi:~ $ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr e8:4e:06:13:f2:a9
 inet addr: Bcast: Mask:
 inet6 addr: fe80::c318:331c:4663:3977/64 Scope:Link
 RX packets:4311 errors:0 dropped:0 overruns:0 frame:0
 TX packets:8497 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000
 RX bytes:369129 (360.4 KiB) TX bytes:9830120 (9.3 MiB)

pi@nissanpi:~ $

Configure Access Point

Now we can configure the access point details. We will set up a password-protected network so only people with the password can connect.

Create a new file by running

sudo vi /etc/hostapd/hostapd.conf

Paste the following in, you can change the text after ssid= to another name, that will be the network broadcast name. The password can be changed with the text after wpa_passphrase=

  1. # This is the name of the WiFi interface we configured above
    # Use the nl80211 driver with the brcmfmac driver
    # This is the name of the network
    # Use the 2.4GHz band
    # Use channel 6
    # Enable 802.11n
    # Enable WMM
    # Enable 40MHz channels with 20ns guard interval
    # Accept all MAC addresses
    # Use WPA authentication
    # Require clients to know the network name
    # Use WPA2
    # Use a pre-shared key
    # The network passphrase
    # Use AES, instead of TKIP
– Adafruit wifi adapters driver=rtl871xdrv (may also require a specific hostapd app!)
– Many others (including RT5370) driver=nl80211
To view your USB adaptors:
sudo lsusb
pi@nissanpi:~ $ sudo lsusb
Bus 001 Device 006: ID 05ac:0256 Apple, Inc.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@nissanpi:~ $
 Now we will tell the Pi where to find this configuration file. Run

sudo vi /etc/default/hostapd

Find the line

and edit it so it says
Don’t forget to remove the # in front to activate it!Then save the file

Finally we can test the access point host! Run

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

To manually run hostapd with our configuration file. You should see it set up and use wlan0 then you can check with another wifi computer that you see your SSID show up. If so, you have successfully set up the access point.

You can try connecting and disconnecting from the Pi_AP with the password you set before (probably Raspberry if you copied our hostapd config), debug text will display on the Pi console but you won’t be able to connect through to the Ethernet connection yet.
Cancel the test by typing Control-C in the Pi console to get back to the Pi command line

Finishing up!

OK now that we know it works, time to set it up as a ‘daemon’ – a program that will start when the Pi boots.
Run the following command

sudo service hostapd start

you can always check the status of the host AP server with

sudo service hostapd status

To start the daemon services. Verify that they start successfully (no ‘failure’ or ‘errors’)
Then to make it so it runs every time on boot

sudo update-rc.d hostapd enable

Raspberry PI DHCP and DNS Server (dnsmasq)



  1. If dnsmasq is used as dhcp server, the local hostnames are automatically added “on the fly” to its dns cache. No need for an additional daemon.
  2. Dnsmasq is easier to install, and administrate than ISC dhcp-server+bind
  3. Its lease file is much easier to parse if need arises.
  4. Dnsmasq takes up less memory and CPU than ISC dhcp-server + Bind (approx. 10 times less)
  5. Dnsmasq does not bypass the kernel firewall rules like ISC daemon allegedly does in some configurations.

There is a package for the Pi and so you can install it in the usual way using apt-get.

  • DNS forwarding and cache – You still use your existing DNS (be it your ISP’s DNS, Google public DNS, or OpenDNS) for accessing the Internet. In theory, the caching it provides could increase performance, though I don’t have any expectations about that.
  • DNS for static IPs – Define domain names for devices with static IPs on your network.
  • DHCP – General DHCP provider.
  • DNS for DHCP clients – For any client that leases an IP from dnsmasq, it will also provide a domain name to that IP. Essentially your own internal dynamic DNS.


I started out planning to pick some TLD not used by ICANN (e.g. .local or .home) for my internal domains. Most posts I read on this subject recommended against that in case ICANN decided to use it in the future. Honestly, I don’t expect that to be an issue, but I followed their advice anyway.

The recommendation was to stick with a domain you already own and designate a subdomain for all of your internal hosts to be assigned under. For example, if you own, you could designate to be the root for all of your internal domains. A device might then be assigned Gets a little wordy, but at least the namespace is safe.

Step 1

At the Pi command line use apt-get update to download any package updates and then write the changes to the local package cache.

sudo apt-get update

sudo apt-get upgrade

Step 2

In newer Raspian versions, interface configuration is handled by dhcpcd by default. We need to tell it to ignore wlan0, as we will be configuring it with a static IP address elsewhere. So open up the dhcpcd configuration file with:

sudo vi /etc/dhcpcd.conf

and add the following line to the bottom of the file:

denyinterfaces wlan0  

Note: This must be ABOVE any interface lines you may have added (if you have added any)!

Restart the service and check is all running:

sudo service dhcpcd restart
sudo service dhcpcd status

Step 2

Install the server software.

sudo apt-get install dnsmasq

 Step 3

The next step is to modify the configuration file to suit your requirements.  This configures how the DNS server and the DHCP provider should behave. I’ll discuss the main options I used, but the example configuration file provided with the install has good documentation.

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig  
sudo vi /etc/dnsmasq.conf  

Paste the following into the new file:

# Use interface wlan0

# Explicitly specify the address to listen on

# Bind to the interface to make sure we aren't sending things elsewhere

# don't forward unqualified names (e.g. myserver)

# won't forward some non-routed addresses

# won't forward requests for the intranet subdomain

# Assign IP addresses between and
# with a 12 hour lease time

# Forward DNS requests to the local DNS and then Google DNS

# append the domain (below) to all hosts

# Use the /etc/ethers file to specify static mappings

Save the changes.

Step 4


This shouldnt need to be touched as it should get the details by DHCP from the local LAN.  Mine is:

# Generated by resolvconf
domain hfcs.local

Step 5


You’ll want to leave the existing contents, but add the host names for any of your devices using static IPs. You do not need every device listed in here, just the ones you want to be addressable via a domain name.

Format is <IP> <host name>, and the host name should only be the lowest level qualifier of the host (not the full domain name). For example, if you want a device to be, only specify mydevice. mynas webserver

Step 6


This is only needed if you have a few devices you want to assign static IPs to, but can’t or don’t want to configure the static IP on the devices themselves.

This is simply a <MAC> <IP> formatted file, with one mapping per line, for example:


Finishing up!

Run the following command

sudo service dnsmasq start

you can always check the status of the DHCP server with

sudo service dnsmasq status

To start the daemon services. Verify that they start successfully (no ‘failure’ or ‘errors’)
Then to make it so it runs every time on boot

sudo update-rc.d dnsmasq enable

Raspberry PI CarPuter

It was time to replace the old PC based CarPuter …


Raspberry Pi model A

DHCP Server:

DNS Server:

WiFi Hub:

DLNA Server:


© 2018: Forester IT | Easy Theme by: D5 Creation | Powered by: WordPress