Posts Tagged ‘Debian’

Linux not From Scratch – But Debian

February 8, 2013 1 comment

I’m a huge fan of the APT package management system, but I don’t like the trend where Canonical is going with Ubuntu and I’m not really a fan of Gnome3. Therefore, I was looking for something based on the APT package management system which is neither Ubuntu/Unity nor Gnome3.

My idea was to take a minimal Debian testing installation and customize it to my needs. No sooner said than done!


I already had a running Linux system on my Laptop, so I was able to prepare the boot medium directly from this machine. But the following steps can also be performed from a Windows or Mac machine, because UNetbootin is available for all these three operating systems (my boot medium had to be a USB stick because my X220 doesn’t have a CD/DVD drive).

I started my plan by installing two necessary packets

sudo apt-get install gparted unetbootin

Then I started gparted and created a fat32 partition on my USB stick. Afterwards I started UNetbootin and selected Debian testing x86_64 hd_media as my target system. Once finished I downloaded the first DVD of the Debian testing release


and stored it on the USB sticks root directory along with the stuff that UNetbootin put on it. Now, some of you might ask why I didn’t use the much smaller network installer and instead downloaded the whole DVD image when I only wanted to use a minimal set of applications. In my defense, I tried the network installer first, but I had some problems with it. The running Kernel lacked support for LVM, disk encryption and my SSD wasn’t recognized.
Once done preparing my USB stick I plugged it into the X220 and rebooted the system. During boot I held down the blue ThinkVantage-button, then hit F12 to select a temporary Boot device. From the menu I selected my USB stick and started the Debian installer.


I went through the default Debian installation (I used my entire disk with LVM and full disk encryption) up to the software selection dialog. There I only selected the following:

[ ] Desktop environment
[ ] Web server
[ ] Print server
[ ] DNS server
[ ] File server
[ ] Mail server
[ ] SQL server
[*] SSH server
[*] Laptop
[*] Standard system utilities

I didn’t want a graphical system just yet, because I didn’t want one of the bloated environments like Gnome or KDE. I just selected some essential components (Even the SSH server is optional. I use it quite often therefore I enabled it, but it isn’t a must-have).


After installing a basic system it was time for me to boot my newly created system. After logging in I installed a set of tools

sudo apt-get install i3 vim-gtk zsh rxvt-unicode build-essential xinit

The package build-essential is also optional. I’m a developer so I need it. Maybe I forgot some packages, just install them as you need them.

That was basically it, now I was able to start the GUI by executing


My window manager should be plain, simple and easy to configure, so I decided to use i3wm. It’s a tiling window manager which provides a lot of cool features. The first usage of i3wm might be a little bit unfamiliar but once you get used to it, it’s very powerful. Here is a quick introduction to i3wm.
You have one Super key, upon first start you can decide which one to use, either ALT-key or Windows-key (I simply refer to it as Super key). There are only a handful shortcuts you need to know in order to navigate through the system.

Super+d Start application
Super+Number Switch between workspaces
Super+cursor left/right Switch active window
Super+w window takes entire screen
Super+e windows side-by-side

For a more complete reference check the keybindings page on For now I wanted to spawn a shell, so I hit Super+d, typed urxvt in the appearing bar and hit Enter.

The default installation of i3wm didn’t look very appealing, so I wrote my own config file. I stored it in ~/.i3/config and the config file for the i3status bar in /etc/i3status.conf. I overwrote the existing files. Now I was able to just hit Super+r to reload the GUI and everything looked a lot better. It might be necessary to install additional fonts (I don’t remember exactly =P). If so, just run

sudo apt-get install xfonts-base

I added the following line in my ~/.i3/config to show my wallpaper.

exec feh –bg-scale /home/jester/Pictures/24.jpg

Before I did any additional configuration work, I wanted to switch to a better shell. In the beginning I had already installed the zsh. Now I just wanted a good configuration. Luckily there is a guy (Robbie Russell) who does this for us. I had to fetch oh-my-zsh from Github (on the bottom of the Github page are further installation instructions). After installing this framework I opened my ~/.zsh and changed the following lines:

plugins=(git debian cp)

