Sunday, May 27, 2012

Installing Octopress on CentOS 6/RedHat/Scientific Linux

Official Octopress website have user-specific installation procedure prone to many errors due to 'rvm' and 'rbenv'. This is the mostly foolproof method to set-up Octopress correctly on Redhat based distros.

Run these as root:
# yum groupinstall 'Development Tools'
# yum install readline-devel zlib zlib-devel openssl openssl-devel libyaml git python-setuptools
# easy_install Pygments
Pygments is not necessary as it uses pygments.rb. (Thanks to @octopress)

Now, run these as normal user:
$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p320.zip
$ unzip ruby-1.9.2-p320.zip 
$ cd ruby-1.9.2-p320
$ ./configure --prefix=/usr --with-openssl-include=/usr/include/openssl --with-openssl-lib=/usr/lib64/openssl/engines --disable-option-checking --disable-pthread
$ make
If you are using 32-bit, then replace '--with-openssl-lib=/usr/lib64/openssl/engines' to '--with-openssl-lib=/usr/lib/openssl/engines'.

Again, run these as root:
# make install
Again, run these as normal user:
$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress
Now, as root:
# gem install bundler
# bundle install
# rake install
Lastly, as normal user:
$ rake install
Now, follow Configuring Octopress. That's it. You have installed Octopress on your system. Leak: I will soon be moving this blog to Octopress and will be hosting it on GAE.

Saturday, May 26, 2012

Better fonts in Chrome For Linux

Make a file .fonts.conf in your home directory and add this to it:
<match target="font">
  <edit name="autohint" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="hinting" mode="assign">
      <bool>true</bool>
    </edit>
    <edit mode="assign" name="hintstyle">
      <const>hintslight</const>
   </edit>
</match>
Now, restart Chrome to see the changes.

Install Java Browser plugin for Firefox 64-Bit in CentOS/Redhat

Download the latest 64-bit RPM package from main Java homepage. Install it as:
rpm -ivh <package-name>.rpm
And, add the plugin to Firefox with:
# cd /usr/lib64/mozilla/plugins
# ln -s $(find / -mount -name libnpjp2.so)
If 'ln -s $(find / -mount -name libnpjp2.so)' fails, then, first find the file 'libnpjp2.so' and supply the path as:
# ln -s <path-to-libnpjp2.so>

Restart your browser and you will have the working Java plugin for Firefox.

Install Log.io on CentOS

Searching for a simple online log viewer, I found log.io. Documentation has a recipe to install log.io on Ubuntu 11.10 but it doesn't match uniformly for CentOS. Seems like many things are hard-coded. So, I began to hack into it to make it working and I succeeded.

Installation Procedure:
# yum install gcc make openssl-devel git
# mkdir ~/downloads 
# cd downloads 
# wget "http://nodejs.org/dist/v0.6.11/node-v0.6.11.tar.gz" 
# tar -xzvf node-v0.6.11.tar.gz
# cd node-v0.6.11/ 
# ./configure
If it complains about missing libraries or anything else and doesn't succeeds, install the required libraries using Yum.
# make
# make install
# ln -s /usr/local/bin/node /usr/local/bin/nodejs
# wget http://npmjs.org/install.sh
# chmod +x install.sh
# ./install.sh
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
# rm -f /usr/bin/npm
# ln -s /usr/local/bin/npm /usr/bin/npm
# useradd -d /home/logio logio
# usermod -G adm logio
# npm config set unsafe-perm true
# npm install -g --prefix=/usr/local git://github.com/NarrativeScience/Log.io.git
# chmod -R 777 /var/log/log.io/

It's done. Now, start the server using:
# log.io server start

The server is now started. Allow access to port 8993 as:
# iptables -A INPUT -p tcp --dport 8993 -j ACCEPT

Hurray!. Head over to http://:8993 and see the power of nodejs.
Similarly, install Log.io on another machine and start the harvester with:
# log.io harvester start
Tested on CentOS 6.

Install latest Skype on CentOS

