How to Fix MySQL Fatal error: Illegal or unknown default time zone

Tags: October 19, 2014 2:36 PM
0 comments

Problem

You want to set the default timezone for MySQL using my.cnf configuration file. But MySQL unable to start and the error log says:

Fatal error: Illegal or unknown default time zone 'NAMED_TIMEZONE'

Solution

Do not use named timezone unless you had timezone data populated on your mysql database. Instead use an offset relative to the UTC e.g: '+07:00' or '-04:00'.

Share on Facebook Twitter

XenServer 6.2: Fix Unrecognized LVM Volume on Boot

Tags: May 18, 2014 6:44 PM
0 comments

Default Xenserver 6.2 root partition is 4GiB that's very small. So I want to separate the /tmp and swap to other partition in this case a LVM volume. The bad news is LVM volumes does not activate on boot. So entries in /etc/fstab which relies on LVM would fail and the boot process got stuck since the system would try to do some file system checking on every partition listed.

Activate LVM on Boot on XenServer 6.2

To activate on boot we need to make small modification to file /etc/rc.sysinit around line 487 to 489. Take a look into these lines:
#if [ -x /sbin/lvm.static ]; then
# action $"Setting up Logical Volume Management:" /sbin/lvm.static vgchange -a y --ignorelockingfailure
#fi
That's the problem, the lines which activate the LVM volume is commented. That's why we ended up with the problem. Now just uncomment those lines and save the file. But make sure you made a copy of it. Reboot the server and all LVM volumes should be detected on boot. Here's an example of my XenServer custom partition scheme:
LABEL=root-mterkkri    /         ext3     defaults   1  1
#/var/swap/swap.001          swap      swap   defaults   0  0
none        /dev/pts  devpts defaults   0  0
none        /dev/shm  tmpfs  defaults   0  0
none        /proc     proc   defaults   0  0
none        /sys      sysfs  defaults   0  0
/opt/xensource/packages/iso/XenCenter.iso   /var/xen/xc-install   iso9660   loop,ro   0  0

/dev/mapper/VG--XEN01-Dom0--TMP /tmp ext2 defaults,noexec,nosuid,nodev 1 2
/dev/mapper/VG--XEN01-Dom0--SWAP swap swap defaults 0 0

/tmp /var/tmp   none rw,noexec,nosuid,nodev,bind 1 2

Share on Facebook Twitter

Switching USB Modem to Serial Manually

Tags: May 12, 2014 3:56 AM
0 comments

Without having to use usb-modeswitch switching the USB modem can be done easily. In this example I use USB CDMA modem with vendor ID 201e and product ID 1023 (when detected as CD-ROM storage) and product ID 1022 (when detected as USB modem or USB storage).

Requirements

Most of these module are present in all modern linux distro.
  • Kernel module: option (USB Driver for GSM modems)
  • Kernel module: usbserial (USB Serial Driver core)

Step 1: Detach the CD-ROM Storage

When you first plug your USB modem it might detected as CD-ROM storage. To identify the modem you can use dmesg and lsusb commands. Make sure running these commands as root.

Share on Facebook Twitter

Ubuntu TP-Link TL-WN723N Ad-Hoc Network

Tags: May 11, 2014 3:20 PM
0 comments

The Wifi ad-hoc network configuration that will be created for this task are composed from the following devices:

  1. Computer A (TP-Link TL-WN723N) IP: 192.168.1.25/29
  2. Computer B (Other Wireless) IP: 192.168.1.26/29

Step by Step Ad-Hoc Configuration

This is important, the Computer B should be configured first followed by Computer A. It might not work if configured using opposite order. Bug: https://github.com/lwfinger/rtl8188eu/issues/4

Share on Facebook Twitter

Ubuntu Linux TP-Link TL-WN723N Driver

Tags: May 9, 2014 11:18 PM
0 comments

Update

The more recent driver for TP-Link TL-WN723N can be found on https://github.com/lwfinger/rtl8188eu. This new driver address problem for kernel 3.8+. Do not forget to copy the firmware file rtl8188eufw.bin to /lib/firmware/rtlwifi/. Failed to do so, you might can not bring the device up.

 

I just bought a nano wireless adapter from TP-Link, the TL-WN723N. But my Xubuntu 12.04 did not recognize it, well that sucks. But thanks to this guy he made the driver for it: https://github.com/gleb-chipiga/rtl8188eu.

