Archive for the ·

linux

· Category...

Manual wifi config in Debian

Comments Off

Most modern GUI based distros handle setup and management of Wifi connections very well these days. However, sometimes you need to go the way of the command line. The following outlines the basics in Debian, plus some useful commands.

Driver
First, the Wifi device I had laying around was a Realtek based USB dongle similar to this. The driver for that is in the non-free repository, so I added the parts in bold to my /etc/apt/sources.list

deb http://ftp.ch.debian.org/debian/ wheezy main contrib non-free
deb http://ftp.ch.debian.org/debian/ wheezy-updates main contrib non-free

I could then install the driver:
apt-get update
apt-get install firmware-realtek

Config
There are two config files to handle: The basic network configuration (/etc/network/interfaces), which also includes wired networks and the loopback, and the WPA wifi specific configuration (/etc/wpa_supplicant/wpa_supplicant.conf). Although it is also possible to specify wifi parameters in the network interfaces file, it is better handled by the wpa because then you can configure settings for multiple networks (e.g. home and work) as seen below.

/etc/network/interfaces contains the following:

# The loopback network interface
auto lo
iface lo inet loopback

# Wired ethernet
auto eth0
iface eth0 inet dhcp

# The primary network interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
      wpa-driver nl80211
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

The loopback lo interface is configured, a wired eth0 port, and the wlan0 wifi. All networks are set to come up automatically, the last two use DHCP to get their address, and the Realtek nl80211 driver is specified as well as a reference to the WPA Supplicant config.

/etc/wpa_supplicant/wpa_supplicant.conf contains:

ctrl_interface=/var/run/wpa_supplicant
update_config=1

network={
    ssid="my_home_network"
    key_mgmt=WPA-PSK
    psk="wifi passphrase"
}

network={
    ssid="my_work_network"
    key_mgmt=NONE
}

Here two networks are configured: A home network with WPA encryption and its passphrase, and an open network for work.

To bring the wifi network up, simply run the following. If iterating on the configuration, it’s has to be stopped first.

ifdown wlan0 && ifup wlan0

Useful commands
Other useful commands while debugging this include:

For general network configuration and status:

ifconfig

iwconfig

For listing all available networks and their parameters. This works even before you have connected to a specific one, so it’s a good test to see if the wifi device is even working:
iwlist wlan0 scan

For starting the wpa supplicant manually and checking the wifi configuration. Notice the specific driver and interface name:
wpa_supplicant -B -Dnl80211 -iwlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Comments Off

Debian 7 – netinst

Comments Off

In search of a small simple GNU/Linux server setup, I started with a Debian 7 installation through a network based install – netinst. Using that image is simple, either by writing to a CD, or simply to a USB drive or memory card:
(Replace X with your flash drive, but be careful; everything will be overwritten, without any recovery option).

sudo dd if=debian-7.8.0-i386-netinst.iso.torrent of=/dev/sdX
The installation was straight forward, but it has to be hand-held since there are multiple prompts from various parts of the installation throughout. Unfortunately, the final step of writing out the GRUB configuration failed, since the install medium, the USB flash reader, was included in the GRUB device map. Removing it from /boot/grub/device.map fixed that, and a little rescue operation resolve the rest.

Once booted, there was a problem with the start-stop-daemon; for some reason, it was set to a fake mock implementation. That caused all services to not start. Swapping in with the real implementation took care of that:

mv /sbin/start-stop-daemon /sbin/start-stop-daemon.FAKE
ln -s /sbin/start-stop-daemon.REAL /sbin/start-stop-daemon

Finally, some essentials are always missing:

apt-get install emacs atop htop iftop iotop tree git tig sudo autossh iptables-persistent wpasupplicant cryptsetup smartmontools

Comments Off

Open a Firefox image in a VirtualBox guest OS

Comments Off

In my recent Ubuntu and Windows install for my father, a requirement was to open images shown in Firefox (which runs on the host Ubuntu OS) in Corel Paint Shop Pro which runs in the VirtualBox guest Windows 7 OS.

