Tuesday, November 13, 2012

qemu init scirpt for gentoo

It's over a year ago since i've posted a gentoo init script for qemu guests. Privately i've updated and added features regularly. Now i've uploaded an updated version which has lots of changes and an easier configuration file.

The most notable changes/features are:
  • per default i'm using now the qxl video card for guests
  • for many options there are default's which the init-script would use if there are no settings
  • guests don't have to run as root, you can specify an different user
  • spice support (you can choose between vnc and spice)
  • qemu guest agent support (qga has to be installed in the guest)
  • snapshot mode, guests can run in an snapshot-mode where changes won't be saved.

init script start and stop
The script needs following packages to work:
  • app-emulation/qemu
  • sys-apps/coreutils
  • sys-apps/net-tools
  • sys-apps/grep
  • sys-apps/iproute2
  • sys-process/procps
  • net-misc/bridge-utils
  • net-analyzer/netcat6
Download the script: Link

Basically most of these packages should be already installed on any system. However, you must configure an bridge first otherwise networking wouldn't work. To install the script there are just a few steps to do. First, extract the file:
 tar xzf qemu-init-script.tar.gz -C /etc/init.d/  

Move the default.config to /etc/conf.d/:
 mv /etc/init.d/kvm.config /etc/conf.d/  

For every guest you have to create an symlink to the init script (example for a guest called windows7):
 cd /etc/init.d/  
 ln -s kvm.init kvm.windows7  

You also have to create an new config file for this windows7 guest:
 cd /etc/conf.d/  
 cp kvm.default kvm.windows7  

Afterwards you have to edit the config to your needs. Basically you must change at least VM_IMAGE and BRDEV. BRDEV is the name of your bridge and VM_IMAGE is the path to the image file or lvm2 partition.
For an new guest you also have to change the boot settings. VM_BOOT_DEV sets how to boot (network/disk/cdrom/floppy), while VM_CDROM should point to an iso file or a cd.
The rest of the config should be quite self explaining. Anyway, i've tried to explain all variables as good as possible.

Thursday, November 8, 2012

qemu lvm2 vs qcow2 benchmark

Playing around with virtual guests always takes quite some time when creating or copying images. Recently i've started looking for a good solution how to store virtual guests. I always vacillate between lvm2 partitions and qcow2 files. Both have their pros and cons. LVM2 is fast and you have the ability for live snapshots while qcow2 files are easy to maintain and and need less space.
Some time ago i already  started an benchmark where i compared the different cache settings on different filesystems + lvm. The result was the there wasn't a big gap between those filesystems and lvm2, though comparing build times isn't a real benchmark.
VM Details

Now i made another benchmark. This time i choose to use the phoronix-test-suite benchmark tool to see what's the difference between qcow2 on btrfs and lvm2. PTS has many good present for testing and i just used an default disk benchmark present. The vm was an typical minimal gentoo amd64 system where i also didn't had X or anything else running, so the result should be quite accurate. I choose to test it with btrfs because it also has an snapshoting feature which might be an alternative to lvm2 one day.

Converting an lvm2 image to qcow2 is pretty simple and is done via:
 qemu-img convert -O qcow2 /dev/vg/g64 /mnt/vms/g64.qcow2  

Below are the result. I was quite surprised because i though using lvm2 has an greater impact on performance. However, as you can see, at a few benchmarks qcow2 were even faster than lvm2.


green = lvm2red = qcow2

For me the biggest drawback of qcow2 and other file formats right now is the lack of an snapshot feature which i could use for creating live backups while the system is running. Even though qemu has an snapshot feature, this one isn't working for me.
I might have an deeper look into qemu's snapshot feature in the future, but for now i'll stay with lvm2. Disk space isn't a real problem and other than that i don't want to rewrite my backup scripts (again).

Monday, August 27, 2012

qemu-kvm spice features


Spice is one of my favorite playgrounds for a long time. Even though it doesn't have lots of features (yet) it's already quite stable and while things like clipboard sharing and window re-sizing are not new, they are new to me.
Recently iv'e started to try out those features, especially clipboard sharing is something which i really wanted to have.

