Feeds:
Posts
Comments

Archive for the ‘linux’ Category

what is this?

for years i wanted to be able to change from a wireless setup to a wired one in a transparent fashion, that is:

  • without having to configure
  • without loosing active connections
  • with the ability to expand bandwidth when needed
but altough this seems to be a default on mac os x and maybe on windows vista+ (not sure for windows) it never worked on linux. this was probably caused by the fact: that i tried to use a bridge at first and wlan does not go well together with ethernet (kernel related limitiation; maybe MTU settings?).
i can’t remember why bonding failed last time i tried it (2years ago?) – maybe because of the used linux drivers?

how does it work?

OXIGEN ICON THEME Oxygen icon theme is dual licensed. You may copy it under the Creative Common Attribution-ShareAlike 3.0 License or the GNU Library General Public License.  i created this image; please feel free to use either of the above liceneses when using my composition of the image (nixos_bonding.png)

bond0/br0 abstraction

first read the manual at [1]. here is the sequence of actions i had to take:

rmmod bonding
modprobe bonding mode=active-backup miimon=100 primary=eth0
ifconfig bond0 up
ifenslave bond0 eth0 --verbose

since wlan drivers are somehow odd from time to time i usually prefer to shut wlan0 down:

ip l set wlan0 down

my first and failed attempt to to get wlan0 to bond0:

# ifenslave bond0 wlan0 --verbose
ifenslave.c:v1.1.0 (December 1, 2003)
o Donald Becker (becker@cesdis.gsfc.nasa.gov).
o Detach support added on 2000/10/02 by Willy Tarreau (willy at meta-x.org).
o 2.4 kernel support added on 2001/02/16 by Chad N. Tindel
 (ctindel at ieee dot org).
ABI ver is 2
current hardware address of master 'bond0' is 00:23:7d:00:ff:fe, type 1
Interface 'wlan0': flags set to 1002.
Interface 'wlan0': address cleared
Master 'bond0': Error: SIOCBONDENSLAVE failed: Operation not possible due to RF-kill
Master 'bond0': hardware address set to 00:23:7d:00:ff:fe.
Slave 'wlan0': MTU set to 1500.
Master 'bond0', Slave 'wlan0': Error: Enslave failed

so after disabling the RF-kill (i have a wlan rf-kill switch on the keyboard)

ifenslave bond0 wlan0

just to make sure all services work as expected, i restart them:

stop dhcpcd
dhcpcd bond0
stop wpa_supplicant
start wpa_supplicant
ip a
2: eth0:  mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
 link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
3: wlan0:  mtu 1500 qdisc mq master bond0 state UP qlen 1000
 link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
5: bond0:  mtu 1500 qdisc noqueue state UP
 link/ether 00:23:7d:00:ff:fe brd ff:ff:ff:ff:ff:ff
 inet 192.168.2.105/24 brd 192.168.2.255 scope global bond0
 inet6 fe80::223:7dff:fe00:6ec8/64 scope link
 valid_lft forever preferred_lft forever

note:

  • eth0/wlan0/bond0 all share the same mac address now
  • eth0/wlan contain tha SLAVE flag
  • all are in state UP
also note: i do not use wicd/network manager
# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=50 time=30.8 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=50 time=28.4 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=50 time=30.5 ms (here i unplug eth0)
64 bytes from 8.8.8.8: icmp_req=4 ttl=50 time=30.5 ms
64 bytes from 8.8.8.8: icmp_req=5 ttl=50 time=31.4 ms
64 bytes from 8.8.8.8: icmp_req=6 ttl=50 time=30.9 ms
64 bytes from 8.8.8.8: icmp_req=7 ttl=50 time=32.2 ms
^C
--- 8.8.8.8 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6008ms
rtt min/avg/max/mdev = 28.420/30.708/32.215/1.105 ms

i also did some bandwidth tests downloading a big file from my local samba server and it changed from slow when being on wlan to fast when plugging in the cable (took about 1-3 seconds)

the only problem so far:

  • konqueror won’t resolve smb://foobar/ to the smb://192.168.2.104 ip

this might be caused as i use the code below in my smb.conf, see [2]:

 server string = foobar
 netbios name = foobar

and netbios might have problems with this setup (but i doubt that, it is probably some konqueror related issue)

requirements