The command to execute an application from the host in the guest is vboxmanage guestcontrol [...] exec, documented here. It also needs the (guest OS) user credentials, the application to run and its arguments. Also note, that back-slashes have to be escaped, and since the path contains spaces it has to be in quotes.

The following assumes that the name of the VirtualBox machine is called “win7″, and application to run is PSP, and shows example values for username, password and filename.

Note that it also assumes that the Windows drive S:\ is a shared mount point between the host and guest OS, and that downloaded images is saved to that location.

vboxmanage guestcontrol win7 exec --image "C:\\Program Files (x86)\\Corel\\Corel PaintShop Pro X5\\Corel PaintShop Pro.exe" --username my_guest_user --password my_guest_password -- "s:\\image_file.png"

So far so good. However, to execute this for any image in Firefox proved a bit tricky. It does not seem to be possible to associate an Open action from the right-click menu with a given application in Firefox. The plugin “Open With Photoshop” came to the rescue. It gives an extra menu item when right-clicking on any image, and what most useful, it let’s you choose the executable to run.

I took the command above, and created my own script, e.g. “corel_psh.sh”, which looks like this:

#!/bin/bash
 
WINUSER=my_win_user
PASSWORD=my_win_password
 
f=$1
b=`basename $f`
 
vboxmanage guestcontrol win7 exec --image "C:\\Program Files (x86)\\Corel\\Corel PaintShop Pro X5\\Corel PaintShop Pro.exe" --username $WINUSER --password $PASSWORD -- "s:\\$b" &> /tmp/open_with.log

I suppose a valuable addition would be to move the downloaded file to the correct location if necessary.

Comments Off

Default PDF viewer in Debian

Comments Off

By some strange logic, the primary and default application for viewing PDFs in Debian is Gimp. If you want to edit the PDF, that might make sense, but that is not the most common use case. There is a bug and discussion about this, but unfortunately, in somebody’s stubborn opinion, “it is not a bug”, and was closed many years ago.

Luckily it is easy to fix. The default setting can be found in the file /usr/share/applications/mimeinfo.cache which contains this line:
application/pdf=gimp.desktop;gimp.desktop;epdfview.desktop;evince.desktop;

Notice how Gimp is listed first, while the PDF viewers ePDFViewer and Evince are last in the list. You can edit that file (as root). Or if you prefer you can override the user local setting in /home/$USER/.local/share/applications/mimeinfo.cache, and insert something like

application/pdf=epdfview.desktop;evince.desktop;

The change should take effect immediately, across all applications and browsers, unless the default is overridden there. E.g. Firefox and Chrome have their own internal PDF viewers, however the default MIME applications will be available for selection when the file is downloaded.

Comments Off

Git branch in zsh prompt

Comments Off

When working in a git directory, I would like to see the current branch as part of the Zsh prompt. There are more advanced use cases out there, but I’ll stick with the branch name for now.

The following lines in ~/.zshrc takes care of the prompt. There are a few gotchas, though: The git command will fail if not in a git controlled directory, so we’ll have to hide that failure message. Then, for Zsh to execute the function, rather than printing its verbatim name, the prompt_subst option has to be set. Finally, it is important to use single quotes for the PROMPT line. If double quotes are used, the first output of the function is used, and never called again.

function get-git-branch {
  b="`git symbolic-ref --short HEAD 2> /dev/null`" && echo "($b)" || echo ""
}
 
setopt prompt_subst
 
PROMPT='%n@%2m %~ $(get-git-branch) %# '

Comments Off

Key mappings in Zsh

Comments Off

Z-Shell is a powerful alternative to Bash, but some of the details can take time to get use to, and some things just have to be changed. For example, the key binding for cursor and other special keys. Using CTRL + arrow keys to skip words might give funny characters like “;5D” and “;5C” instead. As pointed out by Luke Wilde, these keys have to be set up manually. In my case, I had to include the semi-colon in the bindkey command as well.

