Linux

Hauling Servers

After more than four years running my Web applications on Server4You infrastructure, I decided to move on. The reason for my decision to look for a new provider was the decreasing performance of my Server4You Pro X4 Server, especially in comparison with contemporary offers of other vServer providers. I therefore moved this blog and other PHP based applications to a DigitalOcean droplet, which offers 20 GB SSD storage, 512MB RAM and full root access for only 5$ per month. Perfect for Web hosting and serving small services. Moving the data and apps was actually done within two hours, hence its worth comparing offers of different providers and change them from time to time.

Compile the Memcached-Libraries

MySQL provides NoSQL features since version MySQL 5.6 via the Memcached plugin. To use these advanced features for your instance you compiled from source, some modifications are required. Install libevent-dev to obtain the appropriate event libraries via apt.

apt-get install libevent-dev

Then, modify the cmake script and switch the option flag for the Memcached Plugin from OFF to ON. Open the File CMakeLists.txt and search for this line:

OPTION(WITH_INNODB_MEMCACHED "" OFF)

Change this line to:

OPTION(WITH_INNODB_MEMCACHED "" ON)

Then compile MySQL by using these commands:

rm CMakeCache.txt; make clean: cmake . ; make

Then copy the shared libraries into your plugin folder:

cp ./plugin/innodb_memcached/daemon_memcached/libmemcached.so /usr/local/mysql/lib/plugin/
 cp ./plugin/innodb_memcached/innodb_memcache/innodb_engine.so /usr/local/mysql/lib/plugin/

Then from the MySQL-Console, issue these two commands (without the mysql>):

mysql> SOURCE /usr/local/mysql/share/innodb_memcached_config.sql;
mysql> NSTALL PLUGIN daemon_memcached soname "libmemcached.so";

Installing Mint 14 and Windows 7 on Samsung Ultrabook Series 5 535U3C

After reading several articles about a firmware bug on Samsung Ultrabook Laptops, that would destroy the device when attempting to boot a Linux kernel, I was quite skeptical whether to get one or not. The price was tempting (499€) and the design and specs quite nice. But there exist these reports about a bug in the current firmware would brick certain Samsung laptops immediately if booted via UEFI. The device ships with a preinstalled Windows 8, which uses UEFI. For this reason installing Linux Mint (or any other distribution) bears a risk. As I work with Linux but for some tasks simply need a Windows installation (and this class of notebook is too weak for virtualization) I wanted both systems with dual boot. As I didn’t know for sure if my 535U3C was using the critical firmware, I pursued the following steps and ended up with a perfectly working device featuring Windows 7 and Mint Linux:

  1. You need two USB pen drives for convenience.
  2. Prepare a Linux Mint bootable USB stick with the Mint ISO
  3. Prepare a second USB stick with a Windows 7 ISO
  4. Boot the preinstalled Windows 8 and install latest BIOS update
  5. Reboot, press F2 and switch boot mode to CSM legacy mode
  6. Insert the Linux Live USB stick and boot from it.
  7. Install gdisk with sudo apt-get install gdisk
  8. Use it to remove the GPT as described here
  9. Reboot, attach the Windows 7 USB drive and boot from it
  10. The Windows 7 setup has a bug when booting from a USB stick (:-)). It will complain that no drivers are present to read the data from the drive (yes, the installation routine has already started… from this very drive…). Now unplug the USB stick and plug it into a different USB port. Then press Cancel and retry. Now it should work.
  11. Install Windows 7, then reboot
  12. Now install Mint Linux from the second drive just as usual
  13. Enjoy!

Raspberry Pi XBMC

The Raspberry Pi is a creditcard sized micro computer that runs various Linux operating system flavors. Its amazingly cheap prize (35$), the small size and its little power comsumption render it a great gadget for many purposes. With very little effort the Raspberry can be converetd into a mediacenter for watching HD movies or stream movies from Youtube. The setup is quite easy and just involves a few steps. You can comfortably control the device with the App Yatse  on your Android phone. Try it! Its great!

MySQL – Das Handbuch für Administratoren

Seit kurzem gibt es ein neues Buch im Portfolio von Galileo Computing: MySQL – Das Handbuch für Administratoren. Dieses Buch ist für mich etwas ganz besonders, nicht nur, weil es das erfolgreichste Open Source Datenbankmanagementsystem der Welt zum Inhalt hat, sondern weil es sich dabei um den erfolgreichen Abschluss eines sehr spannenden und komplexen Projektes handelt.  Gemeinsam mit Eva Zangerle und Wolfgang Gassler habe ich in den letzten Monaten so gut wie jede freie Minute für dieses Buch aufgewendet und seit wenigen Wochen ist es nun veröffentlicht worden.