hope i covered all requirements:

  • the LAN and WLAN have to be bridged on the router, thus both have to be in the same collision domain (this means that both lan/wlan share the same ip range and devies bound to either can see each others MAC addresses)
  • i use wpa_supplicant and wpa2 encryption, so wpa_supplicant must work when using encryption
  • lspci showed:
    • 03:00.0 Network controller: Intel Corporation Ultimate N WiFi Link 5300
    • 00:19.0 Ethernet controller: Intel Corporation 82567LM Gigabit Network Connection (rev 03)
  • Linux eliteBook-8530w 3.2.20 #1 SMP Tue Jun 12 22:57:17 UTC 2012 x86_64 GNU/Linux
  • ifenslave.c: v1.1.0 (December 1, 2003)
    • it might make sense to call ifenslave with –verbose because only then one can see that

summary

i will make this a default setup for sure:

  • yet i need to package ifenslave as i can’t find it on nixpkgs
  • maybe bonding should be integrated similar to “networking.bridging”, see [3]
  • i wonder how wicd might be affected by bonding
anyway, to see this working at least is a good thing!

links

[1] http://www.kernel.org/doc/Documentation/networking/bonding.txt

[2] https://nixos.org/wiki/Samba_on_nix

Advertisements

Read Full Post »

svn & meld on nixos

a short ‘guide’ on how to use meld for merges in svn.

this has been discussed on many blogs but since i had this issue twice now and especially since svn changed the parameter list and therefore many pages describing this are thus wrong, here it is again. also nobody seems to implement the workflow i like, that is:

  • on the left side is the file to be edited
  • on the right side is the new version (this file is only important while merging)
workflow: what ~/.meld does is to give you MINE and THEIRS for merging into MINE (MINE is the left side document). after the merge it would copy the modified MINE over MERGED. and once the conflict is marked ‘resolved‘ all the different files will vanish and leave a working set of files.

.subversion/config

merge-tool-cmd = /root/.meld

/root/.meld

#!/bin/sh
### the specified command: base theirs mine merged wcfile
/nix/var/nix/profiles/default/bin/meld $3 $2
# this cp copies mine to merged
cp $3 $4
exit 0

afterwards don’t forget to make it executable & install meld of course:

chmod u+x .meld
nix-env -i meld

the merge:

svn up
Updating '.':
A pkgs/applications/misc/gnome_terminator
A pkgs/applications/misc/gnome_terminator/default.nix
U pkgs/applications/version-management/git-and-tools/svn2git-kde/default.nix
A pkgs/applications/graphics/zgrviewer
A pkgs/applications/graphics/zgrviewer/default.nix
U pkgs/applications/audio/audacious/default.nix
U pkgs/applications/audio/yoshimi/default.nix
U pkgs/lib/platforms.nix
G pkgs/top-level/all-packages.nix
U pkgs/top-level/haskell-defaults.nix

Conflict discovered in '/etc/nixos/nixpkgs/pkgs/top-level/python-packages.nix'.
Select: (p) postpone, (df) diff-full, (e) edit,
 (mc) mine-conflict, (tc) theirs-conflict,
 (s) show all options: <strong>l</strong>
  1. type ‘l‘ (like linux) on the keyboard
  2. on the left side is the file you want to patch, so make changes to the left side and save the document
  3. now close meld
  4. back on the shell, type ‘r‘ (for resolved)
  5. continue with other conflicts

Read Full Post »

what is this?

i recently upgraded my hetzner root server and therefore had a system with 2x3tb disks. as fdisk can’t be used to partition disks > 2tb i had to use gpt instead which was quite tricky until it was working. so here is my installation guide. parts of it applies also to other distributions.

this guide uses concepts from the hetzner wiki OpenBSD installation guide [1].

note:

  • gpt is used for both disks
  • there is no extra /boot partition (the system will directly boot from the lvm which is on top of the mdadm); this works since grub2
  • this setup is pretty similar to using fdisk (MBR) partitions
  • this guide still uses BIOS to boot (no EFI/UEFI)
  • /dev/sda1 and /dev/sdb1 are very small partitions (2Mib); they are used to store the grub2 boot stages, see [5]

disk layout

update: 26.5.2012: updated the image according to the swap comment from nbp. swap should not be in the lvm as it might degrade the performance.

the installation

first remove old partitions/mdadm setups

uninstall:

lvremove /dev/myvolgrp/home
lvremove /dev/myvolgrp/system
lvremove /dev/myvolgrp/swap
vgremove myvolgrp
pvremote /dev/md0
mdadm --stop /dev/md0
# to remove the md0 permanently
mdadm --zero-superblock /dev/sda1
mdadm --zero-superblock /dev/sdb1

creating the partitions

update 26.5.2012: also add the swap partition here (not done below!).

parted /dev/sda
mklabel gpt
mkpart non-fs 0 2
mkpart primary 2 3001G
p
Number Start End Size File system Name Flags
1 17.4kB 2000kB 1983kB non-fs
2 2097kB 3001GB 3001GB primary