These should go in ~/.zshrc.

bindkey ';5D' emacs-backward-word
bindkey ';5C' emacs-forward-word
 
export WORDCHARS=''

Only funny thing about setting it up like that, is that if the actual character sequence “;5D” is pasted into the terminal, it will be taken as if the CTRL+LEFT key was pressed. I’m not aware of a work-around for that.

The Zsh wiki lists a few other possible key bindings, including for the Home and End keys:

bindkey "${terminfo[khome]}" beginning-of-line
bindkey "${terminfo[kend]}" end-of-line

Comments Off

Multiplexed SSH sessions for quicker connection

Comments Off

If you need to open multiple SSH connections to the same host, it can get tedious to re-authenticate for every one. And even with public key authentication and no password, the extra channel eats a bit of bandwidth. The solution is multiplexed SSH sessions: Authenticate once, and the following connections to the same host goes over the same session. It’s dead easy to set up:

In your ~/.ssh/config file add the following lines. (Make sure that file has user permissions only, i.e. 600).

Host *
   ControlMaster auto
   ControlPath ~/.ssh/master-%r@%h:%p

It takes effect immediately. SSH twice to the same host to verify.

Comments Off

chroot to ARM

Comments Off

chroot allows you to “run a command or interactive shell with special root directory”, as the man page says. However, it is assumed that the second level root directory is built for the same CPU architecture. This causes a problem if you want to chroot into an ARM based image, for the Raspberry Pi, let’s say. qemu-arm-static, some “voodoo” and several tricks come to the rescue. The process is documented well at Sentry’s Tech Blog, and the original seems to be by Darrin Hodges.

After downloading and unzipping the image, it has to be mounted. There are a few ways to go about this, but I found the easiest was to use plain old mount with an offset. The typical RPi image file is a full disk image, as opposed to a single partition or ISO though. We are after the second partition, which in our case starts at sector 122880. (See this discussion for how to find the correct starting sector using fdisk).

mkdir /mnt/rpi
mount -o loop,offset=$(( 512 * 122880 )) 2014-01-07-wheezy-raspbian.img /mnt/rpi

Next we’ll copy a statically built QEMU binary for ARM to the mounted image. You might need to install QEMU on the host system first. Furthermore, we need to mount or bind the special system directories from the host to the chroot.

apt-get install qemu-user-static
cp /usr/bin/qemu-arm-static /mnt/rpi/usr/bin/

mount -o bind /dev /mnt/rpi/dev
mount -o bind /proc /mnt/rpi/proc
mount -o bind /sys /mnt/rpi/sys

Next comes the magic. This registers the ARM executable format with the QEMU static binary. Thus, the path to qemu-arm-static has to match where it is located on the host and slave systems (as far as I understand).

echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register

Finally, it’s time for the moment of truth:

chroot /mnt/rpi

uname -a
Linux hrb 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 armv7l GNU/Linux

