Delay starting Unifi Video (NVR) until it’s recording partition has been mounted.


Unifi Video installed on Debian is setup to record to a remote filesystem.


The unifi-video service is started before the remote filesystem is mounted. unifi-video fails silently after the remote filesystem has mounted in that it neither keep recordings nor does it notify the user that it is failing to persist recordings.


Delay the start of the unifi-video service until after the remote filesystem has been mounted.

To do so, make note of the remote filesystem to which you wish to save recordings, then modify unifi-video’s init script and make it wait until that filesystem has been mounted.


By /etc/fstab, I’m mounting /video by NFS. /video nfs rw,async,hard,intr,noexec,_netdev 0 0

The following command returns 0 if the above has been mounted; 1 otherwise.

grep " /video nfs4" /proc/mounts

As such, unifi-video’s init script can be modified to start only if the aforementioned test passes.

The script is at /etc/init.d/unifi-video

Add the following after start) while keeping the same indention level as the following code (in that file).

while ! grep " /video nfs4" /proc/mounts
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
        log_failure_msg "(the remote datastore is not mounted)"
        exit 1

Then execute the following to reload the init script.

systemctl daemon-reload

At this point it is a good idea to reboot the server, then execute the following to ensure unifi-video is able to start.

service status unifi-video

Configuring a Debian 9 v.m. to perform unattended upgrades.

Debian’s wiki contains an general guide for unattended upgrades.
(PDF Archive: UnattendedUpgrades – Debian Wiki)

Uncomment the following lines in /etc/apt/apt.conf.d/50unattended-upgrades

Unattended-Upgrade::Mail "root";
Unattended-Upgrade::MailOnlyOnErrors "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "false";

Passwordless SSH

Tired of having to retype your password each time you login to that remote computer?
Let me show you how to setup passwordless ssh.
Generate public and private keys on your client computer. Leave the passphrase empty.

user@local:~$ ssh-keygen -t rsa