set 1 bios_grub on
p
Number Start End Size File system Name Flags
1 17.4kB 2000kB 1983kB non-fs bios_grub
2 2097kB 3001GB 3001GB primary

creating the new mdadm softraid device

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

LVM+filesystems

pvcreate /dev/md0
Physical volume "/dev/md0" successfully created

vgcreate myVolGrp /dev/md0
Volume group "myVolGrp" successfully created

lvcreate -n system -L50G myVolGrp
lvcreate -n swap -L8G myVolGrp

mkfs.ext4 -O dir_index -j -L system /dev/myVolGrp/system
mkswap -L swap /dev/myVolGrp/swap

note: the disk layout diagram mentiones a tmp partition which happended to be added later 😉

using a virtual machine + vnc to boot the iso image

preparing the host system:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

on the hostsystem

#download latest console only 64bit nixos installer
nixos-minimal-0.1pre33860-33874-x86_64-linux.iso

make sure /dev/myVolGrp/system and /dev/myVolGrp/swap are not in use:

apt-get install sudo
qemu-system-x86_64 -enable-kvm -m 1024 -hda /dev/md0 -net nic -net tap -cdrom nixos-minimal-0.1pre33860-33874-x86_64-linux.iso -boot d -vnc localhost:0

note: in contrast to original article [1] i use ‘-enable-kvm’ which speeds things up!

from your homecomputer

execute this two commands (in two different shells):

ssh -L 5900:localhost:5900 root@176.9.99.117
vncviewer localhost

inside the qemu/kvm system via vncviewer

how we have to prepare install the system on the devices we had preparted in the steps before:

inside do:
login as root
mount -L system /mnt

cd /mnt
nixos-option --install
vi /etc/nixos/configuration.nix

stop dhcpcd
ip a add 172.2.0.2/16 dev eth0
ip r add via 172.2.0.1
echo "nameserver 8.8.8.8" > /etc/resolv.conf
# use ping www.google.de to verfy that the routing is working

# example url, configuration.nix is appended to this article
curl http://lastlog.de/configuration.nix
mv configuration.nix /mnt/etc/nixos/configuration.nix
# now the installation, make sure you read the nixos installation guide as well, but in short:
nixos-install
# only the grub2 installation should have failed (as there is no /dev/sda1 in the virtual machine!)
#finally we halt the system
halt

im hostsystem we need to install grub2:

apt-get install grub2
grub-install --no-floppy --root-directory=/mnt --recheck /dev/sda
Installation finished. No error reported.

grub-install --no-floppy --root-directory=/mnt --recheck /dev/sdb
Installation finished. No error reported.

# now we add a ssh key so we can login into this system later on
cd /mnt
mkdir root
cd root
mkdir .ssh
chown 0700 .ssh/
cd .ssh
echo "ssh-rsa AAAAB3Nz.....aU79sGVhyOPRz joachim@ebooK" > authorized_keys

from your homecomputer login into the installed system (reboot the host) and then issue this command:

ssh root@176.9.99.117 -i ~/.ssh/myprivatekey

after the first login, nixos-rebuild switch might fail with this error message:

nixos-rebuild switch --fast
building the system configuration...
updating GRUB 2 menu...
installing the GRUB bootloader on /dev/sda...
/nix/store/iaypdz5mm1qk8izs9412cb28v9vwwcn4-grub-1.99/sbin/grub-probe: error: no such disk.
Auto-detection of a filesystem of /dev/mapper/myVolGrp-system failed.
Try with --recheck.
If the problem persists please report this together with the output of "/nix/store/iaypdz5mm1qk8izs9412cb28v9vwwcn4-grub-1.99/sbin/grub-probe --device-map="/boot/grub/device.map" --target=fs -v /boot/grub" to
grub-probe --device-map="/boot/grub/device.map" --target=fs -v /boot/grub
grub-probe: info: Cannot stat `/dev/disk/by-id/scsi-35000c5003f556643', skipping.
grub-probe: info: Cannot stat `/dev/disk/by-id/scsi-35000c5003f5363a6', skipping.
grub-probe: info: changing current directory to /dev.
grub-probe: info: changing current directory to pts.
grub-probe: info: changing current directory to shm.
grub-probe: info: changing current directory to myVolGrp.
grub-probe: info: changing current directory to md.
grub-probe: info: changing current directory to disk.
grub-probe: info: changing current directory to by-label.
grub-probe: info: changing current directory to by-uuid.
grub-probe: info: changing current directory to by-partlabel.
grub-probe: info: changing current directory to by-partuuid.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to by-id.
grub-probe: info: changing current directory to snd.
grub-probe: info: changing current directory to mapper.
grub-probe: info: opening myVolGrp-system.
grub-probe: error: no such disk.