Host settings:
Basically it's pretty simple. First, you'll need to add following to your start command of qemu-kvm:
 -device virtio-serial -chardev spicevmc,id=vdagent,name=vdagent -device virtserialport,chardev=vdagent,name=com.redhat.spice.0  

Guest settings:
Secondly, it's really important that you enable the consolekit useflag for your window manager (except windows clients). In order that other programs can use it too i enabled it system-wide in make.conf.
Furthermore you have to install the spice vdagent. There is a package in gentoo (app-emulation/spice-vdagent) which does the job.
 emerge -av spice-vdagent  

Afterwards you just have to start the said agent with:
 /etc/init.d/spice-vdagent start  
 rc-update add spice-vdagent default  

Usually you don't have to change anything in the config of the agent as long as you don't change anything at the start command.
However, depending on your Window Manager it can happen that the spice vdagent doesn't work.

So far i found out that it doesn't work with awesome. Xfce, lxde, gnome, kde, razorqt and even windows 7 (with the corresponding driver) are working flawless. I think the reasons is consolekit. The window manager has to be build with consolekit support, otherwise the agent would be useless.

Monday, August 13, 2012

kde unable to mount usb sticks

ck-list-session shows my session as inactive

Recently i could fix another problem on my system which i had since i set it up. I wasn't able to mount usb-sticks. I always got the messages: Not authorized, and since i had no knowledge about udisks i had to look again how to fix it. I was surprised how long i could live without mounting usb sticks.


Basically mounting devices should work without any special configuration changes but my system had a difference compared with other systems. I didn't use an login-manager like kdm. I'm used to go into kde with the startx command. Because of that my session wasn't active and therefore udisks didn't allowed me to mount devices.
The change was simple and was done in:
 /usr/share/polkit-1/actions/org.freedesktop.udisks.policy  

In the section "Mount a device" i had to change a "no" into "yes" in the line "allow_inactive":
  <action id="org.freedesktop.udisks.filesystem-mount">  
   <description>Mount a device</description>  
   <message>Authentication is required to mount the device</message>  
   <defaults>  
    <allow_any>no</allow_any>  
    <allow_inactive>yes</allow_inactive>  
    <allow_active>yes</allow_active>  
   </defaults>  
  </action>  

Easy fix and now i'm able to mount usb-stick's again :)

Thursday, August 9, 2012

gentoo/xen part two

For some time now kernel 3.5 is out. I tested many rc's with xen and i also encountered quite a few problems. Mostly kernel panics. I found the rc5 the most stable of the rc's. Now i'm using the official gentoo unstable version and so far i didn't get any kernel panics.


Windows:
My ATI card with the latest drivers

I had some time now to test and since i like to game i really test alot. Besides that there was the steam summer sale, which means i have now 50+ games. I finished playing Half-Life, Half-Life 2, Episode One, Episode Two and Tomb Raider: Legend.

Now i'm playing Borderlands with my brother in coop mode. I also tried games like Spec Ops: The Line, Diablo 3, Team Fortress 2, L4D2, Tera, Dead Island, RFIT, Unreal Tournament and  Need for Speed: Hot Pursuit 2.
All of them running fluently with mostly max details on. Windows itself also runs without problems. No single BSOD or anything else:

  • Driver update in Windows for the graphic card worked perfectly.
  • However, turning off windows and starting again still don't work with xen-4.2. I still have to reboot the whole system.
  • Another detail worth to mention is, when i played Rift, every time i played i had to unlock my account, because it though i played from a new PC. Steam on the other side don't have any problems.

Linux:

On the linux side it's bit differently. I had problems, but mainly with the kernel which i can't judge since i always tried unstable release candidates which are known to have bugs. After all, the final gentoo 3.5 kernel works again perfectly.

Udev on the other side still makes me headaches. Right now i stuck with udev-182-r3 which is not even in portage anymore. Once i update to a newer version, xen won't start any guest anymore. I think it's because of broken udev rules which is described here. I didn't test that much yet but i have holiday now and hope i can find a solution.

