GliderJan Varho

Posts in category Linux:

Python hug with apache mod_wsgi

I found it surprisingly difficult to find a plain explanation of setting up hug and apache mod_wsgi. So here is how I did it.

Minimal hug API

Writing an API with hug is really easy. You can write a "hello world" in four lines of code:

import hug

@hug.get('/hello') def hello(name: str) -> str: return "Hello " + name

Running this on a devserver is also trivial:

hug -f


Cloning a Linux Partition

  • linux
  • ubuntu
  • filesystem
  • partition

Whenever I want to test a new release of Ubuntu I find myself cloning the root partition so I can safely upgrade and still keep my old install.

However, I usually forget some step and end up needing to debug grub boot. So this is a summary of what needs to be done in order to clone the partition and make it work. (Almost all of the below need to be run as root of course.)

First you need the file systems in question to be unmounted, so likely you

Remote Control Rhythmbox from Command Line

I have a mostly-headless HTPC without keyboard, so it is easier to control it remotely. VNC lets you do anything, but for simple things a command line is faster.

My media player of choice is rhythmbox, so there's an easy way to control it: rhythmbox-control. However, it requires an X session and ssh -X opens a new one. Here's how to use it to control a rhythmbox instance that is already running in the main display:

[code]alias rthythmbox-remote="env DISPLAY=:0.0 rhythmbox-control

Merging Persistence Changes in Ubuntu Live USB

  • aufs
  • filesystem
  • live
  • LZMA
  • persistence
  • Ubuntu
  • USB

When using Ubuntu Live USB there is the option of using persistence to store changes on the USB. It uses aufs to layer a read-write filesystem on top of a read-only squashfs compressed filesystem. This is great, because it fits over 2GB worth stuff into a c. 700MB default live system and still allows changes to be stored.

The bad news is that updates quickly eat the rw space because old versions of applications cannot be removed to free space. Also, removing

Reboot to Another Kernel (or Windows) with grub2

Update: Updated below for 11.04/Natty.

So I had some trouble getting grub-reboot to work, since it only seems to like numbers, but I figured it out. I made a script to reboot to another kernel or OS (Windows for me) once, leaving the default unchanged.

First one must set GRUB_DEFAULT=saved in /etc/default/grub and run update-grub and grub-set-default to set the default kernel (usually '0' for the most recent Linux kernel).

Using ssh with an Encrypted Home in Ubuntu

The encrypted home directory feature of Ubuntu is especially useful with laptops, where if it is lost one probably doesn't want others to have access to data. Unfortunately it messes up ssh access with public keys.

Key authentication is a very useful feature of ssh that I use all the time. It lets me avoid constantly typing in passwords and is more secure than password authentication. It works by storing authorized public keys (by default)

Radeon Power Management in Ubuntu 10.10 (Maverick)

One of the changes in the recent Ubuntu 10.10 (Maverick) is the upgrade of Linux kernel from version 2.6.32 (in Lucid) to 2.6.35. The change introduces several new features of which I especially like Radeon power management (for use with open drivers).

Unfortunately the default power profile only saves power when the screen is off (or on battery I think). I also know of no GUI tools to

Asus Eee PC 1001PX and Ubuntu Linux

  • kernel
  • Linux
  • multi-touch
  • PPA
  • touchpad
  • Ubuntu
  • xinput

To make the wireless of my 1001PX work in Ubuntu Lucid I had to install the 2.6.35 kernel from Kernel team PPA. The package name is linux-meta-lts-backport-maverick and it should eventually become available in the Lucid package archives.

Unfortunately, the touchpad didn't support multi-touch OOTB and the option in Mouse Settings was disabled. Here are the xinput commands I put in /etc/rc.local to get multi-touch scrolling and click emulation.

Ubuntu Lucid Lynx 10.04 Customizations

I finally have Ubuntu Lucid looking like I want it to. First a couple of screenshots and then some linking to the relevant packages etc. Here's the desktop with Firefox open.

Lucid Lynx
Screenshot{.alignnone .size-medium .wp-image-174 width="300" height="187"}

And here I've marked some customizations in the image. (Apologies for ugly text.) [![Lucid Lynx Screenshot /w

Aliasing Hostnames on Linux (Ubuntu)

  • alias
  • command
  • DNS
  • Firefox
  • host
  • Linux
  • ssh

When Googling for hostname aliasing on Linux, the most prominent answers were for SSH hostname aliasing, which is simple. For a general purpose solution the common answer was "install a DNS server", which is way over the top. Here's what I managed to figure out.

The objective is to have something like /etc/hosts, except like "hostname hostname2" instead of "address hostname".

My solution is to use the HOSTALIASES variable, which should point to a host alias file. In my case I did:

Splitting Files in-Place on Linux

Ok, so I have a 160GB disk image I need to split to small pieces (so I can compress those individually in the background later), but I only have a few GB free on the disk containing the image. Unfortunately, split isn't in place. Here's what I managed to put together using Bash on Ubuntu:

#!/bin/bash file=$1 size=$2 count=$3

for i in `seq $((count-1)) -1 0` do dd if=$file of=$file.$i bs=4096 skip=$((size*i/4096)) truncate --size=$((size*i)) $file echo $((count-i))/$count done

Trust Slimline Sketch Tablet on Ubuntu Karmic

Update: See the bottom for Ubuntu Lucid

I just installed my new Trust Slimline Sketch graphics tablet on Ubuntu Karmic 9.10. It was reported as "UC-LOGIC Tablet WP8060U" by xinput. Here's how I made in work, (based on Ubuntu wiki and some Googling):

1. Install wizardpen from Michael Owens' PPA using ppa:doctormo/xorg-wizardpen and installing the package.

2. Create an .fdi file using

Running [email protected] on Ubuntu without Straining the CPU

With my new quad-core I decided to install [email protected] on my Ubuntu Karmic. It is very easy using the origami installer. I just ran the following to install with team Ubuntu as my team:

sudo apt-get install origami && sudo origami install -t 45104 -u USERNAME

Unfortunately, while it is niced by default, it keeps the CPU running at 100%. This means the CPU uses more electricity and runs hotter. Most

Increasing Display Resolution in Virtual Machine Manager

  • Bash
  • KVM
  • Linux
  • resolution
  • script
  • virt-manager
  • virtual
  • virtualization

With KVM you can use a high resolution by passing kvm the -vga std parameter (or -std-vga before KVM-77). When using virt-manager to manage virtual machine guests, there is no option to change display resolution. However, it is possible to work around it as follows.

First, create a bash script that adds the argument to a kvm call: #!/bin/bash kvm [email protected] -vga std

Put it at, say, /usr/bin/qemu-kvm and make it executable: chmod +x qemu-kvm sudo install qemu-kvm /usr/bin/