Download static archive of Skype from main skype website.The latest version while writing this tutorial was skype_staticQT-2.2.0.99.To download, you can do:
# cd /tmp
# wget http://www.skype.com/go/getskype-linux-beta-static
# cd /opt
# tar jxf /tmp/skype_static-2.2.0.99.tar.bz2
# rm /tmp/skype_static-2.2.0.99.tar.bz2
# ln -s skype_staticQT-2.2.0.99 skype
To make it easy to launch Skype and remove shared library related errors, do this:
# ln -s /opt/skype /usr/share/skype
# ln -s /opt/skype/skype /usr/bin/skype
# ln -s /usr/lib/libtiff.so.3 /usr/lib/libtiff.so.4
Even if you are running 64 bit CentOS version, you should install some 32 bit libraries as:
# yum install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 libSM.i686 libXi.i686 libXrender.i686 libXrandr.i686 freetype.i686 fontconfig.i686 zlib.i686 glib2.i686 libstdc++.i686 libtiff.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686 
And, if you have CentOS media available:
# yum --disablerepo=\* --enablerepo=c6-media install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 libSM.i686 libXi.i686 libXrender.i686 libXrandr.i686 freetype.i686 fontconfig.i686 zlib.i686 glib2.i686 libstdc++.i686 libtiff.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686 

Now, you should have a working Skype. Run it as:
# skype
Tested on CentOS 6.2

Friday, May 25, 2012

Delta RPMs on Yum

Delta, in sense of file, refers to the difference between two versions of the file. So, if you have a file and its delta, you can create a new file with all the changes included.

Delta RPMs are exactly the same. Consider a package 'yum-1.2.30-x86-64.rpm' and another updated package 'yum-1.2.31-x86-64'. A delta RPM of this package will be able to recreate the new updated Yum package from the older package available in the system. Since Delta RPMs are just the difference in two packages, they are small in size(in most cases). So, delta RPMs are useful if you have a congested, slow or limited bandwidth.

Enabling the use of Delta RPM in Yum:
We need 'yum-presto' plugin to enable delta RPMs. Install it as:
# yum install yum-presto
Now, try updating your system as:
# yum update
You will see that the download size will reduce dramatically and updates will be faster. That's how Delta RPM works.

Tested on CentOS 6.2.

Zypper implements delta RPMs by default. So, openSUSE users need not to be worry and there is nothing to enable for openSUSE systems.

SSH : Allow only certain users to log in

There are numerous user accounts that exist in a Linux system. You will not want to allow every user to log in via SSH.
Let's talk about the scenario: I have many users in my Linux box but real person-related users are root, alice and bob. So, to allow only them to connect via SSH, edit '/etc/ssh/sshd.conf' and add the following line at the end of the file:
AllowUsers root alice bob

Allow Root Login by SSH Keys only

IF you want to allow root login via SSH keys only while disabling password-based login, edit /etc/ssh/sshd.conf to reflect following change:
Original:
PermitRootLogin yes
Change:
PermitRootLogin without-password

Thursday, May 24, 2012

Install Flash Plugin for Firefox installed from tar.bz2 archive

If you have installed Firefox from the official download (firefox--.tar.bz2) at /opt or similar location and if you are using 64bit version of Linux, then the 64 bit version of Flash Player will not work with Firefox. The solution is to use 32bit version of flash plugin. Here is how you do in Yum based systems:
# rpm -ivh http://linuxdownload.adobe.com/linux/i386/adobe-release-i386-1.0-1.noarch.rpm 
# yum remove flash-plugin
# yum --disablerepo=adobe-linux-x86_64 --enablerepo=adobe-linux-i386  install flash-plugin
If you have a running Firefox window, restart it and you will get your flash plugin back. Tested on CentOS 6.2.

Wednesday, May 23, 2012

Gtk-WARNING in Firefox: Unable to locate theme engine

If you are getting warnings like these:
(firefox:4486): Gtk-WARNING **: Unable to locate theme engine in module_path: "clearlooks"
Install package 'gtk2-engines.i686'.

Tuesday, May 22, 2012

Enable Caching in Yum