Besides some kernel panic's with rc's and the udev thing there aren't any bugs to report. Other updates didn't influence xen at all, even though i'm on ~amd64 and update the system at least once a week.

Gentoo and kde working flawless and fluently. Though i can see that kde responses a bit faster when i start linux without xen, but that's not noteworthy.
xl dmesg

I've also upgraded to gcc-4.6 and xen-4.2. GCC-4.6 didn't change anything particular within xen, while with xen-4.2 i could finally try out gfx_passthrough in the config. However i couldn't get it to work, even though i don't get any error messages too. With xen-4.2 there are also alot of new function in the xl toolstack. I also found a nice solution to turn off the guest from the linux system:
xl shutdown -F 1

The number is the xen-id of the guest system. The "-F" means it sends an ACPI power event. While this isn't something particular new it's nice to know.

Another change i made in my win7x64.cfg:
 # This gives the vm exclusive access to the 4,5,6 and 7 cpu.  
 cpus=['4','5','6','7']


Future:

While kernel 3.5 seems to be a good kernel, 3.6 will be another one worth to try out. If you reading the blog post at xen, 3.6 will get some nice performance improvements. Guess this time i'll wait until the final kernel get released :)
I'm also looking forward too steam for linux. Even though xen is working quite good, native playing games on linux would be awesome.

Finally i'm showing you another demonstration video while playing borderlands. This time in a better quality. Hope you'll like it.

Tuesday, August 7, 2012

lightdm greeter selection

Lightdm is a new lightweight display manager which can replace kdm or gdm and also brings greeters for both of them.
Recently i've tried that new display manager on a virtual machine. There is a nice wiki entry at wiki.gentoo.org which helped me installing lightdm. Unfortunately i failed which was because lightdm always started the gtk+ version.
When i forced the kde version, lightdm crashed. That was because of that issue.

After all, at the wiki there is a important configuration possibility missing. It's not shown how to change the greeter in the configuration file.
That is done with following statement in lightdm.conf:
 greeter-session=lightdm-kde-greeter  

lightdm-kde-greeter would start the qt/kde greeter, while lightdm-gtk-greeter would start the gtk version. For both you have to download the corresponding packages first. I mentioned that at the irc channel and i hope they add that.

Monday, August 6, 2012

kdesu won't start apps in superuser mode

For a long time i had a really annoying bug in kde. This weekend i updated to kde-4.9 and found out that it's still present. The problem was when you press ALT+F2 and type "kdesu systemsettings" (or another program) the password prompt showed up but than nothing happen. I found a few topics about this, most notably here and here.

I had some time and since i could reproduce this problem in my virtual machines too i've started to track down the problem.
After a few hours of searching i finally found it. The reason was because dbus wasn't build with the useflag X enabled.
Adding the X useflag to dbus solved the problem.
 echo "sys-apps/dbus X" >> /etc/portage/package.use  

After creating a bug report on bugs.gentoo.org devs also mentioned that if you're using a desktop/kde profile you shouldn't hit the problem because there dbus would be build with X enabled anyway.
I never though about that but it's true, i'm using a default amd64 profile. The desktop/kde profile do enable to much for me.
Anyway, i also found another issue. ligthdm-kde also need dbus with X enabled otherwise it wont start.

Friday, June 15, 2012

gaming on gentoo/linux via xen


xen - a hypervisor who is one of many hardware virtualization techniques which allows running concurrently guests on a host system. One of the special key features of xen is vga passthrough which allows a guest to have full access to a pci device.
When i bought my new PC i wanted to use that feature because i missed gaming on the PC and since i don't wanted to reboot every time i decided to setup a windows 7 guest with a passthroughed graphic card.
In this post i'll gonna explain my setup and show what i have done to get it work.

My problem was easy to describe. I wanted gaming. Wine was an opinion, but i don't wanted to "frikle" around to get games working and multiboot was a no-go. Even though boot times are already pretty fast i wanted to have linux running all the time. This brought me to xen...

linux and windows side by side