so what is inside this device.map anyway?

cd /boot/grub
cat device.map
(hd0) /dev/disk/by-id/scsi-35000c5003f556643
(hd1) /dev/disk/by-id/scsi-35000c5003f5363a6

Jordan_U#grub@irc.freenode.net recommended to remove the device.map. that made it work:

rm /boot/grub/device.map

summary

took quite some time to figure all this out so i guess someone else might have interested in this guide as well. i also tried to install, using EFI, but soon discovered that this might be a very complicated road to go and therefore skipped that.
it is cool to see that there is a very helpful community surrounding key projects required to get this installation done. i would have had to spend much more time if i wouldn’t have had someone to ask from time to time.

links

[1] http://wiki.hetzner.de/index.php/OpenBSD
[2] https://wiki.archlinux.de/title/Gpt
[3] https://wiki.archlinux.org/index.php/GRUB2#GPT_specific_instructions
[4] http://www.wensley.org.uk/gpt
[5] http://en.wikipedia.org/wiki/GNU_GRUB#GRUB_version_2

configuration.nix

# Edit this configuration file which defines what would be installed on the
# system. To Help while choosing option value, you can watch at the manual
# page of configuration.nix or at the last chapter of the manual available
# on the virtual console 8 (Alt+F8).

{config, pkgs, ...}:

{
require = [
# Include the configuration for part of your system which have been
# detected automatically.
./hardware-configuration.nix
];

boot.initrd.kernelModules = [
# Specify all kernel modules that are necessary for mounting the root
# file system.
#
# "ext4" "ata_piix"
"af_packet" "snd_pcm_oss" "snd_mixer_oss" "rtc_cmos" "rtc_core" "rtc_lib" "snd_hda_codec_via" "i915" "joydev" "drm_kms_helper" "snd_hda_intel" "rng_core" "drm" "snd_hda_codec" "thermal" "i2c_algo_bit" "button" "snd_hwdep" "intel_agp" "psmouse" "i2c_i801" "evdev" "snd_pcm" "video" "agpgart" "pcspkr" "serio_raw" "iTCO_wdt" "i2c_core" "snd_timer" "output" "e1000e" "snd" "soundcore" "snd_page_alloc" "sg" "loop" "ipv6" "kvm" "freq_table" "processor" "thermal_sys" "hwmon" "ext4" "mbcache" "jbd2" "crc16" "raid456" "async_pq" "async_xor" "xor" "async_memcpy" "async_raid6_recov" "raid6_pq" "async_tx" "md_mod" "sd_mod" "crc_t10dif" "sata_sil" "ata_piix" "dm_mod" "usb_storage" "usb_libusual" "usbhid" "hid" "ohci1394" "ieee1394" "ahci" "libata" "scsi_mod" "ehci_hcd" "uhci_hcd" "usbcore" "nls_base" "scsi_wait_scan" "unix"
];

boot.loader.grub = {
# Use grub 2 as boot loader.
enable = true;
version = 2;

# Define on which hard drive you want to install Grub.
devices = [ "/dev/sda" "/dev/sdb" ];
};
boot.extraKernelParams = [ "vga=normal" "nomodeset" ];

networking = {
hostName = "nix9000"; # Define your hostname.
# wireless.enable = true; # Enables Wireless.
};

# Add file system entries for each partition that you want to see mounted
# at boot time. You can add filesystems which are not mounted at boot by
# adding the noauto option.
fileSystems = [
# Mount the root file system
#
{ mountPoint = "/";
#device = "/dev/sda2";
label = "system";
}
#{ mountPoint = "/boot";
# label = "boot";
#}

# Copy & Paste & Uncomment & Modify to add any other file system.
#
# { mountPoint = "/data"; # where you want to mount the device
# device = "/dev/sdb"; # the device or the label of the device
# # label = "data";
# fsType = "ext3"; # the type of the partition.
# options = "data=journal";
# }
];

swapDevices = [
# List swap partitions that are mounted at boot time.
#
{ label = "swap"; }
];

# Select internationalisation properties.
# i18n = {
# consoleFont = "lat9w-16";
# consoleKeyMap = "us";
# defaultLocale = "en_US.UTF-8";
# };

# List services that you want to enable:

# Add an OpenSSH daemon.
services.openssh.enable = true;

# Add CUPS to print documents.
# services.printing.enable = true;

# Add XServer (default if you have used a graphical iso)
# services.xserver = {
# enable = true;
# layout = "us";
# xkbOptions = "eurosign:e";
# };

environment.systemPackages = with pkgs; [
zsh wget wgetpaste vimprobable2
];

# Add the NixOS Manual on virtual console 8
#services.nixosManual.showManual = true;
}

