Remove Desktop GUI from Raspbian

If you’re looking to save some space on your Raspberry Pi (mine runs on a 4 GB SD card), run these commands to remove all desktop/gui-related programs:

sudo su

apt-get install deborphan -y

apt-get autoremove --purge \
libx11-.* lxde-.* raspberrypi-artwork \
xkb-data omxplayer penguinspuzzle \
sgml-base xml-core alsa-.* cifs-.* \
samba-.* fonts-.* desktop-* gnome-.* -y

apt-get autoremove --purge $(deborphan)

apt-get autoremove --purge

apt-get autoclean

That will remove the desktop programs and any orphan programs left behind.

Check out more posts about the Raspberry Pi here: Raspberry Pi Posts

The Random Information Post

This is a sort of catch-all post that will house random coding/sysadmin things I don’t use enough to memorize.

Network Drives

Mount a volume over SSH

sshfs -p 2345 -o IdentityFile=~/.ssh/id_rsa /target/path


Compress a mysqldump

mysqldump -u user -p -B database_name | gzip > ~/backups/backup1.gz;


Merging AVI files

mencoder -noskip -oac copy -ovc copy `ls 20150203*avi` -o digest.avi

add -mc for audio sync

Renaming files using regular expressions

I had a bunch of backed up files with names like:

* 201506.pdf_2015_10_08_160622
* 201507.pdf_2015_10_08_160622

To remove the timestamp suffix, I used the rename utility. I had to install it with homebrew in Mac OS, but it works great:

rename 's/_2015_[0-9]{2}_[0-9]{2}_[0-9]{6}//' 2015*

ran in the above directory will give files named

* 201506.pdf
* 201507.pdf

Securely Wipe Drive

dd if=/dev/zero of=/dev/sdX iflag=nocache oflag=direct bs=4096

Convert all mkv files to mp4 in folder

for f in *.mkv; do avconv -i "$f" -codec copy "${f%.mkv}.mp4"; done

How to Fix the “VT-x is not available” in VirtualBox

I recently ran across this error when moving a VM to a different machine. To fix it:

  • Close VirtualBox
  • Go into the VM folder (usually inside a folder like VirtualBox VMs) and open the text file ending in .vbox.
  • Look for a line like <HardwareVirtEx enabled="true"/> and change it to <HardwareVirtEx enabled="false"/>.

That should fix the “VT-x is not available” error.

Rsync, Mac OS, Debian, and Modified Times. Oh My.

While writing a backup script to back up my data from Mac OS to a Raspberry Pi, I ran into an issue with relative modification times of the files being transferred: rsync thought every file on the Mac side was always more recently updated than on the Debian side.

I was using the -a flag for archive mode, which includes, along with a few other things, rsync’s default behavior of comparing file size and last modification time. The two OS’s weren’t agreeing on the times, however, so each file was copied over every time I ran the backup command.

To avoid this, I started using the -c flag, which compares the checksum of each file on both systems. This resulted in what I wanted: if I changed only one file, then only one file was sent to the backup and it is now very fast. So if you’re having this problem, use the -c flag for faster backups. Here’s my rsync command and flags in case you’re curious:

rsync -rc --progress --delete --exclude-from 'backup_exclude.txt' \
/home/myuser/ /media/treddell/backup_folder/

Installing a Printer in a Windows 7 Virtual Machine with an Ubuntu Host

I recently needed to print a document using a website that wanted to run a Java applet on a Windows machine. After a bit of work I had a Windows 7 virtual machine guest printing to a printer connected to the Ubuntu host machine. I’ll go through the steps to do this here in case I need to do it again or someone else is stuck trying to accomplish the same thing.

Install VirtualBox from Oracle

In the past I was fine using the VirtualBox version from Ubuntu’s repository. This works great if all you need is encapsulated in the VM you’re working with. However, once you want to interface the VM more closely with the host OS, you can run into trouble. Apparently there is some functionality missing when it comes to passing USB devices through to the guest machine using the open-source VirtualBox version. So make sure you go to Oracle’s VirtualBox download page and get the Oracle version: Download VirtualBox.

Install Guest Additions

Next install guest additions. After your guest OS (Windows 7) is installed, boot it up and click on the “Install Guest Additions” option in the “Devices” menu of the VirtualBox window running the OS.

Install the Extension Pack

Now you need to install the “Oracle VM VirtualBox Extension Pack”, also found on the Oracle VirtualBox download page. After downloading it, simply double click on it in your file manager. At this point I got an error saying

The installer failed with exit code 127: Error creating textual authentication agent: Error opening current controlling terminal for the process (`/dev/tty’): No such device or address.

It seems that VirtualBox needs different permissions to install the extension pack, so I closed VirtualBox, opened my file manager as root (sudo thunar or sudo nautilus) and double-clicked it again.

Add user to vboxusers

Add your user to the vboxusers group that VirtualBox should have created upon installation. Do this with the following command:

sudo usermod -aG vboxusers yourusername

Select the printer as a USB device

At this point I recommend shutting down the Windows 7 guest and rebooting your Ubuntu host, just to as superstitious way to make everything “kosher”. Now, after booting the VM again, you should be able to select your printer in the Devices>USB Devices menu. Once you select it, there will be check mark beside it and Windows 7 should see it and start installing drivers for the printer.

After that has completed, you should be able to print using your printer as if the VM were physically connected to it.

Taking Webcam Photos Via the Command Line

Here’s an easy way to use your default webcam to take a photo with a single command from a terminal:

mplayer -vo png -frames 1 tv://

I wanted a quick and easy way to take a photo with my laptop’s webcam and upload it to my server on a regular basis when I’m away from my machine. Side note: this wasn’t to take photos of unknowing human victims, but to check in on my dogs :).

I realized that the first few frames weren’t great due to the camera turning on, so I had it take 5 frames:

mplayer -vo png -frames 5 tv://

I then wanted to upload them to my server to be accessible (behind nginx’s basic authentication so only those with the credentials can see them):

mplayer -vo png -frames 5 tv://; \
scp 00000005.png;

I also wanted to take the webcam photo on an interval:

while true; do \
mplayer -vo png -frames 5 tv://; \
scp 00000005.png; \
sleep 120; \ 

That creates an infinite loop that takes 5 frames of photos, uploads the fifth one to my server, waits 120 seconds and then does it all again. This allows me to see a photo of whatever my laptop is pointed at that is at most 2 minutes old.

How to Create an eBook from Wikipedia

Wikipedia makes it very simple to create an eBook from articles on the site:

  1. Go to the Book creator page to start a book by clicking “Start book creator”
  2. Visit any pages you want to add to the book and click “Add this page to your book” at the top
  3. Click “Show book” at the top of the page when you are done
  4. Select which format (currently PDF, ODT, OpenZIM or EPUB) and then click “Download”

If you’re looking for a way to convert your EPUB Wikipedia eBook to MOBI for a Kindle, check out Calibre.

Update 2015-07-17: Apparently Wikipedia has redesigned how these documents are created and disabled all but PDF export: [Wikitech-ambassadors] Changes to PDF export; ZIM/EPUB will be disabled soon. However, you can still export your book in the PDF format and use Calibre to convert it to MOBI or EPUB.

Mining Bitcoin with a 2012 MacBook Pro

So I started researching bitcoin mining and the feasibility of doing it with a laptop. The machine in question is a mid-2012 MacBook Pro. From what I have read, it’s not worth mining bitcoins (or any other semi-mature) cryptocurrencies on a MacBook Pro. I don’t think I’m up to the task of buying an ASIC miner, but that’s essentially what you should do now to even recoup what you spend on electricity.

I should’ve jumped on the mining cart back when i first heard about bitcoin. Maybe there’s a place for my MacBook Pro in the world of mining DogeCoin… 🙂

Screenshot Sharing Script for Mac OS

I recently wanted to move away from commercial screenshot sharing tools (I was using Jing), so I decided to create a script that takes screenshots, allows you to annotate them, then uploads them to my webhost. The host I use is Digital Ocean and I use sftp to upload the image. Here’s the script:

#! /bin/bash

filename=`date +%Y%m%d%I%M%S`;
filename+=`openssl rand -hex 16`;
host=""; # change to your host
domain=""; # this could be the same as host above for you

screencapture -i $filename;
printf "\nHit enter when you are done editing image in Preview. Don't forget to save it first (cmd+s).\n";
open $filename; #edit?
read go;

rsync $filename $host:/var/www/screenshots/subdir/;
echo "http://$domain/$filename" | pbcopy;

mv $filename ~/Documents/work/screenshots/;
osascript -e 'display notification "The image has been uploaded to your server." with title "Image Uploaded"';

That will take an interactive screenshot, open it in Preview so that you can edit and save it, then continue and upload it to your webhost when you press any key in the terminal. I have my terminal (iTerm2) set to hide with a keyboard combo (ctrl+space) so that I can tell it to get out of the way if I’m taking a screenshot of something else. I assigned the script to a bash alias, so all I have to to do is open a terminal and type my alias. It also copies the url to the screenshot to your clipboard using pbcopy so that you can just paste it when you want to share it.