1) Setup

First, my hardware setup and how it should work.
I have a an 8core amd processor with 16GB ram and two graphic cards. 4cores, 8GB ram and the high end graphic card is solely for the virtualized windows. That's enough power to run most new games without problems. (aside of linux)
Both graphic cards are connected to my 30" monitor and with the input key on the monitor i can switch between windows and linux.
The linux graphic card has two more 22" screens on the left and right of the 30".

2) Installation

2.1 System:
First i made a typical gentoo installation. It's ~amd64 keyworded, means it's more or less bloody edge. I even have a few 9999 packages installed like mesa, libdrm, xorg-server, etc but that shouldn't have any influence on xen.

make.conf:
 CFLAGS="-O2 -pipe -fomit-frame-pointer -mcx16 -msahf -maes -mpclmul -mpopcnt -mabm -mlwp -mavx -march=native"  
 CXXFLAGS="${CFLAGS}"  
 CHOST="x86_64-pc-linux-gnu"  
 MAKEOPTS="-j14"  
 ACCEPT_KEYWORDS="~amd64"  

With gcc-4.6 i'll add "-march=bdver1 -mtune=bdver1" to CFLAGS for enabling all possible features of the new bulldozer cpu.

Another change was to create a second runlevel especially for xen. I already bloged about it so you can read the small howto here: Link

2.2 Network:
I created a bridge so that xen can create tap devices for the virtual guest. A good howto for creating bridges can be found here: Link

2.3 Xen:
Really important is to have a multilib profile on gentoo, otherwise you couldn't set the "hvm" flag on xen-tools which is required for the amd-v processor feature. (i had to install gentoo a second time because of this)
The installation of xen was really smooth. I enabled following flags, where at least the "hvm" flag is really important.

xen flags:
 pp-emulation/xen-tools hvm qemu screen  

I also tried out xen from git because it has lots of vga passthrough patches, but since i couldn't start any virtual machine with the git version, i switched back to the latest version in portage. The git version of xen can be found in the virtualization overlay.

2.4 Kernel:
On the kernel side i compiled almost everything which has to do with xen directly into the kernel. I choose to use the latest git-sources so that i have all the latest features. I'll provide my configuration here for those who are interested: Download

2.5 Grub:
Grub also needed a new entry for xen which looks like this:
 title Gentoo Linux XEN  
 root (hd0,0)  
 kernel /boot/xen.gz dom0_mem=8192M,max:8192M iommu=1 xsave=1 dom0_max_vcpus=4 dom0_vcpus_pin                                                                          
 module /boot/gentoo-3.4.0-rc6 root=/dev/md3 softlevel=xen xen-pciback.permissive xen-pciback.hide=(01:00.0)(01:00.1)(00:12.0)(00:12.2) pci=resource_aligment=01:00.0,01:00.1,00:12.0,00:12.2  

Below the descriptions about this configuration. Dom0 is the host system, all systems which are virtualized are domU's

dom0_mem=8192M = the host system get's 8GB Ram...
,max:8192M = and can't have more than 8GB
iommu=1 = turn iommu on
xsave=1 = don't know exactly what it does, but it was need to prevent a bug with avx, see here: LInk
dom0_max_vcpus=4 = the host system get's 4 cpu's
dom0_vcpus_pin = it pin's the first 4 core's solely for the host
softlevel=xen = see here
xen-pciback.permissive xen-pciback.hide=(01:00.0)(01:00.1)(00:12.0)(00:12.2) pci=resource_aligment=01:00.0,01:00.1,00:12.0,00:12.2 = this is actually for pci(vga) passthrough. The bus number of you're graphic card and/or your usb bus from lspci can be found with lspci. It hide's the first pci device - the hd7970 (01:00.0 & 01:00.1) and one usb bus (00:12.0 & 00:12.2) which i also passthroughed to the guest. Note, you always have to hide everything on a single bus e.g. 01:00.0 & 01:00.1 and not just 01:00.0

3) Windows 7