Driver Installation

Make sure the compiler and git already installed on the system.
$ mkdir -p /tmp/tp-link && cd /tmp/tp-link
$ git clone https://github.com/gleb-chipiga/rtl8188eu
$ cd rtl8188eu
$ make
$ CURRENT_KERNEL=$( uname -r )
$ sudo cp 8188eu.ko /lib/modules/$CURRENT_KERNEL/kernel/drivers/net/wireless/
$ sudo depmod -a
$ sudo modprobe 8188eu
$ ip link show
The wireless adapter should be detected, no need to reboot.

References

Share on Facebook Twitter

Bash Trim Whitespace

Tags: May 2, 2014 10:45 AM
1 comments

To remove leading and trailing whitespace from a subset of strings in a shell we can use sed.

$ echo '   #FOO#   ' | sed -e 's/\s*$//' -e 's/^\s*//'
#FOO#

Function 'trim'

To reuse it in another place, it is good idea to wrap it as a function.
# Function to trim leading and trailing spaces
trim() {
  # Accept input from argument or STDIN
  # So you can do both:
  # $ echo '  #FOO#   ' | trim
  # or
  # $ trim '   #FOO#   '
  local STRING=$( [ ! -z "$1" ] && echo $1 || cat ; )
  
  echo "$STRING" | sed -e 's/^\s*//' -e 's/\s*$//'
}
Now it can be used to trim a string both from argument or standard input.
$ echo '   #FOO#   ' | trim
#FOO#

$ trim '   #FOO#   '
#FOO#

Reference

Share on Facebook Twitter

Finding Interface Name Using IP Address

Tags: April 23, 2014 7:47 AM
0 comments

Getting network interface name using IP address could be accomplished by issuing:

$ ip addr show | grep "192.168.1.2" | awk '{print $7}'
or another alternative:
ifconfig | grep -B 1 "192.168.1.2" | head -n1 | awk '{print $1}'
Both command would output the name of interface such as eth0, eth1, etc.

Reference

Share on Facebook Twitter

Fix LVM Input/Output Error Caused by Node Change

Tags: April 13, 2014 8:42 AM
0 comments

I have LVM partition reside on my external hard drive which connected trough USB. Here's the output before I unplug the device.

$ pvs
  PV               VG    Fmt  Attr PSize   PFree  
  /dev/maxtor1-40g       lvm2 a-    37.27g  37.27g
  /dev/sde5        XENVG lvm2 a-   125.78g 121.78g
When I unplug and plug the device I always got I/O error like this:
$ pvs
  /dev/dm-0: read failed after 0 of 4096 at 0: Input/output error
  /dev/dm-0: read failed after 0 of 4096 at 4294901760: Input/output error
  /dev/dm-0: read failed after 0 of 4096 at 4294959104: Input/output error
  /dev/dm-0: read failed after 0 of 4096 at 4096: Input/output error
  PV               VG    Fmt  Attr PSize   PFree  
  /dev/maxtor1-40g       lvm2 a-    37.27g  37.27g
  /dev/sdd5        XENVG lvm2 a-   125.78g 121.78g
Well that sucks since it would become unmountable. The LVM still pointing to the old /dev/sde5 that's why the error comes.

Share on Facebook Twitter

Mapping Device to Persistent Name Using udev

Tags: April 12, 2014 11:38 PM
0 comments

To prevent device name changes from time to time i.e: /dev/sdc to /dev/sdd and so on a corresponding udev rules need to be created. The first step to dive into udev configuration is getting information from the device.

Getting Device Information

In this example I have Seagate 250GB hard drive which connected through USB. The device is currently attached to /dev/sdd. Here's how to get information from the device. All commands are run by root.

Share on Facebook Twitter

Linux Show Selected Route for Particular IP Address

Tags: April 8, 2014 11:11 AM
0 comments

When having multiple gateway it is very useful know which route is used by particular address. So we can know if the routing is work as expected. For this task we can use ip route get command.

Show Selected Route for particular IP

ip route get 8.8.8.8
8.8.8.8 via 192.168.42.129 dev usb0  src 192.168.42.243 
    cache

Share on Facebook Twitter

Backup Partition Using dd on Linux

Tags: 10:46 AM
0 comments

