How I encrypt and mount drives in Ubuntu using LUKs

Introduction

I used to encrypt the whole file system when I setup machines but this is a bit overkill for me, these days I just encrypt the home directory during setup and then encrypt any extra drives I have.  On my main desktop I have three extra drives I call data1, data2 and data3, once I’ve logged in Ubuntu automatically mounts these drives for me by securely remembering the passwords.  Here’s how to set it up.

Encrypting the drive

Ubuntu should could with everything you need already installed but if you need to you can install the cryptsetup package we’ll be using with the following terminal command:

sudo apt-get install cryptsetup

Now we can encrypt our drive with a single command, replace /dev/disk with your device name.  Make sure the drive isn’t mounted before you run this command:

sudo cryptsetup luksFormat /dev/disk

This will prompt you to enter a password that will be needed to mount the encrypted drive. Make sure you record your password somewhere safe, Ubuntu will remember it for us but you’ll need it if you ever want to mount the drive manually or use if on a different machine.

Next, we mount the new encrypted drive for the first time, we’ll call it mydisk but you can call it anything:

 sudo cryptsetup luksOpen /dev/disk mydisk

Now we’ll format the partition as ext3 with the label of mydisk:

sudo mkfs.ext3 /dev/mapper/mydisk -L mydisk

Reboot your machine, then if you open the file manager you should see your new encrypted volume under the device section:

Encrypted Drive in Nautilus

If you click on the encrypted drive, you’ll be asked you enter the password to mount it, here you can tell the system to always remember your password for you automatically by selecting Remember Forever:

Unlock the volume

That’s it, you should be to access your new encrypted disk from within the file manager once you’ve logged in:

Encrypted Volume in Nautilus

To automatically mount the drive after you login (without first having to click on it in the file manager) just add the following command as one of your startup application list:

gvfs-mount -d /dev/disk

Credit to How to Forge’s article on how to setup a luks volume properly.

 

Android’s Logcat stops working randomly in Eclipse

The best thing about learning to write apps for Android is using the Eclipse editor. I’d never programmed in Java before and at first Eclipse seemed intimidating. But after working through the notepad tutorials it struck me how amazing Eclipse is. I’ve used a few IDEs and Eclipse is the best.

One problem I had was Android’s Logcat window seeming to stop at random. I would have to restart Eclipse to get it to work again which was a pain. It turned out this wasn’t Eclipse’s fault at all. The solution was to click the DDMS perspective and make sure the emulator is selected in the Device tab, this would sometimes become deselected and logcat would not display any results. Clicking once on emulator-XXXX brings up the logcat details.

Random Wallpapers on DWM

My favourite window manager for Linux is DWM. I like to have random wallpapers each time I login so I store them all in a folder and have the script below select one for me:

wallpaper.sh

#!/bin/bash
wallpapers="$HOME/wallpapers"
wallpaper=$(find $wallpapers -type f ( -name '*.jpg' -o -name '*.png' ) -print0 | shuf -n1 -z)
echo $wallpaper > /tmp/.wallpaper
echo Setting wallpaper to: $wallpaper
feh --bg-fill $wallpaper

If I want to change the wallpaper I just run the script again. If I don’t like the wallpaper I run the script below which deletes the current wallpaper and sets a new one:

wallpaper-delete.sh

#!/bin/bash

# Get current wallpaper
wallpaper=$(cat /tmp/.wallpaper)

# Move to trash
mv "$wallpaper" ~/.local/share/Trash/files/
echo Moved wallpaper to trash: $wallpaper

# Set new wallpaper
~/bin/wallpaper

How I learned to be productive

I want to share with you three things that made me productive:

  • Setting daily goals to turn them in to habits
  • Time chunking
  • Waking up early

I always thought the reason I wasn’t productive was because I had a full time job. By the time you get home you’re exhausted, then there’s house work, cooking, etc and then time for bed.  I would envy people who didn’t have to work for a living, jealous of how productive they could be with all that free time.

Tracking Goals and turning them in to habits

I’ve been learning to play the guitar for years, every so often I would pick it up and practice for a few minutes.  I’d try and practice once a week but months would go by and I’d kind of forget about it.  This all changed when I started tracking my goals.  I wrote down the things I wanted to work on like practicing my guitar or excercise, and I started to record each time I practiced, this worked well but once I found a site called joesgoals.com then things really started to click.  Joe’s Goals lets you enter each goal you want to track, and always presents you with the last seven days to see how you’re going.  Once I started using this I would become very clear if I hadn’t practiced guitar or done some excercise for a while, and having a clear week without any marks against my goals became something I did not want to happen ever, where as before I’d never even notice it.

Time Chunking

Getting distracted or talking myself out of doing something was a big problem for me. I seen many people recommending disconnecting your computer from the internet, or not using a computer at all.  A better solution for me was putting my will power to work. By starting a timer for 25 minutes I gave myself some ground rules, I could only work on the task at hand while the timer was running (so no checking email, twitter, etc) and no talking myself out of it.  Once the timer was running I had to keep working until it had finished.

A great way to start time chunking is by using the Pomodoro Technique.

Waking up early

There didn’t seem to be enough hours in a day for me.  It turns out I wasn’t looking hard enough, for me those hours were found between 5am and 9am.

Waking up at 5am sounds brutal, and comes with it the feeling that you’d need a set bedtime in order to do it or it would be impossible.  This is not the case.  As long as you get out of bed at 5am each morning, your body will let you know what time you need to go to sleep.  The thing that motivates me to get up this early is all the free time I have to get my own things done before I start work.

I first read about the benefits of waking up early from this article by Steve Pavlina, I can’t recommend reading this enough:

http://www.stevepavlina.com/blog/2005/05/how-to-become-an-early-riser