3.1 Installation:
The installation of Windows 7 went really smooth. First i've created an 30GB empty image with dd:
 dd if=/dev/zero of=win7_64 bs=1M count=30000  

Then i've wrote a config file for xen:
 name='win7x64'  
 builder='/usr/lib/xen/boot/hvmloader'  
 builder='hvm'  
 vcpus='4'  
 cpus='4-7'  
 memory='6144'  
 on_poweroff='destroy'  
 on_reboot='restart'  
 on_crash='destroy'  
 disk=['file:/home/michael/xen/win7x64s.img,hda,w','file:/home/michael/xen/win7.iso,hdc:cdrom,r']  
 vif=['bridge=br0,type=ioemu']  
 boot='c'  
 acpi=1  
 apic=1  
 viridian=1  
 stdvga=0  
 vnc=1  
 vnclisten='0.0.0.0'  
 vncdisplay=0  
 vncunused=1  
 vncpasswd=""  
 sdl=0  
 pci=['01:00.0','01:00.1','00:12.0','00:12.2']   
Download this config: Download

The last line is important, because this one says which pci buses are gonna be passthroughed to the guest. I also enabled vnc, so that i can connect to the system with krdc which was important while installing windows.
"disk" is the option where you point to the image and also to the iso of the windows7 dvd. A better explanation of all options can be found here: Link and as PDF

Note:
It's important not to turn on gfx_passthru, because with xen-4.1.2 vga passthrough isn't supported at boot time on ati devices. First you have to install windows and than the driver for you're gpu. Afterwards windows want to restart the system to enable the new gpu - do that and you'll have you graphical output on your second gpu :)
As long as you don't want to try out xen-unstable that's the way to go, which means as for now you don't need the gfx_passthru option.

To start xen you just have to type following into a console (as root):
 xl create /path/to/the/win7-config.cfg  

Next you start your favorite vnc viewer and connect to localhost and install windows. Afterwards you'll have to download the windows ati driver and install them. But be sure to install just the drivers without the ati ccc. It's known that the ati ccc makes troubles with xen. Don't install it.
I think it's the best way is to extract them and let windows install the drivers over the device manager.

3.2 Audio:
I've choose to create a Windows 7 64Bit Version. Actually, when i started to though about xen my biggest worries where everywhere except audio. I actually though it's pretty easy to get audio to work, but actually it's almost impossible.
Why? Well, xen doesn't have any emulated audio cards which work with windows7 64bit. I really searched long for a solution and the final one is more or less a workaround.
I bought a new external USB audio card for about 20€ and connected it on the windows usb bus where windows immediately installed the driver.
The usb audio card has one output and one input. From the output of the usb audio card i go into the input of my onboard audio card on linux. Now i can easy turn on/turn off the sound in windows over linux. Crazy - isn't it? :)
And the cool thing is i can run music on linux while playing on windows at the same time since the virtualized windows is just one more input for linux.

This is the audio card which i bought:
USB Audio Card
Product page of the sound card: Link

3.3 Input:
Input was also a important topic. With pci passthrough input devices are also handled different. The problem is that the monitor output is not on the host system thus you also can't move with the mouse from the hostsystem like in qemu or virtualbox.
That's why, besides the graphic card, i also passthrough an complete usb bus. So i had 4 usb slot solely for windows. I already needed one usb slot for the external audio card. Now i needed two other for the mouse and keyboard.
Furthermore i don't wanted to have 2 mice and 2 keyboard for technically one system and so i searched for a switcher like a kvm switch but just for usb. I found this one. It works just for one device so i had to buy it two times.
Delock USB Switcher
Pretty smart isn't it :) It works, but it's not perfect. Here is the product page of this device: Link

3.4 Harddisks:
Besides the 30GB harddrive for the windows7 system i also created a 300GB harddrive just for data. There i store all my games. In case something goes wrong with windows i still have all my games one separate (virtual) partition.

4) Problems