If you want backup entire partition the dd is a very handy tool. It let you create a snapshot of the partition and quickly restore it if you need to. No need to worry about timestamps, ownership, permissions, links, etc.

Backup a Partition (Snapshot)

Make sure the partition is offline or you'll end up with inconsistent result. If it is root partition then you may want to boot via rescue disk and making the backup. Below is an example I'm taking snapshot of my 4GB USB pendrive, the location of the USB pendrive is on /dev/sdc1.

Share on Facebook Twitter

Port Forwarding in Windows

Tags: March 18, 2014 6:04 PM
0 comments

I'm pretty shocked Windows comes with built-in quiet powerful command line tools for port forwarding. The name is netsh. Let say we want to redirect all incoming traffic to IP 1.2.3.4 port 80 to IP 1.2.3.4 port 8080.

prompt> netsh interface portproxy add v4tov4 listenport=80 listenaddress=1.2.3.4 connectport=8080 connectaddress=1.2.3.4

Share on Facebook Twitter

Decode HTML Entities using Javascript

Tags: February 23, 2014 1:13 PM
0 comments

I came into situation where I need to pass some string to Pen Editor instance. The problem is the string is already encoded to HTML entities by PHP's htmlentities(). So, when I have value like This is <strong>strong</strong> element. The Pen editor instance convert it into:

This is <strong>strong</strong> element

Instead of this:

This is strong element

The Solution

The solution is pretty dead simple just inject the string into textarea element and call the value property to get the content instead of innerHTML.

function decodeHtml(html){
  var txt = document.createElement("textarea");
  txt.innerHTML = html;
  return txt.value;
}
If your string already came from textarea like in my case then you don't event need to create a single function.

References

Share on Facebook Twitter

How to Make Text Align Bottom using CSS

Tags: February 21, 2014 5:44 PM
0 comments

What I want to achieve is like picture below.

 

Getting The Job Done

The simple trick to make it works like expected is we need to treat the element as table element. Set display element to table-cell which has vertical-align, the property which what we want to align the text to the bottom. The example below makes H2 element align to the bottom.
h2.bottom {
   display: table-cell;
   vertical-align: bottom;
   height: 60px; /* it's better to make it static */
   line-height: 30px; 
   width: 400px;  /* only as example */
}

Share on Facebook Twitter

Sending On/Off Signal to USB devices in Linux

Tags: February 15, 2014 1:14 PM
0 comments

Some devices like USB modem get stuck when it failed to connect and just hang up forever when trying to dial a number. The solution is unplug and plug it again, weird but it works. But seriously, that is not "a geek way". Rather than plug/unplug we could do it via shell to send the device "on" or "off" signal.

Recognizing the USB Devices

These steps is used to get information about device that we want to send the signal to. A Tool used for this task is lsusb. Here's example of output in my system, make to sure run as root.
$ lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 04f2:b290 Chicony Electronics Co., Ltd 
Bus 001 Device 009: ID 0cf3:3005 Atheros Communications, Inc. AR3011 Bluetooth
Bus 002 Device 018: ID 201e:1022 <-- WE WANT TO SEND SIGNAL TO THIS DEVICE
Bus 002 Device 016: ID 03f0:ae07 Hewlett-Packard 
Bus 002 Device 012: ID 0458:00ee KYE Systems Corp. (Mouse Systems)

Share on Facebook Twitter

Faking Services using Netcat (For Testing Nagios)

Tags: February 3, 2014 4:41 AM
0 comments

Simulating the health of services can be pain if we should install and turn them on/off the real services such HTTP Server, SSH Server, FTP, etc one-by-one on each VM. In this experiment I just faking 2 services which are: HTTP and SSH. Based on this simple topology we would end up with:

Services which Monitored

  • VM 1
    • HTTP
    • PING
  • VM 2
    • HTTP (Simulate the Always 404 Error)
    • PING
  • VM 3
    • HTTP
    • PING
    • SSH

Share on Facebook Twitter

Connecting Two Subnet inside VMs in Linux

Tags: February 2, 2014 2:51 PM
0 comments