to enable the cool git feature which you will see in the screenshot below, and also some aliases for aptitude. Oh-my-zsh contains several themes, I decided to use geoffgarside. So I added the following line


All themes can also be browsed here. Just select the one you like.

For a consistent color scheme I had to write my own ~/.Xdefaults file to have cool colors and transparency in the urxvt terminal windows. After storing the file in ~/.Xdefaults I was able to apply the changes by calling

xrdb ~/.Xdefaults

When I spawned a new shell the background was transparent, the wallpaper was visible and the colors matched the ones in the i3bar.

Instead of installing vim I installed vim-gtk, because with vim-gtk allows to navigate with the mouse and copy/paste text into/out of vim easily by selecting the text. For an even better experience, I wrote my own ~/.vimrc. I just stored this file in ~/.vimrc to have a solid vim configuration.


The following screenshot shows my fully configured system. In the bottom right I have vim open so that you can see the colors, and the status bar in vim. On the top left you can see the zsh (with oh-my-zsh) and its git integration. I’m currently in a directory which contains a git tree (Linux kernel), so thanks to the plugin I can see on which branch I’m currently on. On the left side I simply run Firefox with my start page. On the bottom you can see the i3bar showing system information (e.g. IP address, battery level, CPU temperature, etc.). Also in the i3bar in the far right corner you can see that I’m running Pidgin and Dropbox. It’s pretty neat that the i3bar supports applications with notification icons.


Several parameters in my configuration files are device depended.

If the i3wm doesn’t start correctly check the file /etc/X11/xinit/xinitrc. Mine looks like

# /etc/X11/xinit/xinitrc
# global xinitrc file, used by all X sessions started by xinit (startx)

# invoke global X session script
. /etc/X11/Xsession

Volume Up/Down keys
In my ~/.i3/config I have mapped two keys for volume up and down and another one to mute the sound

bindsym XF86AudioRaiseVolume exec amixer -c 0 — sset Master playback 3.22dB+
bindsym XF86AudioLowerVolume exec amixer -c 0 — sset Master playback 3.22dB-
bindsym XF86AudioMute exec /usr/local/bin/toggle-mute

These keys might differ depending on the used device. With the tool xev it is possible to capture the correct key events and compare them with the mapping table (xmodmap -pk). It might be necessary to write a new ~/.Xmodmap. I didn’t need to do this, therefore I can’t explain it. But there are plenty of information on the web about that.

Have fun!

Categories: tech foo Tags: , , ,

Debian on Android/Atrix with Debootstrap (Part III)

July 22, 2012 1 comment

As an extension to my previous post I will now explain how to make all the stuff persistent. You then do not need to retype the whole stuff to start the VNCServer every time you restart your phone. Just put the following script into the folder /etc/init.d/ of your chroot:


export HOME=”/root”
export USER=”/root”

STARTCMD=”vncserver -geometry 960×540″
STOPCMD=”vncserver -kill :1″

case $1 in
        if [ -e /tmp/.X1-lock ]; then
            echo “VNCServer already running”
        echo “$0 start|stop|restart”
        exit 1

exit 0

Afterwards you are able to start and stop the VNCServer, with the commands

service vncserver start


service vncserver stop

This allows starting, stopping and restarting the server.
To actually start the server when you switch into your chroot, you have to autostart it. The following way is not best practice (don’t let a Linux guru know ;-)). But for us it is working:

echo “service vncserver start” >> /root/.bashrc

or (when you don’t want to get the “VNCServer started…” message everytime you log into your chroot)

echo “service vncserver start > /dev/null 2>&1” >> /root/.bashrc

When you call “bootdebian” in your shell, the VNCServer will automatically start and you can connect to it via your favorite VNCClient.
Have fun!

Debian on Android/Atrix with Debootstrap (Part II)

July 16, 2012 7 comments

