Tag Archives: Ubuntu

QEMU Linu/xMipsel emulation

This tutorial will assume that you have a running QEMU environment and that it works. These are old notes that I am simply capturing here as a reference, so things may have changed regarding links etc. Please exercise some caution with copying and pasting!

First step is to create a disk image to use with our new OS:

qemu-img create -f qcow hda.img 10G 

This will hold all the files related to our MIPSel machine.

Now go and grab the kernel image:

wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mipsel/current/images/qemu/netboot/vmlinux-2.6.18-6-qemu
wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mipsel/current/images/qemu/netboot/initrd.gz

Now you should be able to start the installation process with

qemu-system-mipsel -M mips -kernel vmlinux-2.6.18-6-qemu -initrd initrd.gz -hda hda.img -append "root=/dev/ram console=ttyS0" -nographic 

Once you have gone through the debian installer, you can boot your new system with

qemu-system-mips -M mips -kernel vmlinux-2.6.18-6-qemu -hda hda.img -append "root=/dev/hda1 console=ttyS0" -nographic 

Maven for Android

This is a quick howto on setting up and using Maven for your Android projects. Maven Android integration is not yet excellent, but is coming along nicely, and if you are familiar with Maven projects, will make managing your dependencies a lot easier!

I will be working with Ubuntu, but your set up will be similar. Just adapt paths etc for your setup as you need.

Ubuntu ships with Maven2, but we need Maven-3.0.5 at least in order to work with Android. I prefer to install maven manually because you don’t need to stress about pinning and other such nonsense from a binary distro. I also usually install stuff in /opt/ so that is where we will be working from.

The first thing that you need to do, is to grab the maven distribution file. I used 3.2.1, but anything later than 3.0.5 should work OK.

wget http://apache.saix.net/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz

Extract the archive and copy it to /opt/

sudo cp apache-maven-3.2.1 /opt/

Great! First steps completed! You are doing well so far!
I am assuming that you have a semi-recent JDK installed, in our case we need JDK 6+. Check for your JDK version with

java -version

If all comes back OK, we are ready to proceed.

Get the path to your JDK now with

locate bin/java | grep jdk

and make a note of it. Mine is at

/opt/java7/jdk1.7.0_45

Edit your bashrc file (located at /etc/bash.bashrc on Ubuntu) and add the following parameters (modify according to your paths) to the end of the file:

export ANDROID_HOME=/opt/android-sdk-linux
export M3_HOME=/opt/apache-maven-3.2.1
export M3=$M3_HOME/bin
export PATH=$M3:$PATH
export JAVA_HOME=/opt/java7/jdk1.7.0_45
export PATH=$JAVA_HOME/bin:$PATH:/opt/java7/jdk1.7.0_45

Load up your new basrc file with

source /etc/bash.bashrc

and check that everything is OK.
You should now be able to test your brand new Maven3 installation with

mvn -version

If that seems OK, you are ready to install the Android m2e connector in Eclipse. Please note that this works best in Eclipse Juno or later (I use Kepler).

Open up Eclipse, and choose to install software from the Eclipse Marketplace. This is found in Help -> Eclipse Marketplace. Do a search for “android m2e” and install the Android configurator for M2E 0.4.3 connector. It will go ahead and resolve some dependencies for you and install.

You should now be able to generate a new Android project in Eclipse with New Project -> Maven -> new Maven project and in the archetype selection, look only in the Android catalogue or filter on “de.akquinet.android.archetypes” and choose the android quickstart project.

If this fails, you can also generate a new project on the command line and simply import it to Eclipse.

mvn archetype:generate \
  -DarchetypeArtifactId=android-quickstart \
  -DarchetypeGroupId=de.akquinet.android.archetypes \
  -DarchetypeVersion=1.0.11 \
  -DgroupId=com.your.company \
  -DartifactId=myshinyapp

Once all of that is complete, dev carries on as usual. Remember that now dependencies are in your POM.xml document, so check that out first and ensure that you have some basics in there:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.your.company</groupId>
	<artifactId>myshinyapp</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>apk</packaging>
	<name>myshinyapp</name>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<platform.version></platform.version>
		<android.plugin.version>3.6.0</android.plugin.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>com.google.android</groupId>
			<artifactId>android</artifactId>
			<version>4.1.1.4</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>com.actionbarsherlock</groupId>
			<artifactId>actionbarsherlock</artifactId>
			<version>4.4.0</version>
		</dependency>

		<!-- Androlog is a logging and reporting library for Android -->
		<dependency>
			<groupId>de.akquinet.android.androlog</groupId>
			<artifactId>androlog</artifactId>
			<version>1.0.5</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
			<version>2.3</version>
		</dependency>

	</dependencies>
	<build>
		<finalName>${project.artifactId}</finalName>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>com.jayway.maven.plugins.android.generation2</groupId>
					<artifactId>android-maven-plugin</artifactId>
					<version>${android.plugin.version}</version>
					<extensions>true</extensions>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>com.jayway.maven.plugins.android.generation2</groupId>
				<artifactId>android-maven-plugin</artifactId>
				<configuration>
					<sdk>
						<platform>17</platform>
					</sdk>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

As you can see, I have included some other stuff, like ActionBarSherlock and JodaTime in case, as they are generally really useful, and it may save you some time just copying the dependency information!

Have fun!

Android video footage encoding on Ubuntu

Reposted from old site – original date: Saturday 21 July 2012
I wanted to encode some footage that I had shot from .avi to h.264 to play on an Android tablet device, but it seems that Android cannot play avi natively without additional app installations.
After some research, I found out that avconv, which is the replacement for good old ffmpeg in Ubuntu these days, does not work with x.264 either. The solution was to download and compile in x.264 support from source. Steps taken below.

In retrospect, I am not sure this is a great way to approach this, and probably grabbing an app is way better. That being said, this may be useful elsewhere too though.

mkdir avconv-source

2.) Download and install the x264 library

Grab yasm from Ubuntu

apt-get install yasm
cd ~/avconv-source
sudo git clone git://git.videolan.org/x264.git x264/
sudo ./configure --enable-static
sudo make
sudo make install

3.) Download the avconv source

cd ~/avconv-source
sudo git clone git://git.libav.org/libav.git avconv/
sudo ./configure --enable-gpl --enable-libx264
sudo make
sudo make install

and you can now execute

avconv -i test.mov -c:v libx264 -c:a copy test.mp4

How to monitor your MongoDB server(s) and ReplicaSets with Nagios on Ubuntu

Reposted from old site – original date: Thursday 12 April 2012

I needed to use Nagios to monitor a mongodb server (OK, my localhost as an experiment) and after a little poking around, managed this with relative ease.

These are the steps (I used nagios3 out of the Ubuntu repository)

1. Install Nagios3

2. Fix the SSH and disk error issues according to http://ubuntuforums.org/showthread.php?t=1749248

3. git clone https://github.com/mzupan/nagios-plugin-mongodb to /usr/lib/nagios/plugins/nagios-plugin-mongodb

4. Add the following commands to /etc/nagios3/commands.cfg

define command {
    command_name    check_mongodb
    command_line    /usr/lib/nagios/plugins/nagios-plugin-mongodb/check_mongodb.py -H $HOSTADDRESS$ -A $ARG1$ -P $ARG2$ -W $ARG3$ -C $ARG4$
}

define command {
    command_name    check_mongodb_database
    command_line    /usr/lib/nagios/plugins/nagios-plugin-mongodb/check_mongodb.py -H $HOSTADDRESS$ -A $ARG1$ -P $ARG2$ -W $ARG3$ -C $ARG4$ -d $ARG5$
}

5. touch /etc/nagios3/conf.d/mongodb_nagios2.cfg

6. add the following service definitions to the above file. Use your brain here a bit, so for example, if you do not run a replicaSet configuration on MongoDB, leave that service definition out, else it will produce CRITICAL warns the whole time and annoy you.

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Connect Check
    check_command           check_mongodb!connect!27017!2!4
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Free Connections
    check_command           check_mongodb!connections!27017!70!80
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Replication Lag
    check_command           check_mongodb!replication_lag!27017!15!30
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Memory Usage
    check_command           check_mongodb!memory!27017!20!28
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Lock Percentage
    check_command           check_mongodb!lock!27017!5!10
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Flush Average
    check_command           check_mongodb!flushing!27017!100!200
}

define service {
    use                 generic-service
    hostgroup_name          mongodb-servers
    service_description     Mongo Last Flush Time
    check_command           check_mongodb!last_flush_time!27017!200!400
}

define service {
      use                     generic-service
      hostgroup_name          mongodb-servers
      service_description     MongoDB state
      check_command           check_mongodb!replset_state!27017!0!0
}

define service {
      use                     generic-service
      hostgroup_name          mongodb-servers
      service_description     MongoDB state
      check_command           check_mongodb!index_miss_ratio!27017!.005!.01
}

define service {
      use                     generic-service
      hostgroup_name          mongodb-servers
      service_description     MongoDB Number of databases
      check_command           check_mongodb!databases!27017!300!500
}

define service {
      use                     generic-service
      hostgroup_name          mongodb-servers
      service_description     MongoDB Number of collections
      check_command           check_mongodb!collections!27017!300!500
}

define service {
      use                     generic-service
      hostgroup_name          mongodb-servers
      service_description     MongoDB Database size YOUR-dbname
      check_command           check_mongodb_database!database_size!27017!300!500!YOUR-dbname
}

see the bit that says YOUR-dbname in the final service? Yeah, you need to change that to an actual db name…

7. Do a quick sanity check on your configs

nagios3 -v /etc/nagios3/nagios.cfg

if you get something like:

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

you should be good to go.

8. Restart nagios3 with /etc/init.d/nagios3 restart

9. Check the web interface for nagios3 to see information about your MongoDB services!

10. Have some milk and a cookie, you deserve it!

How to set up and deploy a GlusterFS distributed, replicating file system.

Reposted from old site – original date: Thursday 19 April 2012

OK so you want a replicated, distributed file system. Sure thing. Enter Gluster. Take a look at http://www.gluster.org/ for more information.

For the purposes of this article, we will look at a 2 node replicated store and then mount the filesystem on a third node for use as a regular old filesystem.

1. Make sure that your 2 servers can talk to each other. If needs be, modify your hosts file so that they do. I personally do not like using FQDN for this as it slows things down, so normally would use an IP address.

2. On each of your Ubuntu based nodes, do an apt-get update && apt-get install glusterfs-server

3. On server 1, do a gluster peer probe server2 where server2 is either a FQDN or an ip address, depending on how you roll.

4. Check everything is cool with a gluster peer status. You should now be seeing some information on the peer(s) like hostnames and UUID’s, states and stuff like that.

5. Now we need to create a gluster volume, which is essentially a big disc that you are going to store your junk on. This is also pretty simple. Do a gluster volume create MyVolume replica 2 transport tcp server1:/data server2:/data

Some notes:

replica 2 means replicate across 2 machines. This is for your failover integrity. It also needs to be at least 2.
MyVolume is the name of your virtual volume.
transport tcp means use tcp to talk to the servers in the cluster
serverx:/data is the part on the physical disc that the data will be stored to.

6. Great! Ready for bigger and better things! Let’s start the volume: gluster volume start MyVolume

7. Check the status of the volume with gluster volume info. You should get some output telling you about your nodes as “Bricks”

8. Now is a good time to think about security and authentication. If you want to lock it down to a certain IP or host, you need to do a gluster volume set MyVolume auth.allow 192.168.1.5 or whatever your IP address is. Remember the thing is open until you set the auth.allow so if you need to allow a bunch of clients, then send it a comma separated list of IP’s

9. About now, we have a working server cluster. Now to configure the client. On your client machine, apt-get install glusterfs-client

10. mkdir /mnt/myshared

11. mount -t glusterfs server1:/MyVolume /mnt/myshared

12. You are done. Seriously, that is it. Add your new mount to fstab if you like, copy some stuff to it, watch it replicate etc.

Notes:

1. You can install the client on the server(s) too. If you want to mount the glusterfs share locally (i.e. on the server) use localhost

2. Replicas should be considered when creating larger clusters. Remember when you have more than one node failure, you want enough replicas to keep all the data integrity.

3. Leave other tips in the comments if you think of anything.

Getting the SD Card reader to work on a Dell Latitude and Ubuntu Natty

Reposted from old site – original date: Saturday 24 September 2011

If you have a Dell Latitude series laptop (widescreen version) you probably have experienced the fact that the SD card reader refuses to work.
This is due to the fact that the SD card reader and the Firewire port share space in the BIOS.
Thankfully, it is pretty easy to fix.

vi /etc/modprobe.d/sdhci-pci.conf

add the following lines:

options firewire-ohci quirks=0x10
options sdhci debug_quirks=0x40

Then update initramfs

update-initramfs -u

reboot and Voila! Go read some SD cards!

Upgrading Ubuntu to Natty Narwhal

Reposted from old site – original date: Friday 29 April 2011

So @cazpi decided to upgrade to Natty last night. Everything went smoothly until the restart where the whole system crashed on startup. This seemed to me like a graphics driver issue, so it was relatively simple to fix.

1. Restart the machine, holding down the shift key to get the GRUB menu.
2. Choose the failsafe kernel and select “Low graphics mode”
3. Boot into Ubuntu with no graphics acceleration.
4. Go to the “System” menu, administration -> additional drivers and select the NVidia proprietary driver. It will say that it is not in use.
5. Remove the driver, then add it again. It will download and install a newer version.
6. Reboot into a prettier, faster and easier to use Ubuntu Unity desktop!

No other issues so far. Graphics card is a NVidia 4GB card.

Hope this helps someone else!

Master/Slave replication on Ubuntu

Reposted from old site – original date: Monday 21 February 2011

This is a short HOWTO to set up a master and slave replicating database on Ubuntu using the popular MySQL server.

Steps:

1. On the Master server, you need to edit the my.cnf file located in /etc/mysql/my.cnf and modify the following:
In the mysqld section find the “logging and replication” section, then uncomment the server-id = 1 bit. This is to identify your master as the first ID. Then add in the following lines:

    binlog_do_db=chisimba  # input the database which should be replicated
    binlog_ignore_db=mysql # input the database that should be ignored for replication
    binlog_ignore_db=test
    

2. Still on the master server, you then need to create a user and assign some rights to that user to push the data to the slave(s)

    mysql> grant replication slave on *.* to 'replication'@192.168.10.2 identified by 'slave';
    

Remember to change the IP address to the IP address of your server!

3. Restart your MySQL server with /etc/init.d/mysql restart (or use upstart and do a mysql restart)

4. On the slave server, go to the logging and replication bit again in the my.cnf and add the following:

    server-id=2

    master-host = 192.168.10.1
    master-user = replication
    master-password = slave
    master-port = 3306
    

Taking care to change any variables (like IP address and passwords) to match your own setup.

5. Restart your slave MySQL server.

6. Check that the slave is up and running (as a slave)

    mysql> start slave;
    mysql> show slave statusG;
    

You should get something similar to the following:

    *************************** 1. row ***************************
             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.10.1
                Master_User: replica
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: MASTERMYSQL01-bin.000009
        Read_Master_Log_Pos: 4
             Relay_Log_File: MASTERMYSQL02-relay-bin.000015
              Relay_Log_Pos: 3630
      Relay_Master_Log_File: MASTERMYSQL01-bin.000009
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB:
        Replicate_Ignore_DB:
         Replicate_Do_Table:
     Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 4
            Relay_Log_Space: 3630
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: 1519187

    1 row in set (0.00 sec)
    

On your master server, check that the master is running as a master too:

    mysql> show master status;
    

You should get something like the following:

    +------------------------+----------+--------------+------------------+
    | File                   | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------------+----------+--------------+------------------+
    |MysqlMYSQL01-bin.000008 |      410 | chisimba     |                  |
    +------------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)
    

7. That is pretty much it! Make sure that your slaves are started after the master and then do some quick updates/deletes/inserts to check that the replication is taking place.

