How to roll your own Debian based Linux distro


To build a minimal Debian based Linux system with a fully functional bash shell, TCP/IP networking with DHCP client and apt setup to be able to install any package from the Debian repositories. The resulting system will use about 157 MB disk space and consume less than 10 MB RAM.

This is now implemented in Bachata Linux.


A Debian based Linux system to work from (e.g. Ubuntu desktop) with the debootstrap and extlinux packages installed. Some virtualization environment is highly recommended for testing, such as KVM/QEMU.

Install system

This will install the system on a disk mounted at mnt. Choose a hostname for the instance to create, substitute it for ${HOSTNAME}. Substitute the URL to your nearest Debian mirror for ${MIRROR}.

  1. sudo debootstrap --variant=minbase --include=localepurge,netbase,ifupdown,net-tools,isc-dhcp-client,linux-base,linux-image-2.6-686,linux-image-2.6.32-5-686 squeeze mnt ${MIRROR}
  2. sudo rm mnt/etc/udev/rules.d/70-persistent-net.rules
  3. sudo rm mnt/var/cache/apt/archives/*
  4. sudo rm mnt/var/cache/apt/*.bin
  5. sudo rm mnt/var/lib/apt/lists/*
  6. sudo rm mnt/var/log/dpkg.log*
  7. sudo rm mnt/var/log/apt/*
  8. sudo mkdir mnt/boot/extlinux
  9. sudo extlinux --install mnt/boot/extlinux
  10. sudoedit mnt/boot/extlinux/syslinux.cfg
    default linux

        label linux
        kernel /boot/vmlinuz-2.6.32-5-686
        append initrd=/boot/initrd.img-2.6.32-5-686 root=UUID=${UUID} ro quiet

    Only for KVM/QEMU: add console=ttyS0 to the “append” line

  11. sudoedit mnt/etc/inittab
    For KVM/QEMU: uncomment getty ttyS0 and comment out getty tty[1-6]
    For others: comment out getty tty[2-6]

  12. sudoedit mnt/etc/passwd – blank password for root
  13. sudoedit mnt/etc/network/interfaces
    auto lo
    iface lo inet loopback
    allow-hotplug eth0
    iface eth0 inet dhcp
  14. sudoedit mnt/etc/fstab
    # /etc/fstab: static file system information.
    # Use 'blkid -o value -s UUID' to print the universally unique identifier
    # for a device; this may be used with UUID= as a more robust way to name
    # devices that works even if disks are added and removed. See fstab(5).
    # <file system> <mount point>   <type>  <options>             <dump>  <pass>
    proc            /proc           proc    nodev,noexec,nosuid   0       0
    UUID=${UUID}        /               ext2    errors=remount-ro     0       1
  15. sudoedit mnt/etc/hostname
  16. sudoedit mnt/etc/locale.nopurge
  17. sudoedit mnt/etc/apt/sources.list
    deb ${MIRROR} squeeze main
    deb-src ${MIRROR} squeeze main
    deb squeeze/updates main
    deb-src squeeze/updates main
    # squeeze-updates, previously known as 'volatile'
    deb ${MIRROR} squeeze-updates main
    deb-src ${MIRROR} squeeze-updates main
  18. sudoedit mnt/etc/apt/apt.conf.d/02nocache
    Dir::Cache {
      srcpkgcache "";
      pkgcache "";
  19. sudoedit mnt/etc/apt/apt.conf.d/02compress-indexes
    Acquire::GzipIndexes "true";
    Acquire::CompressionTypes::Order:: "gz";
  20. sudo chroot mnt localepurge
  21. sudo chroot mnt apt-get update
  22. sudo chroot mnt passwd root

Install on a physical disk

  1. Create a bootable partition of at least 288 MB with system code 83 “Linux” using fdisk
  2. sudo mke2fs -L ${HOSTNAME} -t ext2 /dev/xxxx
  3. sudo UUID=`blkid -o value -s UUID /dev/xxxx`
  4. mkdir mnt
  5. sudo mount /dev/xxxx mnt
  6. Install system as above
  7. sudo umount mnt

Install in KVM/QEMU

  1. dd if=/dev/zero of=${HOSTNAME}.img bs=1024 count=288K
  2. mke2fs -L ${HOSTNAME} -t ext2 ${HOSTNAME}.img
  3. UUID=`blkid -o value -s UUID ${HOSTNAME}.img`
  4. mkdir mnt
  5. sudo mount ${HOSTNAME}.img mnt
  6. Install system as above
  7. sudo umount mnt
  8. virt-install --connect qemu:///system -n ${HOSTNAME} -r 256 --os-type linux --os-variant debiansqueeze --import --disk path=${HOSTNAME}.img --network=network:default --graphics none --virt-type kvm

Use --virt-type qemu if your CPU doesn’t support virtualization.

Then you can start it with virsh start ${HOSTNAME} and connect to it with virsh console ${HOSTNAME}

For some reason, doing reboot from inside the guest doesn’t seem to work properly. virsh reboot and virsh shutdown doesn’t work either (you might get that to work by installing some ACPI stuff in the guest). Use halt from inside the guest to have a clean shutdown, and then restart it with virsh start.

Install in VirtualBox 4.1

First create a virtual machine in VirtualBox with an empty VDI disk ${VDI_FILE} of least 288 MB.

Install VDI mounting tool according to this description.

  1. mkdir vdi-mount
  2. vdfuse-v82a -f ${VDI_FILE} vdi-mount
  3. mke2fs -L ${HOSTNAME} -t ext2 vdi-mount/EntireDisk
  4. mkdir mnt
  5. sudo mount vdi-mount/EntireDisk mnt
  6. Install system as above
  7. sudo umount mnt
  8. fusermount -u vdi-mount

Then start the virtual machine in VirtualBox.

Install in other virtualization environments

Please tell me how!

Posted in Linux | 17 Comments

How to move MySQL data directory in Ubuntu Server

By default, the MySQL data is placed in /var/lib/mysql, which is a reasonable default. However, sometimes you want to place it somewhere else, such as on an other file system. Using a symlink doesn’t seem to work, so you have follow this procedure.

To move the MySQL data directory from /var/lib to /mnt/mydata, run these commands as root:

  1. apt-get install mysql-server
  2. service mysql stop
  3. mv /var/lib/mysql /mnt/mydata/
  4. replace /var/lib/mysql with /mnt/mydata/mysql in
    • /etc/passwd – mysql
    • /etc/mysql/my.cnf – [mysqld] datadir
    • /etc/apparmor.d/usr.sbin.mysqld (twice)
  5. service mysql start
Posted in Uncategorized | 10 Comments

Using ZTE Blade Android phone with Ubuntu 11.10

Using a ZTE Blade Android phone connected with USB is a bit tricky with Ubuntu 11.10.

First you need to apply the patch in this bug, after doing that you should get USB storage to work.

After doing that, it is also possible to get development and debugging to work over USB. Create a group androiddev (addgroup --system androiddev), and add yourself to it (gpasswd -a yourUsername androiddev). Then create a file /etc/udev/rules.d/11-android.rules with this content (4 lines, watch the line breaks):

SUBSYSTEMS==”usb”, ATTRS{idVendor}==”19d2″, ATTRS{idProduct}==”1353″, MODE=”0666″, OWNER=”root”, GROUP=”androiddev” #Normal Blade
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”19d2″, ATTRS{idProduct}==”1350″, MODE=”0666″, OWNER=”root”, GROUP=”androiddev” #Debug Blade
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”19d2″, ATTRS{idProduct}==”1354″, MODE=”0666″, OWNER=”root”, GROUP=”androiddev” #Recovery Blade
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”18d1″, ATTRS{idProduct}==”d00d”, MODE=”0666″, OWNER=”root”, GROUP=”androiddev” #Fastboot Blade

Finally logout and login again. Don’t forget to enable USB debugging on the phone before connecting it.

Depending on the exact model you have, you might need to adjust the file. See what the lsusb command says about your phone and put that product id in the second line.

Posted in Linux | 5 Comments

How to disable activity logging in Ubuntu 11.10 Oneiric Ozelot

Ubuntu has mechanism to log user activity such as used documents. This is used to facilitate searching, but can also be intrusive to your privacy.

Here is a way to disable this logging without breaking Unity or any other part of the system, execute these commands in a terminal:

  1. sudo mv /etc/xdg/autostart/zeitgeist-datahub.desktop /etc/xdg/autostart/zeitgeist-datahub.desktop-inactive
  2. rm ~/.local/share/recently-used.xbel
  3. mkdir ~/.local/share/recently-used.xbel
  4. rm -rf ~/.local/share/zeitgeist

then log out and log in again.

Posted in Linux, Ubuntu | 7 Comments

Backup your mobile phone in Linux

To backup data from a non-smart SonyEricsson mobile phone (such as W890i) in Linux, use the gammu utility.

  1. Install gammu, it is available as a package in the standard repositories for Debian and Ubuntu, just install the gammu package.
  2. Create a ~/.gammurc file with the following content:

    port = /dev/ttyACM0
    connection = at

  3. Connect your mobile phone to the computer with the USB cable and select Phone mode
  4. Use

    gammu backup <filename>.vcf -yes

    to backup your phone book to a vCard file

  5. Use

    gammu geteachsms

    to get all SMS stored in the phone (both sent and received), they will be written to STDOUT

  6. There is also a lot more you can do with gammu
Posted in Linux | 2 Comments

PHP session timeout

The developers of PHP has, in their infinite wisdom, decided that the default session timeout should be 24 minutes (1440 seconds).

This means that if you have a MediaWiki wiki and are editing a single page for half an hour and then click the save button, you are logged out and all your changes are lost. I just learned this the hard way.

Fortunately, you can change this with the session.gc_maxlifetime parameter in php.ini. So set this to a higher – more sane – value, such as 86400 (24 hours).

Posted in PHP, web | Leave a comment

Upgrade to Ubuntu 11.04 without Unity

The new Ubuntu release 11.04 Natty contains the new Unity desktop environment which is quite controversal. I have tried it for a while and I think it is neat but too buggy and immature. However, it is easy to revert to the old Gnome 2 desktop environment and have things working almost as in 10.10.

First do a normal distribution upgrade to 11.04, then go to System Settings -> Login Screen and select Ubuntu Classic as default session and reboot.

Posted in Linux, Ubuntu | Leave a comment

Using Sveon SNT1020 WiFi USB adapter in Ubuntu

I just brought an Sveon SNT1020 WiFi USB adapter.

It works very well with Ubuntu Linux 10.10, just connect it to an USB 2 port and you can start using it with NetworkManager right away, no drivers or setup necessary. You should possibly disable any built-in WiFi adapters first though.

It cost €35.

Posted in hardware, Linux | 1 Comment

Web application frameworks in Java

When you know which type of web application you are to develop, it’s time to have a look at some possible choices.

I have tried to categorize some modern and popular web application frameworks in Java.

Simple server driven MVC page based

This category contains the traditional frameworks used for developing web applications with purely server driven application logic. They are based on complete HTML pages and uses the Model-View-Controller design pattern.

They do not directly support for client driven application logic, though it can be done if combined with a comprehensive JavaScript library like jQuery.

Full stack server driven MVC page based

This category contains some more advanced full stack frameworks. They are used for server driven application logic and not suitable for client driven application logic. They are inspired by Ruby on Rails.

Server driven component/widget based

Focus on UI components (widgets) instead of HTML pages, make development a bit more like desktop applications in frameworks like Swing. They are used for server driver application logic and not suitable for client driven application logic.

Client driven component/widget based

Useful for developing client driven application logic by automatically generating the client side JavaScript code.

  • Google Web Toolkit
  • Compiles Java to JavaScript and handle the cross-browser issues. Also abstracts away most of HTML. There is a good tutorial.

  • Vaadin
  • Based on GWT, but abstracts away even more HTML. Also handle the server side and automates AJAX based browser-server communication (using a native data format). A programming model which feels much more like Swing than usual web application development.

  • AribaWeb
  • Quite advanced full stack framework.

Posted in AJAX, Java, JavaEE, web | 1 Comment

Web applications and web frameworks

If you are to develop a web application, there are a lot if frameworks to choose between.

I assume that the web application by its nature needs to have bi-directional communication between the web browser and the server during the execution, initial downloading of resources is not enough. I also assume that the available technologies are HTML, CSS and JavaScript/AJAX; no Flash, Java applets, ActiveX, Silverlight or other browser plug-ins are used.

The first thing you should do is to decide what type of web application you want to develop, since that decision have a big impact on what frameworks that are suitable.

The primary question to ask is whether the application logic should be driven from the server or from JavaScript in the web browser. Before we had AJAX, server driven logic was the only possibility, but with AJAX it is also possible with client driven logic. It is also possible to have a mixture, but that should be avoided since it tends to make the application hard to test and lead to messy code design.

With server driven logic, most requests to the server return a complete HTML page. There may also be some AJAX requests which returns HTML fragments.

With client driven logic, only the initial request return a complete HTML page (usually a quite empty page). All subsequent requests are AJAX which return data from the server in JSON or XML format. This makes it possible to implement the server part as a web service which could be used for other things than providing data for the web application. This also makes the server part easy to test separately. (This is usually associated with Web 2.0.)

Secondly, the framework choice should also depend on whether you are developing the whole system from scratch, or if you have an existing backend with data persistence that you need a web user interface for. When developing from scratch, you can benefit from using a full stack framework with integrated data persistence, but with an existing backend you are probably better off with a framework which only does the web tier.

Posted in AJAX, web | 2 Comments