It is a good idea to enable caching in Yum as it keeps downloaded packages locally and is useful if you have slow connections. The default behavior is to delete downloaded packages. To enable caching, turn 'keepcache=0' into 'keepcache=1' in /etc/yum/yum.conf as:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
...
...
So, all the downloaded data will reside in 'cachedir' location.

Install latest VLC on CentOS 6

RPMForge provides latest VLC version for CentOS system. Install corresponding RPMForge repository as:

64-bit:
rpm -ivh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
32-bit:
rpm -ivh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Now, install VLC as:
yum install vlc
Hurrah! You have a working best media player.

Install RPM with Yum

You can install RPM packages with 'rpm' command but it doesn't resolve dependencies. So, to automatically install dependencies with the package, yum can be used as:
yum install package_name.rpm
If you are getting errors like "Package is not signed", do this:
yum --nogpgcheck install package_name.rpm

Fix: "Cannot retrieve repository metadata" for Yum

# yum provides system-config-network
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.vr-zone.com
 * extras: centos.vr-zone.com
 * updates: centosz4.centos.org
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
This problem can be fixed by uncommenting 'baseurl' in repository configuration file. For example: File:CentOS-Base.repo Original:
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
..
..
..
Change to:
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
..
..
..
If this doesn't solve the problem, then it is something to do with network connection.

Enabling kernel modules at boot time

To maintain persistent kernel module, create a file called 'modulename.modules' in /etc/sysconfig/modules/ and insert corresponding command. For example, to load 'rt3070sta' module, I need to find the location of device 'ra0'. Find it using:
# find / -name 'ra0'
/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/net/ra0
Now, I will add this to rt3070sta.modules:
#!/bin/sh

if [ ! -c /sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3/net/ra0 ] ; then
        exec /sbin/modprobe rt3070sta >/dev/null 2>&1
fi

Monday, May 21, 2012

bash: cd: Input/output error

I was trying to mount a partition on folder 'localdisk'. It mounted successfully but on 'cd'ing to the folder, it said:
bash: cd: localdisk: Input/output error
I found that 'localdisk' was a file and not a directory. I wonder why 'mount' was accepting file as mount point.

Mounting NTFS partitions in CentOS 6

Install fuse-ntfs-3g from RPMForge as:
wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/fuse-ntfs-3g-2010.10.2-1.el6.rf.x86_64.rpm
rpm -ivh fuse-ntfs-3g-2010.10.2-1.el6.rf.x86_64.rpm
Now, NTFS partitions can be mounted using 'mount'. For example:
mount -t ntfs-3g /dev/disk/by-label/blahblahblah /windows/e

Using Redhat/CentOS DVD media as Yum repository

Installing from downloaded media is important for slow as well as limited connections. Anyway, I found a way to use CentOS media as a local yum repository. Here is how it is done:
Insert CentOS media onto your drive. Then, find the mount point where the media was mounted. It should be under /media. If not, mount the media onto a permanent location. Edit /etc/yum.repos.d/CentOS-Media.repo as:
vi /etc/yum.repos.d/CentOS-Media.repo
Modify the line containing baseurl to suit your environment i.e. the mount point. Also, note the repository name. For CentOS 6.2, it is 'c6-media'. Make sure 'enabled' is set to 1. Save the file using [escape]:x Now, run any yum command like:
yum --enablerepo=c6-media --disablerepo=\* install gcc
Yum priorities can also be used to give more priority to local installation media.

Determing Linux/Unix kernel version

Determining kernel version is important for different Linux/Unix related tasks.It can help in diagnosing, upgrading as well as installing device drivers.
Easiest command is to run is 'uname' as:
uname -r
/proc/version also provides details about kernel version. Cat it using:
cat /proc/version

Saturday, May 12, 2012

A journey to FreeBSD

I thought to write about FreeBSD even though this blog covers mostly about Linux.
I started using FreeBSD a year ago. When I first tried it, I was way too confused and was feeling like getting a tea(FreeBSD) when you are addicted to coffee(Linux).

Then, I got to read FreeBSD handbook. I read everything right from beginning to end. Then, I printed the whole FreeBSD handbook and started playing with FreeBSD on a real system. After this, everything changed. I started to love FreeBSD much than any other operating system.

