fredag 23 oktober 2015

DIY 12V UPS for home network equipment

I have a small cabinet for modem, router, network switch and 8-port patch panel. I've managed to squeeze in a small UPS as well. When I finally got DOCSIS 100/20 Mbit Internet, the cable modem was so big that I had to make some changes to the cabinet. It is good to have an UPS for the equipment. Internet usually works during short power outages and the equipment is not damaged by hard reboots. It also protects somewhat against voltage spikes. So when all of the equipment runs on 12 V it got me thinking. Why do I need an UPS that converts 230 V AC into 12 V DC (for the battery) and then to 230 V DC again, and then at least three small adapters to convert it separately to 12 V DC again? Instead I could replace it with one larger 12 V DC power supply combined with a battery.

I found a 12 V UPS, a Mean Well AD-55A. It outputs 4 A at 13.8 V DC and a small battery can be attached (charge 13.4 V, 0 - 0.23 A). Output voltage is adjustable between 12 - 14.5V.

It has of course to be built into a box to be electrically safe. I had an old monitor switch box that was suitable. A few holes were cut to add a fuse and five "DC plug" 12 V outputs. Add a small combined voltage and current meter and we have this:

You have to find the correct DC plugs that fit into the equipment. Be sure to check the polarity!

Installed in the cabinet together with the small lead battery from the previous UPS:

In the top is the network patch panel. Middle right is the big cable modem (DOCSIS). Middle left is the router, an Ubiquiti Erlite-3. A fantastic router. I mistakenly run it on 5 V when I bought it. It didn't mind, but for sure 12 V is better. At the left on the inside of the cabinet door is a small 8 port Gbit network switch. In the bottom is the battery and UPS. Note that there is no Wifi access point in the cabinet. It wouldn't work well inside the metal cabinet. 

A closer look of the running UPS. The switch, router and cable modem together need 1.56 A DC, so there is a lot of margin to run other equipment if needed.

I mostly did this just because I liked to do it. There is a bit more space in the cabinet for air flow and it is definitely not as hot as before. Some electricity is probably also saved, although I didn't do any measurements. The cost was mostly the power supply/UPS module. It was 28 € + VAT + shipping.

It took a lot of time to make the DC plug patch cables, though. But I don't know if you can get them ready built from somewhere.

If I had a large room for the equipment, I would definitely use a large lead battery with a regular car battery charger. Then use a 12 V - 12 V DC power supply to drive the equipment.

söndag 23 augusti 2015

Converting a cordless drill to LiFePo4 batteries

Modern cordless power tools use Lithium batteries, but they are quite expensive. This article shows how to convert an old cordless drill to use modern batteries.

The solution covered here requries soldering skills, knowledge of Lithium batteries, how to connect batteries for balanced charging, how to connect batteries in series and of course basic electrical knowledge. You might also need an assortment of small wires, connectors, shrink tubes, small tools (and small fingers!) and fabrication skills. I will not cover these details in this article.

You also need charger that can handle Lithium batteries (and also the correct type). You can't use the original drill charger.

The particular drill used 10 NiCd (nickel-cadmium) batteries in series for 12 V total output. It is a modest 1200 mAh battery pack and has to be charged quite often.

The picture shows the drill with disassembled battery pack. The original charger was just a 12 V DC adapter without any charging circuitry. I've instead been using a modern charger that is able to charge many different type of batteries. The advantage is that the charger is able to detect when the battery is fully charged.

Battery selection

There are a couple of different modern batteries that can be used. Li-Ion (lithium-ion) is the most common. This kind of battery is used in many RC applications, power tools, electric cars, smart phones etc. A better variant of lithium for really high output current is Li-Po (lithium polymer). The drawback with this one is that it must be handled carefully to avoid explosions! I.e. no overcharging or abusing. A more stable lithium variant is LiFePo4 (lithium iron phosphate). These batteries are very safe, have high output current and the output voltage is almost static during discharge. The power density is also very high. LiFePo4 batteries are quite new on the market, but you can find them for instance in good RC shops.

I decided to use two LiFePo4 packs in series, 2 x 6,6 V = 13,2 V. The battery packs were rated 1700 mAh. They are marked 2S1P, 2 cell, 6,6 V, 20C with a 2S balance connector. 20C means that the battteries can be discharged with a maximum of 34 A! (1,7 Ah x 20). That's an incredible current for such a small battery. From some more or less unreliable sources I've estimated that a drill such as this needs at most 5 - 15 A during heavy drilling. The batteries will be more than adequate.

You can see the old NiCd batteries on the left and the two new LiFePo4 packs on the right.

I was able to barely sqeeze them into the old battery case. I highly recommend using smaller battery packs, because it became a very tight fit with the connectors. I wanted to retain the connectors, so I could easily remove the batteries and fit new batteries if needed.

To connect the batteries in series, I used an adapter.

This adapter was further modified and the output was connected in parallel to the old connector of the battery pack. The idea was to easily connect the batteries in series and have a charging connector.

Additionally you need an adapter for the balance connectors (because of the series connected batteries). In this case, I needed a 2S to 4S adapter.

2S to 4S balance adapter.

Protection circuit

Lithium batteries must be protected from being discharged too much. If the voltage becomes too low, the battery will be damaged. This is also the case for LiFePo4 cells.