When running Debian on Android in a chroot, you are bind to a Shell, but if you want a graphical user-interface to have a more comfortable usage experience you can also install a VNC server in the chroot and connect to it from the Android host system. This tutorial is an extension to my already published tutorial because someone asked me if I can write a little bit more on how to get the VNC Server to run. Here it is:

  • Follow my first tutorial (here)
  • Start the chroot environment
  • Before you execute the commands below keep the following things in mind,
    • You need around 38MBytes of free storage in your chroot
    • When first starting the vncserver you need to specify a password (Remember it!)
  • Now execute the commands to install the vnc server and a lightweight X-Window setup

    aptitude install –without-recommends lxde tightvncserver xfonts-base
    export USER=root
    vncserver -geometry 960×540

  • Switch back to Android and install the android-vnc-viewer
  • Start the app and put in the following settings:

    Nickname: *Whatever*
    Password: -the-vncserver-password-you-defined-before-
    Address: localhost
    Port: 5901
    Username: -empty-
    Color Format: 24-bit color (4bpp)

  • Make sure you set the port to 5901 not the default (5900).
  • You are done. With these steps you should be able to connect to the running VNC server inside the chroot.

Finally, here is a photo of my Atrix running LXDE:

Thank you, and have fun.

Debian on MacOSX with VirtualBox in Headless Mode

Orignally I was searching for a way to build Buildroot images on MacOSX. Because my IMac has much more power than my Thinkpad X220i (i5 Quad-Core vs. i3 Dual Core). Therefore I tried to install all “build-essentials” (the Debian/Ubuntu users know what I mean) via MacPorts. Unfortunately some packets aren’t available through MacPorts, and missing packets aren’t the only problem, the fact that MacOSX not always complies to standards makes it hard/impossible to create uImages with Buildroot on MacOSX. Thus I was searching for a way to have a full Debian system available on my Mac.

My First idea was a Debian Chroot, but in my knowledge there is no way to get a Debian Chroot to run on MacOSX (although there is a Debian port for the Mach Microkernel). My second thought was then a Virtual Machine. I know with a VM I loose a lot of performance. But I gave it a try, because while my Mac executes build tasks I still can use my Laptop without any constrains and do something else at the time.

Therefore I was looking for an approach to have an “always on” Debian on my Mac (By “always on” I mean, starts when I boot my system, and runs in the background without needing too much CPU cycles when idling). At first I tried to automate the start of the VirtualBox application during boot. But I don’t wanted to have the running application always in my sidebar (two times actually, first, the VirtualBox icon itself, and second the VM icon).