Enjoy!

How to make a sound trigger for your camera with Ubuntu

Reposted from old site – original date: Sunday 23 January 2011

So I was interested in taking some high speed photos, but the available tutorials all called either for a very expensive piece of equipment called a sound trigger, or else to build one from a bunch of tricky to get electronic parts and a soldering iron, none of which particularly appealed to me.

This, of course, got me thinking. Why can’t I code a sound trigger? The electronics all already exist in my laptop, and I know that you can do tethered photography on Ubuntu with gPhoto2 (in Ubuntu), so I started poking around.

I started with a bit of Perl, mainly because I knew of a module called Audio::DSP that I thought would do the job. A little bit of code later and I thought that there had to be an easier way, so I started a quick look around on http://www.sourceforge.net and found a little bit of Python (hell yeah!) that would do the job.

The code is called AudioTrigger and they provide a handy .deb even to get things started nice and quickly. Download it at http://sourceforge.net/projects/audiotrigger/

Once you have installed audiotrigger, launch it by going to the Applications menu -> Other -> audiotrigger. Now, audiotrigger launches as a PyGTK app in the taskbar thingy, so I almost thought that it had failed until I spotted the little icon. Much to my joy, right clicking on the icon brings up a context menu with profiles and a start/stop and quit item. I clicked on profiles and in the “Launch” text area, I put in /home/paul/Desktop/photography/strigger.sh I also tweaked the audio settings on my built in laptop mic so that it was nice and sensitive.

In the file /home/paul/Desktop/photography/strigger.sh I simply put a line to fire off gPhoto2 and save a pic to my desktop.

#!/bin/bash
gphoto2 --set-config capture=on --frames=1 --interval=0 --capture-image-and-download --filename "/home/paul/Desktop/photography/caps/%Y%m%d%H%M%S.jpg"

which I then chmodded to read/write/execute and saved.

I then started the audiotrigger “listener” (yes, haha…) and hoped for the best. It worked. Awesome.

So for a couple minutes of code, I saved a couple thousand bucks worth of equipment. How sweet is that? ;)

P.S gPhoto2 works with most, but not all cameras. I have a Nikon D90, but it should work with most well know DSLR’s. Check the gPhoto2 site for configs for your device.

PHP GD and Ubuntu

Reposted from old site – original date: Saturday 18 December 2010

It seems that the maintainers over at Ubuntu regard the PHP5 bundled GD version a fork of Boutells GD library (I understand why) and that forks = security risks (again, the logic is there). However, I am working on an application that requires a higher level of GD functions than the “older” GD library provides, chief amongst them the imageantialias() function (amongst others).

The only recourse was to recompile PHP, build a php5-gd package from that and then replace the current php5-gd deb with the new one. Luckily if you link against the standard system GD library (not the PHP shared lib) you get the full deal!

Sounds simple enough, and so it is! Here are the steps required:

1. Completely remove your old php5-gd with an:

apt-get remove --purge php5-gd

2. You then need a fakeroot and build environment (if you don’t already have one) so install that with the following:

# Install build tools, debian helpers and fakeroot
    apt-get install build-essential debhelper fakeroot
    # source code should reside in /usr/src
    cd /usr/src
    # Download PHP source
    apt-get source php5
    # Install all packages required to build PHP5
    apt-get build-dep php5
    cd php5-5.3.2

3. Next up we have to modify the debian rules as to how the package is compiled. All that you need to do here is to open up the debian/rules file in your favourite text editor and find the line that looks like:

--with-gd=shared,/usr --enable-gd-native-ttf 

and replace it with:

--with-gd=shared --enable-gd-native-ttf 

4. You can then go ahead and rebuild the deb with the following:

# build the php5-* packages
    dpkg-buildpackage -rfakeroot
    cd ..
    # Install the new php5-gd package
    dpkg -i php5-gd_5.3.2-1ubuntu4.5_i386.deb 

5. Restart apache with

/etc/init.d/apache2 force-reload

and you should be smiling!

That’s it. Told you it would be simple!