Read Full Post »

booting nixos from lvm on top of mdadm

what is this

since i might require such an setup more often i post it here, so i don’t forget it (see [1]).

this guide works great for fdisk+mdadm+LVM but it did not work for parted lately using ubuntu server. i don’t know why, maybe because of the raid controller?

in case someone removes the commands from the nixos wiki, here are the commands again:

  mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1

  pvcreate /dev/md0
  vgcreate myvolgrp /dev/md0
  lvcreate -L 1G -n boot myvolgrp
  lvcreate -L 5G -n system myvolgrp

  mkfs.ext4 -n boot /dev/myvolgrp/boot
  mkfs.ext4 -n system /dev/myvolgrp/system

  mount -L system /mnt
  nixos-option --install

  cat /etc/nixos/configuration.nix
  ...
    { mountPoint = "/";
      label="system";
    }
    { mountPoint = "/boot";
      label="boot";
    }
  nixos-install

advantages of this setup

  • no special partition required either something like /dev/sda1 or /dev/sdb1 where /boot would be placed on
  • LVM can be used for anything
  • still mdadm is below, which is a good thing
reminds me though that i should check if /etc/nixos/configuration.nix is capable of installing grub in several partitions already. usually it is only installed in /dev/sda given by this example:
   boot.loader.grub = {
    # Use grub 2 as boot loader.
    enable = true;
    version = 2;

    # Define on which hard drive you want to install Grub.
     device = "/dev/sda"; # here is only one partition given
  };

links

[1] https://nixos.org/wiki/Soft-RAID_mdadm_(/dev/md0),_LVM_(PVs,VGs,LVs)

[2] https://nixos.org/wiki/Encrypted_Root_on_NixOS

Read Full Post »

what is this?

i bought an UPS with two ports: serial and usb. and because i did not know much about the UPS (AEG – PROTECT HOME VA 600) i started to look at the communication protocol. turns out there are lots of good tools for serial line interception but nearly none for the usb stuff. sadly the driver i wrote isn’t needed at all as an email to the nut-ML revealed that this UPS uses the Q1 protocol which is already supported pretty well using the blazer_usb and blazer_ser module.

anyway it was pretty interesting to hack on NUT using debian and later nixos. so here is a guide how to log/analyze serial traffic and how to write a simulator for either side.

and not to forget: thanks to Arnaud Quette for his ups/nut support. there is also a brief nut setup introduction, see [1].

sniff serial port data between UPS and PC

  1. set serial settings to:
    – enable serial port
    – port number com 1 irq 4 io port 0x3f8
    – port mode: host device
    – port/file path: /tmp/interceptty
  2. maybe correct the permissions to /tmp/interceptty
  3. interceptty -s ‘ispeed 2400 ospeed 2400’ -l /dev/ttyS0 | tee mylog | interceptty-nicedump
  4. on the linux host:
    tail -F mylog | grep “<“
  5. start virtualbox vm with a windows xp installed
    note:
     ignore this virtualbox warning: “Ioctl failed for serial device ‘/tmp/interceptty’ (VERR_INVALID_PARAMETER). The device will not work properly.”. it works anyway, at least on my system (using ubuntu 10.10 with standard virtualbox).

using the virtual python UPS

  1. on the server side open /dev/remserialVM
    remserial -d -p 23000 -s “2400 raw” -l /dev/remserialVM /dev/ptmx 
  2. on the client side (same host), do:
    remserial -d -r 127.0.0.1 -p 23000 -s “2400 raw” -l /dev/remserialPY /dev/ptmx
  3. chmod 0777 /dev/remser*
  4. change the virtualbox serial settings:
    – port mode: host device
    – port/file path: /dev/remserialVM
  5. then format a ‘message’ with a hexeditor also called “hexeditor”
  6. start the vm
  7. then send the formated message:
    cat message > /dev/remserialPY
  8. if the message was received by the windows ups monitoring software (it will think that the message it received originated from the UPS and not that it was crafted manually)
note: instead of manually sending messages, i also used the script: ./simulate-ups.py which does that automatically.
note: simulate-ups-monitor.py can be used in an analog way but simply using the ups with a real serial port. i should mention btw, that i was using both a usb2serial adapter and an old computer which still contains one of those ancient serial ports.

simulate-ups.py

#!/usr/bin/python
import serial
ser = serial.Serial('/dev/remserialPY', 2400)

line = ''
count=0

def process_command(cmd):
        print " < incomming: " + cmd
        if cmd == "Q1":
                print "REQUEST FOR DATA FROM USV"
                n = ("20").decode("hex")
                d = ("0d").decode("hex")
                a = ("28").decode("hex") + \
                    "000.0" + n + \
                    "000.0" + n + \
                    "000.5" + n + \
                    "005" + n + \
                    "00.0" + n + \
                    "00.6" + n + \
                    "25.0" + n + \
                    "00000001" + d
                ser.write(a)

