söndag 29 mars 2015

Easy Minecraft installation in Linux

This is an installation script for Minecraft on Linux. It installs the Minecraft launcher in the system, so that all users can easily start and play Minecraft. It creates icons and a shortcut to the launcher.

The script is an improved version of this script (github https://gist.github.com/wvega/728367)

When the user starts Minecraft, it will download a copy of Minecraft to the user's home directory, exactly like when manually installing Minecraft.

This script works fine on Fedora, but I imagine it should work on most Linux distros. The only requirement is that Java is installed somewhere. The script assumes there is a link to Java at /usr/java/latest/bin/java or in /usr/bin/java, otherwise it will exit with an error.

The script downloads the Minecraft launcher, and installs it system wide. Sometimes the Minecraft launcher address has changed and then of course the script must be updated.


Download the shell script here or from github. Do "chmod +x minecraft-install.sh". Then execute it with "sudo ./minecraft-install.sh".

Identifying an unknown Windows hard disk - reading Windows file versions in Linux

What do you do when you have an unkown Windows hard disk or partition, that you don't want to boot or that is unbootable? How do you identify the Windows version installed on the hard disk or partition?

In Linux, we are used to mount the hard disk and then look at /etc/issue, /etc/redhat-release or something similar. You can even see the kernel version in the file names of the installed kernel images in /boot.

But for a Windows OS? Well, you could look at the version of ntoskrnl.exe, for instance.

Here are the version numbers for different versions of Windows [1]:

4.x: NT 4.x
5.0: Windows 2000
5.1: Windows XP
5.2: Windows 2003 Server (and R2), Windows XP 64-bit
6.0: Windows Vista, Server 2008
6.1: Windows 7, Server 2008 R2
6.2: Windows 8, Server 2012
6.3: Windows 8.1, Server 2012 R2

10.0: Windows 10, Server 10

 So just mount the hard disk/partition and then look for C:\Windows\System32\ntoskrnl.exe.

But how do you read the version number of a Portable Executable (PE) file in Linux? You could extract it with hexdump -C and search for the version number (in hex!), but that is quite awkward. There are supposedly some PE tools for linux, but I couldn't find any in Fedora repositories.

A simple way is to use Wine and a Windows tool to check the header of the PE file, for instance Sysinternal's SigCheck tool [2].

wine sigcheck -q -n ntoskrnl.exe
6.2.9200.16424 (win8_gdr.120926-1855) 

In this case, the Windows version is Windows 8 (or possibly Server 2012 R2). 

Telling the difference between Server and Workstation is harder. I don't know how to do that without Windows running (when you could programmatically check for OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION for a server OS, at least for Server 2008 and later).


Update. I have since discovered another tool, ExifTool [3] that is able to read PE headers and display version number. On Redhat/Fedora this is available as perl-Image-ExifTool. 
exiftool ntoskrnl.exe |grep 'File Version  '
File Version             : 6.1.7601.23677 (win7sp1_ldr.170209-0600)

[1] https://msdn.microsoft.com/en-us/library/ms724832%28VS.85%29.aspx
[2] https://technet.microsoft.com/en-us/sysinternals/bb897441.aspx

[3] http://www.sno.phy.queensu.ca/~phil/exiftool/

lördag 28 mars 2015

Laptop touchpad stops working after suspend

The MSI GE60 Laptop has an Elantech touchpad that has always had some problems working in Linux after suspending and resuming the laptop.

Edit: Found some notes. It seems to have worked fine in Fedora 18, but in Fedora 19 after a synaptics driver update (xorg-x11-drv-synaptics-1.7.1-3.fc19.x86_64) it went totally nuts. Edge scrolling stopped working and after suspend/resume, the touchpad notification icon was flashing over the GDM login prompt, alternating with the on and off icon image. The touchpad was also turned off after reboot and couldn't be turned on except for in the Gnome system settings. After a few updates, some of the problems were fixed, except for the problem that it is turned off after suspend/resume.

At least now with Fedora 20, which is currently installed on the laptop, the touchpad always stops working when resuming from suspend, and the hardware button to turn on doesn't affect its state.

It is using the psmouse kernel driver and synaptics in Xorg:

from dmesg:
[    1.961844] psmouse serio1: elantech: assuming hardware version 3 (with firmware version 0x550f00)
[    1.978787] psmouse serio1: elantech: Synaptics capabilities query result 0x79, 0x15, 0x0c.
[    2.064901] input: ETPS/2 Elantech Touchpad as /devices/platform/i8042/serio1/input/input5


from Xorg log:
[    30.565] (II) LoadModule: "synaptics"
[    30.565] (II) Loading /usr/lib64/xorg/modules/input/synaptics_drv.so
[    30.611] (II) Module synaptics: vendor="X.Org Foundation"
[    30.611] (II) Using input driver 'synaptics' for 'ETPS/2 Elantech Touchpad'
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: x-axis range 0 - 2356 (res 0)
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: y-axis range 0 - 1240 (res 0)
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: pressure range 0 - 255
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: finger width range 0 - 15
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: buttons: left right double triple
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: Vendor 0x2 Product 0xe
[    30.629] (--) synaptics: ETPS/2 Elantech Touchpad: touchpad found
[    30.644] (**) synaptics: ETPS/2 Elantech Touchpad: (accel) MinSpeed is now constant deceleration 2.5
[    30.644] (**) synaptics: ETPS/2 Elantech Touchpad: (accel) MaxSpeed is now 1.75
[    30.644] (**) synaptics: ETPS/2 Elantech Touchpad: (accel) AccelFactor is now 0.075



One way to turn the touchpad on again is to use the keyboard to navigate to computer settings (in Gnome) and turn off and on the touchpad. Another way is to reboot the computer.

To make it work with suspend, you can turn off the touchpad before suspending and turn it on afterwards. To do this automatically, create a file at /etc/pm/sleep.d/00-trackpad with the following content:
#!/bin/sh

declare -i ID
ID=`xinput list | grep -Eo 'ouchpad\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
case "$1" in
  suspend|hibernate)
     xinput disable $ID ;;
  resume|thaw)
    xinput enable $ID ;;
esac
Edit: Don't forget to make the script executable with chmod +x.

There are some examples on the Internet with similar solutions (mostly for Ubuntu). However, they unload and load the psmouse kernel driver. This doesn't work in Fedora, because psmouse is built into the kernel.

To finally fix this, a bug report should be created for the synaptics driver, but it is not always easy to get obscure bugs fixed upstream.