The old drill didn't have any such protection. But there are cheap Lithium protection circuits available on the Internet. This one is compatible with 1 - 8 battery cells, shows total voltage and individual cell voltage and has a buzzer for low voltage. The low voltage can be set from 2,7 to 3,8 V. I set it to 2,8 V for the LiFePo4 cells.

The protection circuit fitted into the spacer that sits in the bottom of the battery case.

Spacer in place in the battery case.

And from the bottom side. You can see the LED display that shows the battery voltage.

The protection circuit can be directly connected to the balance connector of a Lithium battery back.

UPDATE: It seems that my charger doesn't like the protection circuit at all, so it has to be completely disconnected when using the balance connector while charging.

Schematic that shows the Low Voltage Alarm connected to the 2S to 4S balance adapter. A switch breaks the negative voltage to the alarm and is sufficient to turn the alarm off when the drill is not used. Because the balance connector is needed for charging, I cut a small hole in the middle of each wire and soldered the wires to the alarm. By disconnecting the wires from the connector (carefully use a small screwdriver to press down the tabs), you can put heat shrink tubing on the wire to protect it.

Putting it together

The picture shows the assembled pack. The protection circuit is not connected yet, but I was able to do a test run. If you look carefully you will see that there is a 6S balance connector. That's because I didn't have a 4S connector yet, so I swapped the positions of the wires in the 6S one and left a few disconnected. Plugging it into the 6S connector on the charger works just fine.

In this picture the protection circuit is soldered to the balance cable and everything is in place.

Closeup of the balance cable and power cable mess. More space would have been better.

An already existing hole was enlarged in the battery case so that I can pull out the charging and balance connector when the battery is going to be charged. The old power connector at the top is secured with a wire through the neck.

The finished drill. You can see the switch in the front of the battery pack that turns the protection circuit off. Happy drilling!

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

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". Then execute it with "sudo ./".

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)



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/
[    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:

declare -i ID
ID=`xinput list | grep -Eo 'ouchpad\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
case "$1" in
     xinput disable $ID ;;
    xinput enable $ID ;;
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.

onsdag 7 januari 2015

Commercial software on Linux - RAR

I found that I had an old registration key for WinRAR laying around. Since I don't use Windows any more at home, I checked and found that there is indeed a commercial Linux version of the software available nowadays.

RAR is a proprietary archive format that was widely used in the 90's and the next decade when the Internet became a popular place to share software and media files. It has better compression ratio than ZIP, has strong encryption and very good error recovery capabilities. I have some memories from my time as a student of keeping a WinRAR binary on a floppy and use it to decompress and compress files transferred from and to the Internet.

I'm not going to debate over FOSS vs. commercial software in this post. If we weigh in such arguments, there are no reasons to use anything else than the LGPL licensed 7Z (p7zip) or tar with bzip2, gzip or xz (and their parallel variants), but that was not the point of this post.

There is also a freeware unrar program and libunrar library available for Linux and Unix (for Fedora in the rpmfusion repository), but it is only able to extract files from RAR archives.

To be able to create RAR archives, you have to use the official software from RARLAB. You can use it for 40 days. After this you have to buy a license key. The license is fair; software upgrades have been free (at least until now).

To easily install the RAR program (instead of downloading from the official web site and manually install it) on Fedora, there is a repository available at This way also updates are nicely handled. Just add the repo file:

sudo yum-config-manager --add-repo
sudo yum -y install rar

As far as I can tell from the RARLAB site, the license for WinRAR and RAR for Linux/Unix are the same and the later versions use the same license key. Just put the rarreg.key in your home directory (for a single user license) and begin archiving.


tisdag 6 januari 2015

Preventing normal users from Shutting Down or Rebooting PC

The default policy in linux is often that normal users can shut down or reboot a PC, even if other people are logged in. When using a desktop PC as a server or if you often leave your applications open, you don't want that to happen.

This is a question that comes up many times on the Internet. The problem is that the components in linux change and not every distribution uses the same components.

In linux, only root has the power to shut down or reboot. Many linux distributions use Policykit for rules to override this and let the normal users shut down and reboot.

In Fedora 21, to override the default rules, create a new rule with the following command:
sudo nano /etc/polkit-1/rules.d/60-noreboot_norestart.rules
 Paste the following text:
polkit.addRule(function(action, subject) {
    if ( == "org.freedesktop.login1.reboot" || == "org.freedesktop.login1.reboot-multiple-sessions" || == "org.freedesktop.login1.power-off" || == "org.freedesktop.login1.power-off-multiple-sessions") {
        if (subject.isInGroup("power")) {
            return polkit.Result.YES;
        } else {
            return polkit.Result.AUTH_ADMIN;
Save the file. The policy will now be in use for users logging in. It will always prevent a normal user from rebooting or shutting down the system and it will ask for the administrator user password. If you want to allow a user to shut down or reboot when no one else is logged in, modify the rules above and remove the parts " == "org.freedesktop.login1.reboot" ||" and " == "org.freedesktop.login1.power-off" ||". Then it will only prevent users from rebooting and shutting down when other users are logged in.

[1] At some point there was a bug in systemd that ignored the login rules, but it was fixed last year [].

[2] The code in this article was copied from here []