How to enlarge a VirtualBox VDI disk file

VirtualBox does not offer anything for this task -- you need to do it yourself. It's not that hard:

Get more disk space

  1. Add an extra virtual hard disk to the machine with the disk size you want to achieve.
  2. Get a Linux live CD (like the Ubuntu live image) that offers fdisk, dd and gParted.
  3. Boot the guest from the CD, open a terminal (on the guest, not the host!) and become root: sudo su
  4. fdisk -l to see the disk information. \
    There should be one drive with some partitions and one without any....

Show the status of a running dd copy

When you do a bitwise copy using the dd tool you will not see any output until it completes or an error occurs.
However, you can send a command signal to the process to have it show its progress so far.

From another terminal, simply call (be root or use sudo):

pkill -USR1 dd

This makes dd write something like this into the terminal it is running in:

388+0 records in
387+0 records out
396288000 bytes (396 MB) copied, 24.9862s, 15.9 MB/s

Using Dropbox on Ubuntu

If you are exchanging files with a client via Dropbox you do not need to access the Web page every time you want to fetch files. Instead, you can fully integrate your Dropbox account(s) into nautilus (Gnome's file manager) with automatic synchronization.

  1. Get the .deb file for your system architecture (32 or 64 bit) from the Linux download page.
  2. Install the downloaded package using either the Gnome integration (double-click it) or the shell, e.g.: `dpkg -i naut...

How to use Ubuntu in English, but still show German formats

If you want to have an English Ubuntu UI, but still see dates, money amounts, paper formats, etc. in German formats, you can fine-tune your /etc/default/locale like this:

LANG="en_US.UTF-8"
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"

Make sure you have both en...

Linux: Refer to all arguments of a script call

In shell scripts you can use $1 to refer to the first argument, $2 for the second, etc. If you want to refer to all arguments (e.g. when writing a bash script that takes an arbitrary amount of arguments and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...”.

Use $@ instead, like in this script:
$ cat welcome
#!/bin/bash
echo Hello to $@

When called, the above would produce this:
$ ./welcome the world and universe
Hello to the world and universe

Note that $@ works for both sh and `ba...

Force Google Chrome to run in English on Linux

If you need Google Chrome to run in English, and your system locale is a non-English one, you have two options:

  • Switch your system to an English locale
  • Head over to /opt/google/chrome/locales/ and remove any .pak files except those starting with “en”. They reappear when Chrome gets updated.

This may help you running your Selenium tests using the Chrome driver on applications that choose the language from what the browser sends as preferred language (which Chrome guesses from your system locale).

List directories ordered by size (with human-readable output)

You know there is the du command to fetch the disk usage of a directory (“.” in this example). By default, output is sorted by directory name, not size:

du -h --max-depth=1 .
40K  ./a
2.3G ./b
3.1M ./c
500M ./d
2.8G .

To see which directories take up the most (or least) space you can order them by size like this (the -h switch does the magic of understanding humanized size formats):

du -h --max-depth=1 . | sort -h
40K  ./a
3.1M ./c
500M ./d
2.3G ./b
2.8G .

Note that you will need to...

Enable soft tabs in Vim

If you want to enforce soft tabs (spaces instead of tabstops) in Vim put this into your ~/.vimrc (Linux) or C:\Users\<Username>\_vimrc (Windows):

set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab

You can also call those commands in a running Vim instance (using ":set ...") to switch on soft tabs temporarily.

On a side note: remember the :mkvimrc command that saves active settings to a vimrc file.

Defining host aliases in your SSH config

You probably already manage servers you often connect to inside the ~/.ssh/config file. What is nice: you may define alias names for hosts so that you can say something like ssh foobar-staging.

This is especially helpful for servers whose hostnames are hard to remember or who don't have a DNS record at all (and must be accessed via their IP address).

To achieve the above, you can define something like this in your ~/.ssh/config:

Host foobar-staging
  Hostname staging.example.com

Note that SSH will only match this for `ssh f...

Getting started with Puppet

When you simply want to get to know Puppet, follow puppetlabs’ Learning Puppet Docs. They give you a handy introduction inside a virtual machine they provide. You can watch the talk by Garrett Honeycutt 'Expanded Introduction to Puppet'.

Do not miss their cheatsheat and their [learn-puppet virtual machine](http://info.puppetl...

Installing RMagick on Ubuntu

When installing RMagick you may get an error messages like this:

Version 2.13.1:

checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /home/arne/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
d...

How to send a test e-mail from shell

If you want to manually check if e-mail delivery works on a machine by sending an e-mail you can run the following:
mail -s Test someone@example.com < /dev/null

This will send an empty e-mail with "Test" as its subject to someone@example.com.

If you want it to contain a message body, call mail -s Test someone@example.com only; the mail application will then read your input from stdin. Finish your message by sending EOT with Ctrl-D -- if you are asked for anything else ...

Dual monitors crashing Linux with NVIDIA drivers

My T410 has a NVIDIA graphics card (NVS 3100M).

My BIOS configuration looks like this:

  • NVIDIA Optimus is disabled in
  • "Discrete" mode on
  • Internal Intel card deactivated

My X crashed when trying to activate both Dell U2410 monitors connected using DVI to the docking station.

The solution was to disable DDC/CI on the monitors: Menu -> Other settings -> DDC/CI disable

Note that you shouldn't disable DDC/CI if you don't have any issues with your displays.

Encrypt files using OpenSSL

Using OpenSSL it's very easy to seriously encrypt files.
Use the script below. Input / Output are self explanatory. Put a long passphrase into PASSWORD_FILENAME. It is the key to decrypt to file again. Paste this into a console and copy it to wherever you need it.

touch /tmp/openssl_encryption_password && chmod 0700 /tmp/openssl_encryption_password && apg -n1 -m 60 > /tmp/openssl_encryption_password

Remember to at least delete the input file afterwards. Better use [shred to wipe files on Linux](https://makandracards.com/makandra/1013-s...

Securely remove files on Linux

When you delete a file with rm it's still possible to recover the file or parts of it. Use shred to overwrite the content of a file and delete it afterwards.

shred -u $file

Be aware that this is not sufficient for flash memory, like SSDs or USB pen drives. The write will possibly target another memory area than where the file was located previously. Prefer disk encryption whenever possible.

Erasing directories

To erase complete directory structures, using shred is cumbersome. Use wipe instead:

wipe -...

Continously run command under bash

Sometimes you want to run a command forever, e.g. to compile a haml to html file on the console. Use this:

$ while(true) do haml index.haml index.html; sleep 1.5; done