In some cases, the error “qemu: uncaught target signal 4 (Illegal instruction) – core dumped” occurs. User kinsa notes here that the lines of the file ld.so.preload (i.e. on the slave, /mnt/rpi/etc/ld.so.preload) has to be commented out (with a # in front).

Congratulations, you now have an ARM based chroot. What to do with it? Maybe install a few “missing” packages before copying over to one or more SD cards, set up the users, modify passwords, etc. Or take advantage of the CPU and memory of the host system or compile from source.

apt-get install htop tree ipython ipython3 gnuplot

As a final note, when done, you want to clean up the mount points.

umount /mnt/rpi/dev
umount /mnt/rpi/proc
umount /mnt/rpi/sys
umount /mnt/rpi

Comments Off

Fedora 20 released

Comments Off

Fedora 20 was released a few days ago. J.A. Watson at ZDNet has a brief overview of the different desktops available, and concludes that for the most they run just fine on any hardware, including “sub-notebooks”. Furthermore, even though the “spin” of each desktop have specialised in their own applications, there are always plenty more to chose from in the main Fedora repositories.

The Anaconda installer was written back in release 18, and FedUp (FEDora UPgrader) is now the main system upgrade tool. It is not quite clear whether it is preferred to perform that on a running system though, as opposed to booting from an installer image.

Thus, the following links still apply, even for existing installations:

Comments Off

Building XBMC on the RPi

Comments Off

Some notes on building XBMC from source on the Raspberry Pi: I started with the Raspbian 2013-09-25-wheezy image from here. After basic setup, I switched to CLI only, set the GPU memory to 16 MB, logged in over SSH, and started a screen session. A remote session is preferred, since there will be a lot of coping back and forth between the RPi and your desktop.

For the most, I followed these instructions, with a few modifications: First, the boot files to set GPU memory are not there in the Raspbian distribution I had installed. Instead, I used raspi-config to set the memory split. Secondly, the large one-liner apt-get install of all the dev packages (step 4 in the instructions) did not work very well. It gave dependency conflicts with the mesa packages. I found myself splitting up that line into many chunks, which then worked fine. Finally, a few packages were missing, and I had to run configure several times to figure that out. In the end, I also installed these:

apt-get install dh-autoreconf gawk gperf zip ccache

For a successful build, I had to modify the search path of a header file. There are a few ways to go about that, as discussed here. I used this solution:

sudo sed -i 's/#include "vchost_config.h"/#include "linux\/vchost_config.h"/' /usr/include/interface/vmcs_host/vcgencmd.h

That took me as far as a working XBMC setup, however videos are not playing. With MPlayer there is no problem, but XBMC just gives a black screen. I will have to investigate further.

There’s a similar set of instructions here.

Comments Off

Firefox plug-ins and fixes

Comments Off

Firefox wants to be like Chrome. I’d rather just keep my old Firefox. Here’s the list of fixes to restore or remove some of their blunders:

Disable the “fancy” stuff. These settings can be reached from the special about:config page. I disable these

  • browser.tabs.animate
  • browser.tabs.insertRelatedAfterCurrent
  • keyword.enabled
  • browser.fixup.alternate.enabled

Then some plug-ins:

Comments Off

perceptualdiff – compare images perceptually

Comments Off

I recently found myself needing to compare bitmap images, to see if they were about the same. The images were from Gnuplot generate graphs, and I wanted to check whether subtle changes in the data had not introduced unexpected changed to the plot. A simple binary diff told me that there were indeed some differences, however, comparing them manually was not possible.

Enter the handy tool perceptualdiff, which lets you compare TIF and PNG images based on a perceptual metric. It actually goes beyond simple bitwise pixel diff, and tries to compare based on a model of the human visual system. Consider the examples below, and it is clear that it is a useful tool. It makes it easy to see where the small differences were introduced. (As it turns out, it is only the result of the two plots being generated on different machines, with different versions of Gnuplot and possibly also different available fonts).

The tool is in the Fedora repository, so a simple yum is enough:
yum install perceptualdiff

To generate an output diff image, this command does the job:
perceptualdiff -output diff.ppm image1.png image2.png

Comments Off

Fonts for Gnuplot

Comments Off

After struggling with fonts in Gnuplot 4.6 (on Fedora 17) (getting the not so useful error “gdImageStringFT: Could not find/open font while printing string”), I found tonicas post on debugging the issue. Although helpful, it did not give the full solution to my problem. It turns out, many of the old fonts are not available in Fedora 17 at all.

I wanted a sans-serif font, and in the end I went for the DejaVuSans. After installing the font packages, I specifically exported that path for use with Gnuplot:

sudo yum install dejavu-sans-fonts dejavu-fonts-common
 
export GDFONTPATH=/usr/share/fonts/dejavu

Then I can use that font in Gnuplot by addressing it specifically:

set title 'Test' font 'DejaVuSans,21'

Comments Off

Bodhi Linux on Nexus 7

2 comments

Bodhi Linux is a Debian based distribution using the Enlightenment Window Manager. They have taken the effort to make a Nexus 7 image (ARM HF), and have gone for the very simple approach seen by the Ubuntu folks: Simply flash the boot and userdata partitions, and you’re ready to go.

The images can be found here. (Notice, there are actually two different kinds; boot and root, with different versions of the later). After unpacking, it boils down to:
sudo fastboot erase boot
sudo fastboot erase userdata
sudo fastboot flash boot boot.img
sudo fastboot flash userdata rootfs.img
sudo fastboot reboot

With the Enlightenment WM, they have actually managed to come further towards a UI which suits a small touch screen (compared to the Ubuntu and KDE Plasma Active UIs). The top panel features large buttons, and overall the interaction feels snappy. Now, they have of course not managed to cover all the upstream applications, which is now the next frontier for all of these distributions.

As it is Debian based, is uses the the Debian repositories, and just like the Ubuntu ones, a lot of applications have already been cross-compiled to ARM HF (Hard Floating point). As a crude test, Eclipse-JDT installed and started up fine, While Libreoffice-Writer was missing a package. glxgears installs, but does not start; possibly a driver issue. USB OTG with a hub, keyboard and mouse works out of the box.

So far, this is the best alternative GNU/Linux based distribution for Nexus 7 I’ve tested. However, as mentioned before, these are still early days, and there will be a lot of work for both upstream application maintainers and distributions to create a great UI experience suited for a touch screen.

KDE Plasma Active for Nexus 7

Comments Off

On the heels of running Ubuntu on the Nexus 7, I thought I’d try KDE’s Mer based (partly derived from MeeGo) Plasma Active as well. As their documentation states: “Even though very much already works reasonably well, there are still some glitches. So, please don’t expect a 100% working system.” And it is indeed a bit more than small glitches which have to be fixed before it is a usable system.

Using Ruediger Gad instructions, I downloaded the boot and userdata images, and proceeded with the installation steps. Although not one-click like Ubuntu, it is reasonable straight forward, however, once it is time to boot the new OS, there are some problems: I only see a “dead” Android on its back with a red exclamation mark. (This is of course Google’s fault, who have hidden any useful information one might get a further clue from, and gone for a “IT for Dummies” mode). It seems Gad had anticipated some problems though, since he has provided a helpful fastboot command to load the boot image dynamically. This works, with the caveat that the MOSLO (MeeGo OS Loader) will go into a USB slave mode if a USB cable is detected. Therefore, I had to issue the fastboot command and then quickly jerk out the cable, and the OS would boot. (Skipping the MOSLO altogether failed to boot at all (Stuck on “Waiting for root device /dev/mmcblk0pX”)).

Once finally in the UI, I don’t seem to have the same luck as Gad. On the first try, even the most basic clicks and moves left the whole screen hanging for up to 30 seconds, and it failed to render the application icons seen on his blog. Trying to boot a second time, I got so far as to open the browser and terminal. Typing with the on-screen keyboard in the URL did not work, since it loses focus once another part of the screen is touched. Looking at dmesg in the terminal, I could see that my USB-OTG adapter, USB Hub, keyboard and mouse were detected correctly, however there seems to be drivers missing, since nothing happened when moving the mouse or typing. So yeah, some glitches, which hopefully will be ironed out in a new release.

What’s a bit more worrying, is the impression of the overall UI, and usefulness on a small touch screen. Just like the Ubuntu UI, Plasma Active is still stuck with a desktop centric view: Small icons and buttons, difficult to interact with. Setting up the Wifi dumped the user right in to an old desktop dialogue, complete with small text fields, and OK / Cancel buttons in the far bottom corner. This was probably the most disappointing bit, since I had expected the Plasma Active interface to be designed specifically for small touch screens. Clearly I was wrong.

Overall then, KDE Plasma Active is an interesting initiative, and one to watch in the future. However, just like Ubuntu, these are still very early days for new alternative OSes on tablets and phones. Given some more time, things will look a lot more promising, for sure.

Comments Off