This should be applicable to real world (physical devices) not just virtualized environment. The topology is simple:

                 +----------------------------+
                 |          The Host          |
                 |          --------          |
                 |           Router           |
                 +----------------------------+
                       |               |
                    +-----+         +-----+
        192.168.1.1 | br0 |         | br1 | 192.168.1.9
                    +-----+         +-----+
                       |               |
  Mask: 192.168.1.0/29 |               | Mask: 192.168.1.8/29
        +--------------+               +----------+
        |              |                          |
        |              |                          |
 +--------------+      |                   +---------------+
 |     VM 1     |      +----+              |    VM 3       |
 | 192.168.1.2  |           |              | 192.168.1.10  |
 +--------------+           |              +---------------+
                    +--------------+
                    |     VM 2     |
                    | 192.168.1.3  |
                    +--------------+

The Details

The goal is to connecting VM in different subnet so they can talk to each other. Btw, I'm using Virtualbox for this playground. Here's the breakdown from the schema above:
  • The Host had two interface br0 and br1 (Both are virtual)
  • The schema using two subnet 192.168.1.0/29 and 192.168.1.8/29
  • The Host had two bridge interfaces and three TAP interfaces (for each VMs)
  • tap0 for VM 1, tap1 for VM 2 and tap2 for VM 3
  • tap0 and tap1 attached to br0 and tap2 attached to br1

Share on Facebook Twitter

Insert iptables Rule to Specified Position

Tags: 11:36 AM
0 comments

Suppose I already have rules for iptables like this:

$ iptables -L FORWARD -n -v --line-numbers
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1      228 13794 ACCEPT     all  --  vmbr0  ppp0    192.168.1.10         0.0.0.0/0           
2      337 28308 DROP       all  --  vmbr0  ppp0    0.0.0.0/0            0.0.0.0/0
I want to insert my new rule between them (number 1 and 2). Here's how to do it:
$ iptables -I FORWARD 2 -i vmbr0 -o ppp0 -s 192.168.1.11 -j ACCEPT
iptables insertion rules sounds something like "Insert it before number {X}". So in my case I need to put it before number 2 (-I FORWARD 2). Take a look to the result.
$ iptables -L FORWARD -n -v --line-numbers
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1      228 13794 ACCEPT     all  --  vmbr0  ppp0    192.168.1.10         0.0.0.0/0           
2        0     0 ACCEPT     all  --  vmbr0  ppp0    192.168.1.11         0.0.0.0/0           
3      342 28728 DROP       all  --  vmbr0  ppp0    0.0.0.0/0            0.0.0.0/0

Share on Facebook Twitter

How to Create Bridge Networking in Linux

Tags: February 1, 2014 1:47 PM
0 comments

Two user space tools used for creating bridge networking in linux are tunctl and brctl. tunctl used for simulating the network or link layer device and brctl for configuring them.

Create the TAP interface

Issue command below to create tap interface and then activate the tap.
tunctl -t vtap01 -u myuser
ip link set up dev vtap01
# or
ifconfig vtap01 up

Create the Bridge

Issue command below to configure the bridge for using the TAP interface which just created.
brctl addbr vbr01
brctl addif vbr01 vtap01

Assign IP and Routing to the Bridge

Make the bridge identified by others such as another computers or VMs (Assuming the network is 192.168.1.0/30).
ip link set up dev vbr01
ip addr add 192.168.1.1/30 dev vbr01
ip route add 192.168.1.0/30 dev vbr01
or it could be written as:
ifconfig vbr01 up
ifconfig vbr01 192.168.1.1 netmask 255.255.255.252
route add -net 192.168.1.0 netmask 255.255.255.252 dev vbr01
The host at 192.168.1.2 should be able to ping host 192.168.1.1 (via bridge).

References

Share on Facebook Twitter

Test SSH Key Locally Without Server

Tags: January 4, 2014 12:54 AM
0 comments

To test a generated ssh private/public key-pair without having to connect to a SSH server we can use ssh-keygen. Here's the example:

# ssh-keygen -y -f /location/of/the/private-key
References

Share on Facebook Twitter

How To Block IP Address using IPTABLES

Tags: January 3, 2014 11:17 PM
0 comments

Make sure running the iptables command as root. Example below shows how to block traffic coming from IP 1.2.3.4.

# iptables -I INPUT -s 1.2.3.4 -j DROP
Turn on some logging on those rule, we insert it at line two. Assuming the first iptables command was the at line one.
# iptables -I INPUT 2 -s 1.2.3.4 -j LOG --log-prefix "Dropped an As*hole"
References

Share on Facebook Twitter