Details dazu sind auf der offiziellen Buch-Homepage www.mysqladmin.at zu finden und in diesem Blog.

VirtualBox 4 – Performance Problems Solved

For a current project I am working on, I need several Linux machines running simultaneously, in order to perform some test-runs. Further more, I need a Windows 7 installation, because I have to use some software only available for Microsoft Systems. Therefore, the virtualization solution VirtualBox, is quite handy to manage all of systems. Although my host system is not really state of the art ( Dual-Core E5200 @ 2.50GHz , 6GB RAM), the system performs quite nicely with several guests up and running at the same time. Only if I would perform complex tasks within a Linux guest, such as compiling software from source, the whole system would freeze and be unusable until a reset. After googeling for a while, I

found a solution to this problem. The trick is to set the kernel option nohz=off in the GRUB boot menu file, you can find in /boot/grub/menu.lst. Open this file as root user and locate the record of your current kernel. Simply add the before mentioned option to this line and reboot the host system. The complete kernel boot section should no be similar to this one here:


title           Ubuntu 10.10, kernel 2.6.35-28-generic-pae
uuid            94e1022f-4ffd-4825-b8ca-2e86eca07d10
kernel          /boot/vmlinuz-2.6.35-28-generic-pae root=UUID=94e1..d10 ro quiet splash
                        nohz=off
initrd          /boot/initrd.img-2.6.35-28-generic-pae
quiet

After I added this option, the system behaved much better and did not freeze anymore.

Parsing KML files with PHP

KML with PHP. As the format is XML based, open and clearly defined, its actually pretty simple. The following code uses the Document Object Model in order to retrieve all nodes from a , which contain the string of coordinates as their element content.