So far everything works really flawless, but there are still some problems.

  • I wouldn't count the audio devices as problem, because it works really good but it's sad that xen still can't emulate any modern audio cards.
  • It was also a pain for me when i found out that xen supports passthrough first after you installed windows and installed the ati driver. I tried alot after i found that out. Anyway, this will come with xen-4.2.
  • Another problem right now is actually the usb switcher - and that one is also just a minor one.It works, but mostly just from windows to linux. Linux actually never want to release the keyboard/mouse and so i always have to unplug the devices first. It's annoying, but its ok :)
  • My biggest problem right now is that once you shut down the virtualized windows you cannot start windows again. I have to restart the whole linux system too, otherwise it won't work. A bit annoying but i hope that will be fixed with xen 4.2.
Lastly i made a short demonstration video showing UT3 with max details on my 30" screen. I know, it's not the newest game out there, but i think it still has a really good graphic and actually i don't have anything better. (newer yes, but i guess diablo 3 isn't such a pretty game :) )


Btw, sorry for the bad quality - it's my first video on youtube.
That's all for now. Next step will be xen unstable, kernel 3.5 with latest gcc xD

Wednesday, May 16, 2012

different runlevels in gentoo

Different default runlevels isn't something which is quite popular because usually one default runlevel is enough. Nonetheless sometimes it's quite useful.
Since i play around with xen it's very handy to have two different default runlevels. One where the xen services xenconsoled and xenstored get started and one without these services.
The reason is, when starting gentoo without xen these services would crash and thus would slow down the boot process.

To create a new runlevel called "xen" you have todo following:

# mkdir /etc/runlevels/xen
# cd /etc/runlevels/default
# for service in *; do rc-update add $service xen; done
# rc-update add xenstored xen
# rc-update add xenconsoled xen

This would copy all services from the default runlevel into xen and would add both xen init scripts too. Next you need to configure the bootloader and add the softlevel parameter to /boot/grub/grub.conf.

title Gentoo Linux XEN
root (hd0,0)
kernel /boot/xen.gz dom0_mem=8192M,max:8192M iommu=1 xsave=1 dom0_max_vcpus=4 dom0_vcpus_pin 
module /boot/gentoo-3.4.0-rc6 root=/dev/md3 softlevel=xen

Finish, that's all. Quite easy and really useful for xen. A more detailed howto about runlevels can be found at gentoo's offical documentation: Link

Sunday, May 13, 2012

new pc, new toy

It's been already 5 years ago since i bought my last desktop PC. Now i bought a new one. A few months ago i've started to think about my new system. Basically i don't wanted anything special, there was just one thing which i definitely wanted to try out: xen with vga passthrough. Therefore i couldn't choose just anything because you need hardware support for vga passthrough and not every vendor does support it.

Anyway, last month i finally had everything i needed and thus bought my new system.

A big change with the new system was to choose amd over intel. For years now i went with intel, but this time i decided to take amd. The main reason was because amd/ati started to release documentations about their graphic cards years ago. That's something i wanted to support.

Well, this is now my new system:

AMD FX 8150 8-core processor 3,6Ghz
Gigabyte 990FXA-UD5
2x OCZ Vertex 3 120GB
Lian Li PC-6 Aluminium Case
NEC PA301W 30" Display
Scythe Grand Kama Gross CPU Cooler
Seasonic Xseries 760W Power Supply
PowerColor Radeon HD6850 (passiv)
XFX R7970 Radeon H7970 Black Edition
Corsair DDR3 1600MHZ 16GB DIMM

The system runs on gentoo amd64 testing (of course). Since i have two gpu's and xen, there is a virtualized windows 7 64bit for gaming too.
The HD7970 is for windows, while the HD6850 is for gentoo. I also additionally pluged in 2x 22" Lenovo l220x running on the HD6850 on linux (from the old pc). Mouse, keyboard and the audio system is still from the old pc.

This is my desktop right now:

The motherboard supports iommu which is needed for vga passthrough in xen. Nonetheless i updated the bios to the latest version first. On the cpu it's called amd-vi (the cpu flag is called svm) which the amd 8-core also supports. GPU support isn't a hardware feature and has been already implemented for almost every gpu so i didn't had to look for a particular one.