while True:
        ch = ser.read(1)
        if ch == "\x0d":
                process_command(line)
                line = ''
        else:
                line = line + ch

simulate-ups-monitor.py

#!/usr/bin/python
import serial
import re
import time
import sys

ser = serial.Serial('/dev/ttyS0', 2400)
#, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 0)

line = ''
count=0
status="unknown"

def write(cmd):
        #print "sending " + cmd;
        ser.write(cmd)

def print_status(status):
                print "status is: Unknown|LostCom|Normal|ScheduledShutdown|60SecsShutdown|ActiveShutdown|CriticalPowerFail: " + status

def process_command(cmd):
        valid = re.compile(r"\([0-9][0-9][0-9].[0-9] [0-9][0-9][0-9].[0-9] [0-9][0-9][0-9].[0-9] [0-9][0-9][0-9] [0-9][0-9].[0-9] [0-9][0-9].[0-9] [0-9][0-9].[0-9] [01][01][01][01][01][01][01][01]")
        if valid.match(cmd):
                #print status + " : VALID REPLY FROM USV   ->    " + cmd
                #(239.5 239.5 235.6 000 49.9 13.6 25.0 00001001
                netz_eingang=cmd.split(' ')[0].lstrip('(')
                netz_unknown=cmd.split(' ')[1]
                netz_ausgang=cmd.split(' ')[2]
                percent=cmd.split(' ')[3]
                hz=cmd.split(' ')[4]
                bat_voltage=cmd.split(' ')[5]
                temperature=cmd.split(' ')[6]
                bits=cmd.split(' ')[7]
                bit1=bits[0]
                bit2=bits[1]
                bit3=bits[2]
                bit4=bits[3]
                bit5=bits[4]
                bit6=bits[5]
                bit7=bits[6]
                bit8=bits[7]
                print status + " " + cmd
        else:
                print "invalid reply detected: " + cmd
                sys.exit(1)

write( ("51310d").decode("hex"))

while True:
        ch = ser.read(1)
        if ch == "\x0d":
                process_command(line)
                time.sleep(1)
                write( ("51310d").decode("hex"))
                line = ''
        else:
                line = line + ch

simulate the UPS monitor

