Print to Email (print2email) in Ubuntu

I plan to write up here how I was able to pull together some nice pieces to create a printer in Ubuntu (actually, should work on most if not all Linux distributions) which you can print anything to and have it emailed. A pop-up window comes up and allows you to select from a pre-define set of email addresses or type in another recipient. What is printed is then emailed with a PDF attachment of the contents.

I found I was just tired of printing to PDF (PDF-CUPS), then having to go to my email client, attach the file and send it out. I was hoping to find a browser plug-in as this is what I most often want to print from, but was surprised there wasn’t one or at least I didn’t see one that was what I wanted. Anyway, having this solution independent of the browser allows any application to be the source of what you want to print from.

Here is an example of this page if it was printed and emailed to you as a PDF:


Enable NFS Export of AUFS pool in Ubuntu 12.04


This is taken from the Reference above at the latter part for Ubuntu variation. The purpose of doing this kernel compile was to enable the NFS export of a AUFS filesystem. 12.04 has AUFS still in the release however NFS export is off by default.

A good NFS export tutorial can be found here

Example export of NFS from /etc/exports:

(note, /storage is the aufs pooled. The export will require a fsid and I believe crossmnt is also required)



This is usually required after editing /etc/exports

sudo service nfs-kernel-server start

or perhaps

exportfs -r


Get the source for Precise

git clone git://

Copy the existing Kernel package and other control scripts

cp -a /usr/share/kernel-package ubuntu-package

cp ubuntu-precise/debian/control-scripts/{postinst,postrm,preinst,prerm} ubuntu-package/pkg/image/

cp ubuntu-precise/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/

cd ubuntu-precise

Get the existing config (Copy the kernel config file from your existing system to the kernel tree. This is the file that has the NFS export for AUFS turned off)

cp /boot/config-`uname -r` .config

Bring the config file up to date. Answer any questions that get prompted. Unless you know you are interested in a particular feature, accepting the default option by pressing Enter should be a safe choice:

make oldconfig

Change the NFS export of AUFS flag in the ncurses screen here (Do a search, i.e. / to find where aufs is)

make menuconfig

Clean the kernel source directory

make clean

Compile the source (Build the linux-image and linux-header .deb files using a thread per core + 1. This process takes a lot of time)

CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN` fakeroot make-kpkg --initrd --append-to-version=-customsds5 --overlay-dir=$HOME/linux/ubuntu-package kernel_image kernel_headers

Change to one directory level up (this is where the linux-image and linux-header .deb files were put):

cd ..

Now install the .deb files. In this example, the files are linux-image-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb and linux-headers-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb. You may receive warnings about ‘/lib/firmware/2.6.24-rc5-custom/’ – this is expected and will only be problematic if the driver you are trying to test requires firmware:

sudo dpkg -i linux-image-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb

sudo dpkg -i linux-headers-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb

You are now ready to boot into your new kernel. Just make sure you select the new kernel when you boot:

sudo reboot

Setting up Raspberry Pi Security CAM on Model A or B with minimal armhf image

This is just my notes on getting this setup of which I was inspired by this article. The Model A has 256MB of memory. Apparently the GPU needs a minimum of 128MB to work so it is important to get the CPU as much memory as possible by having non-required things stopped or uninstalled altogether. There is nothing here specific to the Model A, so this will all work with a Model B.

I looked at mainly two minimal images (this and this). I ended up using MINIBIAN as I struggled to get the camera working on the former although I believe the information futher down on making the script would have solved it. Alright, lets get to it.

  • I used the dcfldd command to prepare the SD card, but you can use plain dd also:
dcfldd bs=1M if=/tmp/2013-10-13-wheezy-minibian.img of=/dev/mmcblk0
  • I then used gParted to grow the ext4 partition to 2 GB (as updating the firmware takes up a lot of space).
  • For the remainder of the 8GB SD card, I made a xfs partition called storage (UPDATE: I will need to use ext4 as adding another type of filesystem adds tools and processes to manage them which takes a lot of memory relative to the little available)
  • You will need to have a network connection, I used a USB-Ethernet dongle on a Model A as it does not have an ethernet port and WiFi is not enabled on MINIBAN (wpasupplicant not installed – will be done later)
  • Next step was to put the SD card in the Pi and boot up
  • ssh to the Pi and log in with user root (default password: raspberry)
  • Issue the following commands:
dpkg-reconfigure tzdata (select your closest timezone)
apt-get update
dpkg-reconfigure locales (select your locale)
apt-get upgrade
apt-get autoremove
apt-get autoclean
  • Now, we need to enable the camera. I used this information and created a script as raspi-config doesn’t seem to work on these minimal images.
nano (paste the contents from the link)
chmod 755
apt-get install lua5.2 (needed as it is used in the script)
  • We can now test the camera by taking an image:
raspistill -o image.jpg

The camera should light up it’s RED light and take a photo. If we are successful here, we will now try to get motion to work. Go ahead and reboot in the meantime.

First we start by installing the dependencies required by motion (referenced here):

apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev

Since motion does not yet support the Pi, we need to keep following the above referenced location and get the special build of motion from the Dropbox link, un-compress it and put it in the executable path:

tar zxvf motion-mmal.tar.gz
mv motion /usr/bin/.

You can probably use the settings in the file from Dropbox above, however I used the config file and init script from this location.

cp motion.conf /etc/.
cp motion /etc/init.d/.
chmod 755 /etc/init.d/motion

The above conf file has a video location (if you search for CAM1 you will find it) you will need to modify to determine where to store the images and videos the camera captures.

The above motion init file has a sleep 30 for start option for the CAM1 location to be mounted. You can comment this out if you are storing images on the card or somewhere else that does not require this delay.

The init script will do a chuid to run this as user motion, therefore we need to create that user. I created it as a system user with no shell and added it to the video group so it is able to access the camera module.

useradd motion -rs /bin/false
usermod -a -G video motion

You should now be able to start and stop motion:

/etc/init.d/motion start
/etc/init.d/motion stop

To set it up so that it autostarts at boot up, execute this command:

update-rc.d motion defaults

Next up, I will attempt to reduce unnecessary usage of RAM on this Model A to give motion as much as possible following this guide. Currently I get about 20MB free when motion is running, which by subtraction means motion uses 40MB to run. Remember also that the GPU takes half (128MB) of the total RAM when you need to use the camera. I will do the following changes from the referenced guide above to get back about 13.5MB RAM:

  • Replacing OpenSSH with Dropbear | Save: +10MB RAM
  • Remove the extra tty / getty’s | Save: +3.5 MB RAM
  • Disable IPv6
  • Replace Deadline Scheduler with NOOP Scheduler

BTW, you can check the current version of the firmware etc using the following two commands. Not sure how you would compare if you have the latest or not. If you need to update it, you can use the instructions from the previous referenced guide.

    • /opt/vc/bin/vcgencmd version
    • uname -a

This gives me the following:

Sep 1 2013 23:27:46 
Copyright (c) 2012 Broadcom
version 4f9d19896166f46a3255801bc1834561bf092732 (clean) (release)

Linux raspberrypi 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l GNU/Linux

Here are the commands for the changes I made in the order I did them (explanations can be found from the referenced link):

apt-get install dropbear openssh-client
/etc/init.d/ssh stop
sed -i 's/NO_START=1/NO_START=0/g' /etc/default/dropbear
/etc/init.d/dropbear start
apt-get purge openssh-server
sed -i '/[2-6]:23:respawn:\/sbin\/getty 38400 tty[2-6]/s%^%#%g' /etc/inittab
sed -i '/T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100/s%^%#%g' /etc/inittab
echo "net.ipv6.conf.all.disable_ipv6=1" > /etc/sysctl.d/disableipv6.conf
echo 'blacklist ipv6' >> /etc/modprobe.d/blacklist
sed -i '/::/s%^%#%g' /etc/hosts
sed -i 's/deadline/noop/g' /boot/cmdline.txt

The next step I will do is set this up to work with WiFi (with a hidden SSID). If you have a Pi with Ethernet port or will use a USB-Ethernet dongle, then you may not require this. The Linksys USB10T works out of the box. I will however be using a Edimax nano WiFi adapter. My setup is from this reference.

I will also set this up to store images on my Synology NAS and try to get the Surveillance Station app on the NAS to work as described here. (DONE – works like a charm)

Finally, it goes without saying that without the hard work of all the folks referenced here (and many more), this would have been a whole lot tougher if not impossible for me to get going.