Setting up the system wasn't a big deal. Below are the most important changes while i set up the system.

* i had to change the primary output in the bios so that the system would show the output on my hd6850.

* i also had to enable iommu in the bios (for xen).

* to get eyefinity working i had to download x11-drivers/radeon-ucode and enable the firmwire blobs in the kernel under Device Drivers --> Generic Driver Optinos (howto)

The harddrives running in both raid1 (for the boot partion) and raid0 (for the system/home). Since all the important files are on my server file inconsistency is not  that important. Windows is virtualized and thus just a file on the hard disk.

So far the system is pretty stable. I have a few minor problems with xen but nothing serious. I'll gonna blog about my xen setup anyway.

Monday, May 7, 2012

ssh with different private keys


SSH is probably one of the most used command line tools on linux. If you want to connect to another linux host it's the best way to go. It's also very secure and since security is really important nowadays many hosts on the Internet choose a public key authentication. This method is really smart because it only let people connect if they know their password AND their public key is in the "authorized_keys" file on the host.

For some time now i started a gitolite services at home. It's just for my own usage and thus not available over the Internet. Every script which i write is stored on the gitolite server.
This is quite handy because i can easily switch back to an older version of a script in case i made a mistake. Besides that I'm also forced to learn git which i really want to learn. 

Gitolite also have a public key authentication (on top of ssh), but since the service just runs on the local network and i don't wanted to enter my password every time, I've created a second key without a password.

Well now my problem was, ssh doesn't choose the right key for the git service so i searched the web for solution of my problem. A few hour later i found what i needed. It's easy. You just need a configuration file for ssh, which looks something like this:

Host tunafix
        Hostname tunafix
        User git
        IdentityFile ~/.ssh/gitolite_rsa

Host tunafix
        Hostname tunafix
        User michael
        IdentityFile ~/.ssh/id_dsa

The configuration is stored in file ~/.ssh/config. As you can see, depending on the username ssh choose different identity files. 

Wednesday, May 2, 2012

notify script for cmus

Recently i bought a new PC and therefore i wanted to switch to a new audio player. Usually i use amarok which is still one of the best audio player out there. But it has a big disadvantage - it uses mysql for its database, and i simple don't wanted mysql.
Though, to choose mysql for the database backend is still a good decision - if you have a really big collection.
And that's amarok's audience - users with a huge audio collection.
Well, actually i have a huge audio collection too, but since i actually just play around ~40 tracks all the time besides mostly listening to streams, i really don't wanted a audio player which depends on mysql.
While looking for a new player i found cmus. A very simple console player. It's perfect. It has all the things which i need (playlists, mp3/flac support, stream support) and also has a really tiny memory footprint.
To make the player really comfortably in kde i wrote a small script which shows me some basic information about the actual track which i'm listening too.

And that's the script:
#!/bin/bash
KDIALOG="/usr/bin/kdialog"
GREP="/bin/grep"
AWK="/bin/awk"
CMUSREMOTE="/usr/bin/cmus-remote"

declare -i duration=$($CMUSREMOTE -Q|$GREP "duration"|$AWK '{ print $2 }')
declare -i position=$($CMUSREMOTE -Q|$GREP "position"|$AWK '{ print $2 }')
percent=$[100*position/duration]

artist=$($CMUSREMOTE -Q|$GREP "tag artist") # ${artist:10}
title=$($CMUSREMOTE -Q|$GREP "tag title") # ${title:9}

$KDIALOG --title "CMUS is playing... ($percent%)" --passivepopup "${artist:10} - ${title:9}" 3



It looks like this:


To make it even more comfortably i put some code into my .bashrc and initab.
.bashrc:
if ! [ "$(pidof cmus)" ];
  then /usr/bin/cmus
fi


inittab:
c8:2345:respawn:/sbin/agetty -a michael 38400 tty8 linux


With that settings, cmus always get started on tty8. And with the alias p="cmus-remote -u" i just have to press "p" after login to play music (just a note: i don't use a login-manager, thats why i always login at the console and start kde/X with startx).