I recommend everyone reading this to try FreeBSD even if you uncomfortable with Linux. If you are really uncomfortable with CLI, try using PC-BSD (PC-BSD is to FreeBSD as Ubuntu is to Debian).

FreeBSD cannot be called Unix due to legal reasons but I don't think anyone will sue you when you are thinking that it is really a Unix system.

Try installing FreeBSD on VirtualBox or similar platforms to make sure you don't mess with your valuable data.

You should also stop thinking that FreeBSD runs Linux applications directly. They are different. There is a Linux Binary Compatibility for FreeBSD to run Linux applications which is not a sort of platform virtualization. So, performance is pretty realistic and matching with that of Linux.

Another thing I like about FreeBSD is 'lagg'. This allows you to combine two or more network connections for failover protection or load balancing. Linux too has 'bonding' but I find 'lagg' easier to use.

The last thing worth mentioning is pfSense which, in my view, is the most easiest and effective firewall distribution. The web interface pretty rocks. And, the best part of pfSense is that it is based on FreeBSD.

Some Useful Links:
http://www.freebsd.org/doc/handbook/
http://www.pcbsd.org/
http://pfsense.org/

Private Key Conversions

Convert OpenSSH private key to Putty ppk format:
Step 1:Download and run Puttygen.
Step 2:Select "Import Key" From "Conversions" menu.
Step 3:Type your passphrase if you have set them.
Step 4:Click "Save private key".

Convert Putty ppk format to OpenSSH format: 
Step 1:Select "Load private key"
Step 2:Select "Export OpenSSH key"

Convert Putty ppk format to ssh.com format:
Step 1:Select "Load private key"
Step 2:Select "Export ssh.com key"

Solving "/bin/bash^M: bad interpreter: No such file or directory"

If you are getting errors like "/bin/bash^M: bad interpreter: No such file or directory", then I am a mind-reader and can say that you have edited this script on a Windows system. Error looks like:
# ./mysql_backup.sh
-bash: ./mysql_backup.sh: /bin/bash^M: bad interpreter: No such file or directory
You can solve this error by using "dos2unix" as:
# dos2unix mysql_backup.sh

Determine Directory Size In Linux with 'du'

'du' is an acronym for Disk Usage. So, if you want to find the size of a directory in Linux/Unix:
du <directory_name>
A more human-readable format can be generated using -h switch which outputs size with M,G and similar postfix.
du -h <directory_name>

Thursday, May 10, 2012

Check the progress of 'dd'

Even though I call 'dd' a disk destroyer, I have to use this regularly. Once, I had to copy a whole disk to another disk and was waiting for it to finish. Then, I found 'SIGUSR' signal that could be sent to a process to output some relevant information ('dd' in our case).

While 'dd' is running, open a new terminal. First let's get the PID:
# ps -A|grep dd
Then, do this:
# kill -USR1 <pid>
Now, see the terminal where 'dd' is running. You would get some details about the transfer progress. If you are really impatient, you can run this command every 20 seconds with 'watch':
watch -n 20 kill -USR1 <pid>

Convert openSUSE DVD ISO into USB image

To convert openSUSE 12.1 DVD ISO (64 Bit) to an ISO that can be dded"to a USB drive, do this:
# zypper in syslinux
# isohybrid openSUSE-12.1-DVD-x86_64.iso
Now, use SUSE Studio ImageWriter to write this ISO or dd to your usb drive.

Battery Status From Linux Command Line

When you are running a CLI or a minimal desktop environment on a laptop/netbook/notebook, it is necessary to check battery status for some reasons. 'acpi' is a system tool to provide easy human-readable battery status and information. For installing 'acpi' on Ubuntu or Debian systems, type this:
apt-get install acpi
You must be root to do that. Use 'sudo' for Ubuntu/Mint systems. Now, type 'acpi' to see battery status. I got this with a fully charged battery:
# acpi
Battery 0: Full, 100%, rate information unavailable

List all Cron Jobs From All Users

To list all cron entries from all users:
# for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
This is meant to be run as root.