# ./simulate-ups-monitor.py
VALID REPLY FROM USV -> (241.5 241.4 237.5 000 49.9 13.5 25.0 00001001
VALID REPLY FROM USV -> (241.5 241.4 237.5 000 49.9 13.5 25.0 00001001
VALID REPLY FROM USV -> (241.4 241.4 237.5 000 49.9 13.5 25.0 00001001

summary

so would i buy a AEG Protect Home VA 600 again? currently there is no ‘time left’ estimation and therefore i shutdown the system either after 25 seconds or on LB (low battery) but after reloading the batteries the shutdown usually is triggered by the 25 seconds rule after a state change to OB (on battery). i think this is a decent setup and therefore i would probably buy that UPS again. but i don’t really have a clue about UPS devices so there might be much better ones in the same price range, maybe someone on the NUT/UPS ML can make a better recommendation.

what i really dislike is that this product ships with linux support BUT not with NUT support. i later realized that they created their own linux software. what a waste of time, i would rather love to get the specification and then use NUT instead – probably this is the case for nearly all the users seeing that this devices has linux support. but my request to get the specification was simply ignored, so i think there are better vendors out there.

another interesting aspect of nut is how complex the integration in the system is.

links

[1] https://nixos.org/wiki/How_to_setup_UPS/NUT

Read Full Post »

i’ve just finished a wiki page on how to develop arbitrary software on nixos [1] (thanks to viric!). as this is fundamentally different to all other linux and non linux operating systems i think this is worth a posting about this subject in my blog.

the interesting aspect is that nix/nixos provides such a development environment per project so one is not forced to pollute the system environment with the ongoing changes which always lead to horrible side effects as regression (you know when old habits stop working as a tiny update of libX breaks tool Z).

the way it is used is covered by [1] already.

a slightly more complex example

config.nix

     1  {
     2    packageOverrides = pkgs : with pkgs; rec {
     3      # example environment from viric
     4      sdlEnv = pkgs.myEnvFun {
     5        name = "sdl";
     6        buildInputs = [ stdenv doxygen SDL SDL_image SDL_ttf SDL_gfx cmake SDL_net pkgconfig ];
     7      };
     8
     9      # a custom library NOT included in nixpkgs (maybe later it is but assume for this example it is not)
    10      libnoise = callPackage ./libnoise.nix {};
    11
    12      # this is the needed environment for development of my spring random map generator
    13      # type 'load-srmg-env' to load it after installing it using 'nix-env -i env-srmg'
    14      srmgEnv = pkgs.myEnvFun {
    15        name = "srmg";
    16        buildInputs = [ stdenv doxygen cmake libnoise qt4 ];
    17      };
    18    };
    19  }

in the ~/.nixpkgs/config.nix expression i added a custom library which is then available with nix-env, this way it can be installed using (nix-env -i libnoise).

the interesting point is that line 2 contains the rec keyword indicating that all 3 attributes in the attribute set (line 2 to 18) may recursively reference each other. this is required as the the srmgEnv on line 14 where the buildInputs lists libnoise.

the libnoise expression is outsourced (line 10) into the file libnoise.nix (listed below).

libnoise.nix

     1  {stdenv, doxygen, fetchgit, cmake}:
     2
     3  stdenv.mkDerivation rec {
     4    name = "libnoise-1.0.0";
     5
     6    # i also change bits in the library and therefore i like to have it local
     7    # in case i change anything this needs to be done to reflect the change
     8    # 1. make the change 
     9    # 2. use 'git add file_which_has_changed'
    10    # 3. use 'git commit'
    11    # 4. use 'git log' to find the most recent rev
    12    # 5. paste the copied rev in the rev field below
    13    # 6. reinstall the libnoise 
    14    src = fetchgit {
    15      url = /home/joachim/Desktop/projects/libnoise;
    16      rev = "8b5b89b7241a112dfe0b387f7589ea9a2df00b02";
    17      sha256 = "";
    18    };
    19
    20    buildInputs = [ cmake doxygen ];
    21
    22    meta = {
    23      description = "libnoise";
    24      homepage = "http://www.github.com/qknight/libnoise";
    25      license = "LGPL2";
    26      maintainers = with stdenv.lib.maintainers; [qknight];
    27    };
    28  }
    29

the libnoise.nix file is interesting as it references a local git repository. it also lists what to do in order to alter the package.

once the srmg-env is installed (nix-env -i env-srmg) it can be used using: load-srmg-env. as mentioned in [1] this environment will then behave as if one had used ubuntu linux and then installed all the required libraryies.

future

as i noted in [1] nix will soon get a toggle (nix-build –run-env ‘<nixpkgs>’ -A xterm, see [2]) which will clone the environment of virtually any sourceScription on the system. this means one can hack on any software easily by injecting code into the build chain on an arbitrary position – still, this changes won’t be persistent, meaning:

  • after reinstallation of the sourceScription the former version will be installed
  • the environment will not last a reboot of the system (not 100% sure about this)

still it is one step towards the concept of the midstream platform (mentioned in my diploma thesis) and is a great way to test a quick hack.

update: 23.5.2012

another interesting potential property is that tools like kdevelop could be patched to automatically see all the include paths of a complete project and therefore are able to provide automatic code completion without having too much manual effort.

 

kdevelop can do that already! when importing the project’s ‘CMakeLists.txt’, kdevelop reads the ‘found’ entries and therefore collects all the library paths!

links

[1] https://nixos.org/wiki/Howto_develop_software_on_nixos

[2] https://github.com/NixOS/nix/commit/7f38087f35e6f74a73bfdb28da8acd8930565d51

Read Full Post »

n900 findings

315px-Nokia_N900-1repairing the n900 camera

i own a nokia n900 and i’m very happy with it. some time ago it fell of my pocket and then the 5mega pixel camera didn’t work anymore as well as the flashlight. i’m a big fan of QR codes and i was often using the flashlight so this was a problem.

the funny thing is that reflashing the device [2] made it work again. now i wonder why the camera is working again. the camera module is plugged to the n900 as can be seen in the videos on youtube, just search for it [3]. maybe while hitting the ground the camera was disconnected from the device while the device was running and that screwed the firmware? i don’t have a clue but i think it is worth mentioning.

0. symptoms

once the camera was not working i had problems:

  • starting the n900 (coldstart) if still connected to any charger, it simply would not boot
  • starting the camera application; it would report something like: camera device not ready or something similar and instantly close the widget
  • flashlight did not work anymore

1. the backup

1.1 create a backup using the backup tool coming with the n900

this is a really great tool, don’t forget to check all the 4 points in the list ‘what to backup’.

also consider to read [4] (i didn’t do that but on this page there are some screenshots of the backup util i’m referring to).

1.2 dpkg and a list of all files in ‘opt’

maybe that is of use later so i note down all files and installed packages:

ls -la opt > opt_fils

dpkg -l > dpkg_l

1.3 now make a backup of all files

as i also develop for the n900 i had already a working ssh root login:

rsync -av –progress –delete n900:/home/user .

2. eMMC/VANILLA

RX-51_2009SE_10.2010.13-2.VANILLA_PR_EMMC_MR0_ARM.bin

./flasher-3.5 -F ../RX-51_2009SE_10.2010.13-2.VANILLA_PR_EMMC_MR0_ARM.bin -f

3. FIASCO/Rootfs

RX-51_2009SE_20.2010.36-2_PR_COMBINED_MR0_ARM.bin

./flasher-3.5 -F ../RX-51_2009SE_20.2010.36-2_PR_COMBINED_MR0_ARM.bin -f -R

4. restoring the backup

once the device was booted after the udpate the camera was working. what a relief! but i didn’t know where to copy the backup as the folder using the ‘mass storage usb’ feature was nearly empty. so i created a new one and connected it again using usb later. after the backup directory was migrated to the device i disconnected the usb cable and restored my 50mb backup. took quite some time and after the final reboot the device also installs the software which was removed in step 2 and 3. i decided to skip this and to install only needed software manually.

note: after the backup is restored and the n900 restarted the wlan starts working again.

5. restoring the applications

a list of software i installed:

  • gainroot
  • openssh client and server
one these applications are installed plug in the usb adapter and set the device into ‘pc suite mode’ and use gainroot to type:
ifconfig usb0 10.0.0.1/24 up
on the host computer type:
ip a add 10.0.0.2/24 dev usb0
ip l set usb0 up
ssh root@10.0.0.1
to find applications use the app catalog on the n900 but to find the associated package i did:
apt-cache search adblock | grep plus
(and similar commands)
all other applications can be installed using apt-get via usb or wlan:
  • rsync
  • adblock plus
  • adflashblock-css
  • agenda timer
  • battery-eye
  • countdown timer
  • datetoday home desktop widget
  • evopedia
  • flashlight
  • convert
  • gpsjinni
  • headphone daemon
  • healthcheck
  • htop
  • iptraf
  • irssi
  • mad-developer
  • mappero
  • mbarcode
  • mbarcode qr code plugin
  • mbarcode webrequest plugin
  • mbarcode wifi plugin
  • mclock
  • mstardict
  • nmap
  • ogg support
  • orrery
  • password safe
  • personal ip address
  • quicknote
  • recaller
  • tuner
  • view contact info with bigger font
  • wifieye
  • wifi switcher
  • foreca weather applet
using the ssh shell one can type this on the device as root:

apt-get install adblock-plus-1.0
apt-get install adflashblock-css agenda rsync
apt-get install battery-eye wifi-switcher countdowntimer datetoday-home-widget evopedia flashlight-applet
apt-get install gpsjinni headphoned healthcheck htop network-monitor irssi mad-developer
apt-get install maemo-mapper mbarcode-plugin-qrcode mbarcode-plugin-wifi mbarcode-plugin-webrequest mbarcode mbarcode-core
apt-get install mclock mstardict nmap ogg-support decoders-support orrery pwsafe
apt-get install personal-ip-address quicknote recaller tuner contact-zoom wifieye foreca-weather-applet

other software i newly installed
  • monav
  • snuggle
  • wallet
  • mdbus2
again – using the ssh shell one can type this on the device as root:

apt-get install monav-routing-daemon snuggle qtwallet mdbus2

6. remove the photo click sound and the intro animation

ssh into the n900 and type:

rm ./opt/usr/share/hildon-welcome/media/Hands-v32-h264.avi ./home/opt/usr/share/hildon-welcome/media/Hands-v32-h264.avi

rm /usr/share/sounds/camera_snd_title_*wav

reboot

random notes

  • after the reinstallation everything is much faster now. the settings dialog loads twice as fast and the desktop feels much smoother.
  • application load times are similar to before
  • for some programs i had to copy files from my backup to the device manually:
    • my documents
    • evopedia dumps
    • monav map data
    • my camera pictures
    • osm2go
    • mstardict
    • music
    • quicknote
  • monav is probably one of the coolest programs for the n900, thanks very much to Christian Vetter and Christoph Eckert

links

[1] http://maemo.cloud-7.de/Gallery-N900-exploded/

[2] https://wiki.maemo.org/Updating_the_tablet_firmware#Updating_.26_Flashing_your_device

[3] http://www.google.de/search?q=Nokia+N900+Disassemble&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de:official&client=firefox-a

[4] http://prokonsul.blogspot.com/2011/01/make-backup-and-restore-from-it-on-n900.html

[5] http://natisbad.org/N900/n900-commented-hardware-specs.html

Read Full Post »

Older Posts »