function parseKML(){

// Create a new DOM model  
$doc = new DOMDocument();  
// Load a KML file  
$doc->load( ‘example.kml’ );  
//Pick all Point – Elements  
$points = $doc->getElementsByTagName( “Point” );  
// For every point, extract the coordinates  
foreach( $points as $point ){  
$coordinates = $point->getElementsByTagName( “coordinates” );  
$coordinate = $coordinates->item(0)->nodeValue;  
$geoPoint = parseCoord($coordinate);

}

The following function applies a regular expression to the given string of coordinates. This regex filters the longitude and the latitude of a given set of coodinates and creates a new GeoPoint, which is simply a class called GeoPoint, having the two parameters as member variables.


function parseCoord($coordinate){  
$geopoint = null;  
// Delete all blanks  
$coordinate = str_replace(” “, “”, $coordinate);  
//Regular expression  
$regex = “/([-+]{0,1}[0-9]{1,}\.{1}[0-9]{1,})\,([-+]{0,1}[0-9]{1,}\.{1}[0-9]{1,})/”;  
// Apply regex  
try {

$match = preg_match($regex, $coordinate,$result);

// If the string is valid, retrieve results  
if($match>0){  
$long = $result[1];  
$lat = $result[2];  
$geopoint = new GeoPoint($long, $lat);  
}  
} catch (Exception $e) {  
echo ‘There was an error: ‘,  $e->getMessage(), “\n”;  
}  
return $geopoint;  
}

Getting static – with WordPress

As I moved to a new server recently, I decided to convert my blog which I had during my semester abroad into static HTML, as the blog itself won’t change anyway. The easiest way to do so was to download the original blog with HTTrack completely to my local system. This tool converts dynamic links into static, relative ones, which is needed in order to move the blog to a new location. HTTrack preserves the page’s structure completely and includes all files such as images. After the download was complete, I just copied the whole, static website to its new destination. Great 🙂

How to extract some pages from a multi-page PDF?

It may be necessary to split a set of pages from a multi-page PDF into a separate document. Usually, this can be done by using the „Print to PDF“ function of Ubuntu, but not all applications are supported now. Otherwise, one could just print the desired pages to a new PDF file. Another solution would be cups-pdf, a virtual printer. But the quality is very low and insufficient for some purposes.

Finally, I found this nice tool: pdftk

Install it with sudo apt-get install pdftk and then simply enter the following, in order to extract pages 3 to 17 from input.pdf and write them into output.pdf:

pdftk input.pdf cat 3-17 output output.pdf

Nvidia 9500 GT and Ubuntu

As I do not really play computer games but still enjoy a little bit of hardware accelerated graphics (Compiz is really an eye candy and – believe it or not – enhances usability), I decided to get myself a GeForce 9500 GT from Nvidia, which is very cheap. Unfortunately, I had troubles with using device’s 3D-features from the very first. Neither using envy, the comfortable tool in order to install 3D video cards, nor installing the Nvidia binary drivers with Synaptic, nor compiling the drivers from scratch did work. Although I could use accelerated graphics after installing and restarting the Xserver, the settings seemed to get messed up after one or even after some reboots of my system. After restarting my computer, the screen would turn and remain black, when ever GDM was or should be started. The solution can be found by following the link below

The solution to this problem was to completely remove all nvidia packages, which accumulated during various installation odysseys. In order to do so, switch to a console (Alt+Ctrl+F2), log in and stop GDM by using the command
sudo /etc/init.d/gdm stop
Then, search for all packages with the command
dpkg -l | nvidia
and feed all found packages into the uninstallation routine from apt-get with the command
apt-get remove [package name]
If you have removed all found packages, make sure that there are no references to Nvidia packages or modules in /etc/init.d by searching for leftover files with
ls -a | grep nvi
Remove found files, renaming does not help! Then, install the original driver for your Nvidia card obtained by the Nvidia servers and follow the instructions. Finally, a reboot should bring you into your preferred Desktopenvironment again, now with nice graphics.

Thunderbird, Lightning and Google Calendar on Ubuntu 8.10

It is a known bug, that the calendar extension Lightning does not work correctly with the latest versions of Thunderbird. In my case, I was not able to create a new calendar at all. In order to fix this, just install libstdc++5:

sudo aptitude install libstdc++5

Works fine with Tb 2.0.0.19 and Lightning 0.9

Enable Hibernation on Ubuntu 22.04 with LVM and Full Disk Encryption

When settin up my new laptop I forgot to enable hibernation manually and the device deep decharged over night. It would only power on again after getting the original power supply from the office, since my USB charger had 63W instead of 65W according to Tuxedo support. Anyways, the following steps I have taken from Ask Ubuntu worked flawlessly.

Check if there is a swap partition in use

sudo swapon -s

Disable the current swap partition

sudo swapoff -a

and remove the record from /etc/fstab and add a new record for the new swap file we will create in the next step. My /etc/fstab file looks like the following, after the old record has been commented out (#) and the new record for the swapfile has been added.

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vgubuntu-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/nvme0n1p2 during installation
UUID=e62203cc-4593-4651-b239-c9d6c8710e2e /boot           ext4    defaults        0       2
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=6FC6-A930  /boot/efi       vfat    umask=0077      0       1
# Original swap partition
#/dev/mapper/vgubuntu-swap_1 none            swap    sw              0       0
/swapfile   none    swap     sw      0       0

Since the entire disk is encrypted, the swapfile is encrypted too.

Then create the new swapfile and ensure it is big enough to hold the entire memory plus some buffer. I simpy created 40 GB just to be sure.

sudo fallocate -l 32G /swapfile
sudo chown 0 /swapfile
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Reboot with sudo reboot and check if the new swap file is in use with sudo swapon -s

Filename				Type		Size		Used		Priority
/swapfile                               file		41943036	0		-2

Lookin good!

To enable hibernation, we have to tell the bootloader grub that there is a swapfile to resume from. To do this, we have to get the UUID from the root partition / using the following command.

findmnt / -o UUID

The output will be similar to this

UUID
4674b60a-68b3-427c-9b0e-124866c78828

Then we have to get the offset from the swapfile

sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'

This will return the offset on position 0

sudo filefrag -v /swapfile |grep " 0:"
   0:        0..       0:    3717120..   3717120:      1:

In my case the offset is 3717120.

Now add the UUID of the root partition and the offset to the grub command as follows. Open the config file with vim /etc/default/grub and add the following parameters to your existing line.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX"

My final grub config looks like this, your mileage will be different

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i915.enable_psr=0"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i915.enable_psr=0 i915.enable_dc=0 intel_idle.max_cstate=2 resume=UUID=4674b60a-68b3-427c-9b0e-124866c78828 resume_offset=3717120"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Finally, udate grub with sudo update-grub and restart with reboot. Then you can try to hibernate with sudo systemctl hibernate.