Luckily on a website I found an explanation on how to start a VM in headless mode with VirtualBox’s command line tools. First I downloaded the Debian Netboot image (16MBytes), then I started the VirtualBox application and set up a new Linux system (For the name I chose “debian_shell”, I set the amount of Ram to 2Gbytes (from my 4GBytes) and for the harddisk I selected 8GBytes “dynamically allocated”. Afterwards I booted the downloaded Debian Netboot image to install a minimal system. During installation, in the packet selection screen I deselected “Desktop” and selected “SSH Server”. It was important for me to only have a terminal based system no X window overhead. That was it for now, my system was installed, configured and ready to be used.
After finishing the installation I configured the network behavior of my guest system (In the VirtualBox application “Right Click->Settings” on the “debian_shell” entry, then “Click” on “Network->Adapter1->”Port Forwarding”). I added an entry like the following to forward SSH connection attempts on my host machine on port 9003 to the default SSH port (22) on the guest system.


Then I created a small shell script with the following content to start my VM in headless mode.

RUNNING=`ps aux | grep -v grep | grep VBoxHeadless | cut -d ' ' -f 1`

if [ x$RUNNING == "x" ]; then
    VBoxHeadless --startvm debian_shell --vrdp=off > /dev/null 2>&1 &
    sleep 10
ssh death-jester@ -p 9003

I stored this script under “/usr/local/bin” with the name “debian”. Now when I called the script, it checked if the VM was already running if not it started the VM, and then logged into the machine via SSH, if the VM already ran it just logged in. For a more comfortable login I also stored the public key of my host-machine on the guest system.

Now have fun with your new “headless” Virtual Machine.

Debian on Android/Atrix with Debootstrap

April 2, 2012 1 comment

The Story

I have bought a new Smartphone. No, not the new and shiny Samsung Galaxy Nexus. An already a little bit older model, but still one of the most powerful devices out there, and a lot cheaper then the Galaxy Nexus, the Motorola Atrix 4G. My Nokia N900 served me well for the past 1.5 years, but now it was time for me to jump on the train called Android. But with my new Smartphone I don’t wanted to lose the possibility to use all my favorite Unix tools (e.g. SSH, SCP, RSYNC, etc.). So I decided to search for a guide on how to install Debian on Android. I found a lot, but non of them directly addressed on how to install Debian on Android/Atrix. So I decided to write a short guide for all the Atrix owners out there.

Rooting the Atrix

Before you start with the guide on how to install Debian you have to root your phone, otherwise this tutorial is useless for you. There are plenty of tutorials on how to do that, just bug google with “root atrix”. In other words, here I will not explain how to root your phone.

Debian Image

First of all we have to build a Debian image file, which we store on the Atrix to chroot into later. Just follow these steps to create an image. The parameter seek=xxxx defines the size of your chroot, so if you have enough space on your phone you can also create a bigger image. The command below will create a 800MB Debian image.

sudo -s
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=838860800 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian/
debootstrap --verbose --arch armel --foreign lenny debian
umount debian/
rm -r debian/

The debootstrap command will take some time, because it basically downloads the whole OS from the Debian FTP server.


On the Web I found a script to boot Debian on your phone, but for my Atrix it didn’t work out of the box. So I changed it to fit the Atrix’s system structure.

if [ $EUID -ne 0 ]
	echo "Becoming ROOT!"
	su -c bootdebian
	exit 1
echo "Mounting system as R/W"
mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system
echo "Setting some stuff up.."
export bin=/system/bin
export img=/mnt/sdcard-ext/debian.img
export mnt=/data/local/debian
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
if [ ! -d $mnt ]; then
    mkdir $mnt
echo "Mounting the Linux Image"
losetup /dev/block/loop5 $img
mount -t ext2 -o noatime,nodiratime /dev/block/loop5 $mnt
mount -t devpts devpts $mnt/dev/pts
mount -t proc proc $mnt/proc
mount -t sysfs sysfs $mnt/sys
echo "Setting Up Networking"
sysctl -w net.ipv4.ip_forward=1
echo "nameserver" > $mnt/etc/resolv.conf
echo "nameserver" >> $mnt/etc/resolv.conf
echo " localhost" > $mnt/etc/hosts
echo "Mounting sdcard and emmc in /mnt"
if [ ! -d $mnt/mnt/sdcard ]; then
    mkdir $mnt/mnt/sdcard
/system/xbin/busybox mount --bind /mnt/sdcard $mnt/mnt/sdcard
if [ ! -d $mnt/mnt/sdcard-ext ]; then
    mkdir $mnt/mnt/sdcard-ext
/system/xbin/busybox mount --bind /mnt/sdcard-ext/ $mnt/mnt/sdcard-ext
echo "Entering CHROOT "
echo " "
chroot $mnt /bin/bash
echo " "
echo "Shutting down CHROOT"
umount $mnt/mnt/sdcard
umount $mnt/mnt/sdcard-ext
sysctl -w net.ipv4.ip_forward=0
umount $mnt/dev/pts
umount $mnt/proc
umount $mnt/sys
umount $mnt
losetup -d /dev/block/loop5
mount -o remount,ro -t ext3 /dev/block/mmcblk0p12 /system

Copy the quoted text and save it to the root folder of the internal memory of the Atrix (/sdcard) with the name


It’s important to keep the name, otherwise the first command where the script checks if you’re root will fail. Now start the terminal application of your choice on the Atrix. I use the Better Terminal Emulator (I think its worth the price for only 2.99). Start the second stage of the debootstrap process by typing the following text.

mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system
cat /sdcard/bootdebian > /system/xbin/bootdebian
rm /sdcard/bootdebian
chmod 777 /system/xbin/bootdebian
/debootstrap/debootstrap --second-stage
echo 'deb lenny main' > /etc/apt/sources.list
apt-get autoclean
apt-get update

Now thats it, From now on you can call bootdebian when ever you need access to your Chroot. You can install everything with apt-get, the same as on you Desktop machine or Laptop.

Have Fun!