Distribute your public key (~/.ssh/ to each servers .ssh/authorized_keys file.
user@local:~$ cat ~/.ssh/ | ssh user@servername 'tee -a .ssh/authorized_keys'
Security concerns: If someone gets hold of your private key AND your left the passphrase empty, the he will have access to all of the remote computers just as you.

[ad#Google Adsense-1]

How to : Install Ubuntu onto software RAID0

Found this nifty article which explains how to install Ubuntu onto software raid 0
2 hard-drive, best if they are identical.
Ubuntu liveCD
Boot into a live cd
Install “mdadm” and remove “dmraid” (the latter causes some of my drives to not show up in the installer).

sudo apt-get update
sudo apt-get install mdadm
sudo apt-get remove dmraid

Partitioning the two drives:
– Start the gparted partitioning manager
– Create a 500 MB partition on the “first” drive (“/dev/sda” + “/dev/sdb” = “/dev/sda” is the first one, but you can use any…I think)
– Create the main (“/”) partition on both drives, it’s size should be the rest of the free space minus the space used in the above partition and the swap partition beneath. Remember, this and the next partitions needs to be of equal size on both drives.
– The next partition is for your swap space. Create them with the same size as your RAM (combined they then will become doubled the space of your RAM).
It’s important you are aware what partitions are what “names”, sdb1 etc. You can also use different partitions sizes off course, as long as they have “enough” space.
[ad#Google Adsense-1]
Create the raids:

sudo mdadm –create /dev/md0 –verbose –level=0 –raid-devices=2 /dev/sda2 /dev/sdb1
sudo mdadm –create /dev/md1 –verbose –level=0 –raid-devices=2 /dev/sda3 /dev/sdb2

Format the new raids, or else the install application will want to alter the partition table, on the swap raid partition at least in my experience.

sudo mkfs.ext4 /dev/md0
sudo mkswap /dev/md1

Start the installer (on the desktop), but DON’T reboot in the end when it asks!!!
– Complete the steps…
– …until you get to the partitioning, choose the advanced option at the bottom.
– Choose “/dev/md0” and click change, choose ext4 (or what ever you want) in the dropdown menu, choose to format and choose mount point “/”.
– Choose “/dev/md1” and click change, choose swap (now the rest is greyd out?)
– Choose the 500MB partition, click change: ext4, format, “/boot”
– IMPORTANT! When you arrive at the summary page (after entering name, password etc), click advanced at bottom right, and choose the drive where the 500MB partition is located (“sda”, “sdb” etc….but NOT “sda1”, “sdb1” etc), this is where grub, the boot loader, will be installed.
– The pair partitions will show in black as unknown with a warning sign…just ignore this, it’s ok (assuming the drives doesn’t have additional problems).
You can skip the step on the summary page, but then the Ubuntu installer will install the boot loader on what ever drive it considers the first drive. This should be technically ok, but I prefer to keep Linux separate, had the Win7 connected, so it was detected by Grub.
[ad#Google Adsense-1]
We now need to do some stuff on the installed Linux, but before we boot off it because it can’t boot before we do. So we will mount it and “log” into it.

sudo mount /dev/md0 /target/
sudo mount –bind /dev/ /target/dev/
sudo mount –bind /sys/ /target/sys/
sudo mount –bind /proc/ /target/proc/
sudo mount –bind /dev/sda1 /target/boot/
sudo chroot /target

Notice the underlined part, you have to point it to the 500MB partition you created.
IMPORTANT: In Ubuntu 11.04, use the mounted dir, and not /dev/sda1.
“/media/7feb0b41-e0c2-4d98-b83e-f5f8f7b2e94b” <- example

sudo apt-get update
sudo apt-get remove dmraid
sudo apt-get install mdadm
sudo grub-install /dev/sda

Again, notice the underlined part, do the same as above, where is the 500MB partition?
Update: Notice that “dmraid” is now removed. A bird told me that it could interfere with mdadm. I installed/kept it, but you should probably remove it. Please tell me if this messes up things!
Update 2: Ubuntu 11.04 doesn’t have dmraid, so nothing to remove 
Reboot and remove the live cd/usb stick. If you have set the BIOS to boot from the correct HDD, your Linux Raid 0 setup should start 

How to : Change the hostname on Fedora 15

[ad#Google Adsense-1]
Change the entry in /etc/hosts and /etc/sysconfig/network.
If your using network, then Run as root: service network restart
If your using network-manager, then run as root: service NetworkManager restart
[ad#Google Adsense-1]

How to : Change the hostname on Ubuntu 11.04

[ad#Google Adsense-1]
Follow these steps in order to change the hostname on Ubuntu Server
1. Execute sudo hostname host.domain , replace host.domain with your hostname, example:
2. Edit the /etc/hosts file.
3. Edit the /etc/hostname file.
4. Edit the /etc/resolv.conf file if needed.
5. Reboot the server (highly recommenced although not required)
[ad#Google Adsense-1]

Rooting FreeBSD , Privilege Escalation using Jails

[ad#Google Adsense-1]

Pétur Ingi Egilsson <>
A remote user with root privilegs to a FreeBSD jail & user privileges to the jails host machine can obtain root privileges on the host machine.

FreeBSD 8.2 – Confirmed
Proof of concept:
From within the jail:
Compile the following using gcc and move resulting executable to /tmp/a.out
#include <stdio.h>
Make sure /tmp/a.out is owned by root and that is has the setuid flag set ( chmod u+s a.out )
From within the jails host as a regular user:
Locate the jails directory structure ( use the command ‘jls’ )
Execute the a.out program
[ad#Google Adsense-1]

Speed up your Internet browsing on Linux with a DNS Cache server

[ad#Google Adsense-1]
Most Linux distributions, unlike OpenSuSE, OS X and Windows, do not have a DNS Cache service installed by default.
Your computer will need to lookup a website’s IP address every time you visit it. The lookup request is passed on to the DNS server(s) specified in the /etc/resolv.conf file. It will take the server a few ms (milliseconds) at best to respond. It can take a ‘long’ time if your using a slow Internet connection (or a wireless LAN).
Caching DNS acts just like a regular DNS, from the users point of view. The service is configured to respond to lookup requests and return IP addresses. If the Caching DNS does not know the answer to the request, he will simply forward the request to the correct server and then forward the reply to you once it has been received.
So what’s the difference?
An Caching DNS holds a small database of recent requests, or so to speak. He will keep each entry in his database for a specified amount of time  (more about TTL). If the Caching DNS receives a requests for a entry currently in his database, he will respond to it instantly without contacting any other servers. If the Caching DNS is on your local computer, this will occur in 0 milliseconds.
You can check the responce time of your DNS server by running the following command:
dig | grep “Query time”
Let me demonstrate this by running the command two times on two different targets and explain the output.
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 49 msec
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 51 msec
Look at the above output. 49 msec (milli seconds) and 51 msec. The small difference between the lookup time for the two requests indicates that the DNS server I’m using has the answer to the request in the cache. is after all a very popular destination and someone on my campus has probably visited it recently.
What about a site nobody on my campus is likely to visit? I’ll go for
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 46 msec
The first request took 610 msec, that’s because the DNS server I’m using didn’t know the answer to my request and had to contact the DNS in charge of (which I guess is located somewhere in Japan).
Now, the second request took only 46 msec, that’s because the DNS I’m using has cached the request and does not have to contact the _Japanese_ server again any time too soon.
When the Caching DNS receives a lookup request, he will first check to see if he has the answer cached, if not he will contact the server responsible for the domain in question.
I would like to shave those 50 msec, by average, off each site I visit on the web.
I’ll show you how this can be done on Ubuntu Linux.
Begin by installing dnsmasq either from “Applications->Ubuntu Software Center” or by using the command sudo apt-get install dnsmasq from the console.
Next you’ll need the change the order of your DNS servers, do this by going to “System->Preferences->Network Connections”
Select the name of the connection you are using and click Edit…
Goto IPv4 Settings
If you have “Method: Manual”, put “,” (without the quotation marks) in front of whatever it says in your “DNS servers:” field.
If you have “Method: Automatic(DHCP)” -> Change to “Automatic (DHCP) address only” and put “,” in the “DNS servers:” field. is Googles DNS server, you might want to replace this with the one provided by your ISP (Internet Service Provider).
Reboot the network-manager service by executing the command sudo service network-manager restart from the command line.
You now have a DNS Caching service running on your computer.
Let me demonstrate the benefit:
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig|grep “Query time”
;; Query time: 0 msec
[ad#Google Adsense-1]
Other Linux distrobutions:
1. Install dnsmasq
2. Put “nameserver” at the top of your /etc/resolv.conf file
3. You might have to bring your interface down\up using ifconfig or ifdown\ifup

Questions or comments?

How to: Change the hostname on Ubuntu Server

[ad#Google Adsense-1]
Follow these steps in order to change the hostname on Ubuntu Server
1. Execute sudo hostname host.domain , replace host.domain with your hostname, example:
2. Edit the /etc/hosts file.
3. Edit the /etc/hostname file.
4. Edit the /etc/resolv.conf file if needed.
5. Reboot the server (highly recommenced although not required)
[ad#Google Adsense-1]

How to flush DNS cache Linux, Mac OS X, Windows

[ad#Google Adsense-1]
To flush DNS cache on Microsoft Windows (Win Vista, Win 7)

Run hte command prompt with Administrator privileges

Type ipconfig /flushdns

To flush the DNS cache on Linux, restart the nscd daemon:-

Linux does not cache dns by default. Some systems might have a dns cahcing service such as nscd. Restarting the DNS caching service will flush the DNS cache.

To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal, on Ubuntu or Debian you need to use sudo service nscd instead

To flush the DNS cache in Mac OS X 10.6 Snow Leopard

type dscacheutil -flushcache in the Terminal


[ad#Google Adsense-1]