Archive

Posts Tagged ‘linux’

Making Windows more Unixy

July 14th, 2010 3 comments

At work I’m stuck on Windows (XP). At home I use Linux (Arch) and Windows (7). I still use Windows because I need to check that software I write runs on Windows, and certain things like iTunes and Spotify still work much better on Windows. I hate developing on Windows though.

I, like many others, would like to be able to have a Unixy (I didn’t think it was a real word, but look!) experience on Windows, so I (like many others) installed Cygwin.

Installing Cygwin

Installing Cygwin’s pretty easy. Just download setup.exe (using the link “Install or update now! (using setup.exe)”) and run it. Follow the instructions, using the suggested values, until you get to Select Packages. Select Packages is a bit like apt-get on Debian or Ubuntu, or Pacman on Arch Linux. It provides an interface for installing and uninstalling packages for your Cygwin installation. For now, go with the defaults, but add Shells -> chere (see below for why). To install chere, click on the text that says “Skip”. This will change to the latest version number of chere. You can run setup.exe again any time without reinstalling Cygwin, so don’t feel like you need to find everything you’re ever going to need. Now click next, and be prepared to wait a looooong time (it could take longer than an hour).

Open Cygwin Here!

There’s a PowerToy for Windows XP which will allow you to right click on a folder and open a command window. On Windows Vista and 7 this is built in. It’s hidden unless you hold Ctrl+Shift when right clicking. It would be even more useful if you could open a Cygwin shell in this way too. Luckily, you can! That’s what chere is for. Just installing chere in Cygwin won’t cut it though, you need to install it into Windows. To do this, run chere -i (for install) in Cygwin. On Windows Vista or 7 you’ll need to run Cygwin as administrator (right click the icon and select “Run as administrator”) for this to work.

Open Explorer Here!

I’d like to be able to do the opposite – that is, open an explorer.exe window with the working directory of the Cygwin shell. This is fairly easy to do as a bash script. Make a new file called openexp or something equally cryptic and save it in /bin (this is a Cygwin dir). Make it executable (chmod +x /bin/openexp) and put the following line in it:

explorer $(cygpath --windows $(pwd))

Now, when you want to open explorer from Cygwin just run openexp.

If you’re new to Bash you may need this explained. Like most codey things, it’s best explained from the inside out.

pwd: pwd stands for present working directory, and outputs the current path.

$(pwd): $() is used for command substitution. $(pwd) is replaced by `/home“ or whatever

cygpath --windows $(pwd): cygpath –windows converts its path argument from Cygwin (Unix) form to Windows form. Its argument will be the working directory in Unix form.

explorer $(cygpath --windows $(pwd)): explorer.exe is Windows Explorer. It takes a directory as an argument – this will be the Windows formatted version of the working directory.

Categories: Linux Tags: , ,

Samsung Fn hotkeys and Arch Linux

July 14th, 2010 3 comments

I’ve got a new Samsung R530 laptop. The first thing I did when I got it was to install Arch Linux (my Linux distro du jour). I nearly broke everything when I installed Grub in the Windows boot partition (I think Grub and NTLDR were fighting), but it all turned out well in the end.

I really like developing in Linux – it really is the perfect development environment. It’s just a pain that everything doesn’t work out of the box. The thing I’ve had the most trouble with is the keyboard ‘Fn’ hotkeys. By this I mean combinations like Fn + Up (brightness up), Fn + F4 (switch display) etc. I’m going to walk through the steps I took to get these keys working in Arch Linux in the hope that someone in the same situation as me may be saved the hours of faffing I’ve had to do.

First, I tried finding out the keycodes using xev and acpi_listen, as suggested by this Super User question. xev showed the volume hotkeys working (which were doing their job anyway), but neither showed anything for the brightness keys. I asked the Arch Linux forum for help and was directed to the Extra Keyboard Keys Arch Wiki page. There I learnt my first lesson:

A scancode is the lowest identification number for a key. If a key doesn’t have a scancode then we can’t do anything because it means that the kernel doesn’t see it.

A keycode is the second level of identification for a key, a keycode corresponds to a function.

A symbol is the third level of identification for a key, it is the way Xorg refers to keys.

I used showkey to find out if the problem keys had keycodes, and discovered that they didn’t. If a key doesn’t have a keycode, it can still have a scancode. If it doesn’t have a scancode then the kernel just doesn’t see it, and you’re screwed. To find out if a key has a scancode, run dmesg | tail -5 after pressing one of the keys. This should tell you what the scancode is, and tell you how to map the scancode to a keycode.

So, at this stage I was able to discover the scancodes of all the non-functioning hotkeys. I made a list a bit like this:

  • Fn + F2: Show battery – e003
  • Fn + F4: Switch display – e002
  • Fn + F5: Backlight on/off – e004
  • etc…

The next step was to follow the instructions in Map scancodes to keycodes. This told me to look in /lib/udev/keymaps. I found samsung-other in there, which contained the following:

0x82 switchvideomode # Fn+F4 CRT/LCD (high keycode: "displaytoggle")
0x83 battery # Fn+F2
0x84 prog1 # Fn+F5 backlight on/off

In fact, every item in samsung-other matched the keycodes I’d found. Great! The next step is to tell udev to use these keycodes. To do this, make a new file in /etc/udev/rules.d/ called 10-local.rules (as suggested in Writing udev rules), and write:

SUBSYSTEM=="input", ATTRS{name}=="AT Translated Set 2 keyboard", RUN+="keymap $name samsung-other"

Replace samsung-other with your keymap if you’re using a different one. Reboot, then run showkey and see if the keys have keycodes (they should do now). If not, you’ll need to look to Map scancodes to keycodes for advice.

At this point, I’ve got working keycodes, but it seems like X is receiving constant key presses when I press one of them, and it’s causing the computer to crash. I don’t actually have a solution to this at the moment. I thought I’d post this in case my working helps anyone else with a similar problem. Maybe it’ll work for you!

Categories: Linux Tags:

Rsync to a mounted Linux CIFS share

June 27th, 2010 2 comments

I was in a position where I wanted to rsync some files from my Linux box to a NAS drive. The drive in question is a Lacie Internet Space (like this but white), which runs Linux. I guess because it’s designed mainly for Windows use, it uses the SMB/CIFS protocol.

In order to rsync files to the NAS, I mounted the drive with fstab. This worked OK, but when I tried to do rsync -va --del, I got a load of permissions errors, whether I ran it as me or root. The errors meant that file metadata wasn’t being transferred, but also that locally deleted files weren’t being deleted on the NAS (making the –del option useless).

I searched and searched for the solution, and everybody seemed to have it, but nothing worked. Then I came across KaZim’s fstab page. The answer which was eluding me was to add the noperm option to the relevant line in fstab. (Apparently it’s a problem with smb shares on Linux servers.) Here’s my working fstab entry:

//HIPSERV/MyBackup/Archie /mnt/backup cifs credentials=/root/.eve,nocase,noperm,file_mode=0777,dir_mode=0777 0 0

[It may be obvious to most people, but to mount everything in fstab do mount -a as root.]

And here’s the working rsync:

rsync  -va --del /home/nick/ /mnt/backup/
Categories: Linux Tags: