Wednesday, February 17, 2010

Remove old images of Linux (Ubuntu) kernel

Development of Linux is quite fast paced and new versions of kernel are released pretty frequently. I have a dual boot desktop with Ubuntu and Windows XP. With each update grub boot menu keeps on growing and I have to make Windows XP default OS as desktop is used by my 8 year son as well. Each version of kernel takes up > 100MB space, though that is not a big worry with huge storage available at much cheaper price.

The unused (older) versions of kernel can be removed safely. Usually I prefer to keep the last version along with "last - 1", to be on safer side so that I have something to fallback upon if something goes wrong with the latest kernel. To remove a version of kernel go to Synaptic Package Manager and search for linux-image and select the ones you want to remove.



You'll get an option to remove completely (Mark for Complete Removal), that will get rid of everything including configuration files used by that package. Before removing kernel make sure to not remove the current version as that will make the system unusable. Use uname -a command to know the currently used version of kernel. Output of this command looks like below on my machine-

vinod@vinod-desktop:~$ uname -a
vinod@vinod-desktop:~$ Linux vinod-desktop 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 02:39:34 UTC 2010 x86_64 GNU/Linux

You can also find and remove linux-headers using this simple method.

Wednesday, December 23, 2009

Start Apache as service in Linux (Fedora)

The Apache HTTP server is installed by default in all Linux distributions and it is configured to run as service. I usually prefer to install Apache from source instead of using the default one. After installing Apache I want to run that instance as service so that it can be restarted automatically whenever machine is rebooted. This can be achieved easily by modifying /etc/rc.d/init.d/httpd file, which is configured to run the Apache installed with OS.

Comment the following section, though it is not required but I prefer to keep all configuration at one place


if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
Modify the following lines-
apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
to point towards your Apache installation
apachectl=/opt/apps/httpd-2.2.14/bin/apachectl
httpd=${HTTPD-/opt/apps/httpd-2.2.14/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/opt/apps/httpd-2.2.14/logs/httpd.pid}
Now your custom Apache instance will be started by OS instead of the default one.

Tuesday, September 22, 2009

403 Forbidden with wget

We have few shell scripts, which access some HTTP URLs using wget as part of some task. wget failed to access some of the URLs with error message like below-

Resolving repo1.maven.org... 38.97.124.18
Connecting to repo1.maven.org|38.97.124.18|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2009-09-22 11:38:53 ERROR 403: Forbidden.

Though all failed URLs were accessible using browsers from same machine / user account. Reason of this failure is that wget does not send any information about itself (agent information) i.e. name and version of the browser etc. and some servers do not entertain requests without agent information. A simple workaround for this problem is to add a dummy agent information as shown below-
wget -U MyBrowser/1.0 URL_TO_DOWNLOAD
Now everything will work as expected.

Sunday, September 06, 2009

Few more notes about Redmine installation

This is in continuation to earlier post Getting started with Redmine where I jotted down my experience about installation of Redmine and other required packages. When I attempted to install Redmine in another machine with slightly different configuration and in different manner, I stumbled upon few more facts.

  • zlib-devel package should be installed and that too before installing ruby. Though ruby, rubygem and rake will be installed without any problem but installation of rails (gem install rails) will fail due to lack of zlib-devel.
  • If PostgreSQL is installed from a RPM package, say yum install postgresql-server. Then PostgreSQL installation will not have pg_config file and installation of PostgreSQL adaptor for ruby (gem install pg) will fail as installer script uses pg_config during installation. In absence of this file PostgreSQL adaptor will fail with an error like below-

        [vinod@localhost opt]$ gem install pg
        Building native extensions. This could take a while...
        ERROR: Error installing pg:
        ERROR: Failed to build gem native extension.

        /opt/ruby-1.8.7/bin/ruby extconf.rb
        extconf.rb:1: command not found: pg_config --version
        ERROR: can't find pg_config.
        HINT: Make sure pg_config is in your PATH
        *** extconf.rb failed ***
        Could not create Makefile due to some reason, probably lack of
        necessary libraries and/or headers. Check the mkmf.log file for more
        details. You may need configuration options.

        Provided configuration options:
            --with-opt-dir
            --without-opt-dir
            --with-opt-include
            --without-opt-include=${opt-dir}/include
            --with-opt-lib
            --without-opt-lib=${opt-dir}/lib
            --with-make-prog
            --without-make-prog
            --srcdir=.
            --curdir
            --ruby=/opt/apps/ruby-1.8.7/bin/ruby

    Gem files will remain installed in /opt/ruby-1.8.7/lib/ruby/gems/1.8/gems/pg-0.8.0 for inspection.
    Results logged to /opt/ruby-1.8.7/lib/ruby/gems/1.8/gems/pg-0.8.0/ext/gem_make.out
  • OpenSSL develipment headers are required by Phusion Passenger. Without this Passenger installation will fail with an error like-
        * OpenSSL support for Ruby... not found

        * To install OpenSSL support for Ruby:
        Please (re)install Ruby with OpenSSL support by downloading it from http://www.ruby-lang.org/.


    To overcome this first install openssl-devel package
          yum install openssl-devel

    Then execute following script from Ruby installation-
          /opt/ruby-1.8.7-p174/ext/openssl/ruby extconf.rb --with-openssl-dir=/usrl/local/ssl

    Now passenger installation will succeed.
I think there were few more things I stumbled upon, but lost their track during all this exercise.

Friday, August 07, 2009

Yum hangs on Fedora 11 behind proxy

Yesterday I installed Fedora 11 on a new machine from a live CD. As usual I tried to update the system just after installation. This machine was behind a proxy server and http_proxy variable was configured to let yum get through proxy server. Yum hanged just after emitting two line on the console-

    [root@localhost ~]# yum update
    Loading "refresh-packagekit" plugin
    Setting up Package Sacks


Even after 1 hour it did not came out and I can't kill it using ctrl+c, killing the process from another terminal was the only option. Running yum in verbose mode also does not print any useful information-

    [root@localhost ~]# yum -v update
    Not loading "blacklist" plugin, as it is disabled
    Loading "refresh-packagekit" plugin
    Not loading "whiteout" plugin, as it is disabled
    Config time: 0.082
    Yum Version: 3.2.22
    Setting up Package Sacks


The wget http://www.yahoo.com/ was successfully downloading the web page that means internet connectivity and proxy was not an issue. Then I looked inside /etc/yum.repos.d/fedora.repo, to get some clues. All URLs mentioned in that file were using https, so I tried to do wget over https-

    [root@localhost ~]# wget https://www.yahoo.com/
    --2009-08-07 16:35:11--  https://www.yahoo.com/
    Resolving www.yahoo.com... 69.147.76.15
    Connecting to www.yahoo.com|69.147.76.15|:443...


and that too hanged after emitting above text. Now I see why yum is not able to update. Changing URLs from https to http in /etc/yum.repos.d/fedora.repo took yum slightly ahead from where it was hanging earlier-

    [root@localhost ~]# yum -v update
    Not loading "blacklist" plugin, as it is disabled
    Loading "refresh-packagekit" plugin
    Not loading "whiteout" plugin, as it is disabled
    Config time: 0.082
    Yum Version: 3.2.22
    Setting up Package Sacks

    fedora/metalink                                          |  10 kB     00:00
    fedora                                                   | 3.8 kB     00:00
    fedora/primary_db                                        | 8.4 MB     00:09


Now yum hanged after emitting above-mentioned text. Changing URLS from https to http in /etc/yum.repos.d/fedora-updates.repo made update successful.

This https issue seems to be specific to Fedora 11, as I never faced any difficulties on updating previous Fedora releases (6, 7, 8 and 9).

Tuesday, August 04, 2009

Updating a Linux box behind proxy server

Recently I had to update a Linux (Fedora 9 to be precise) box, which was behind a proxy server. To get through the proxy server I configured relevant environment variables as described here. After executing 'sudo yum update' command system seems to be hanged after emitting following line on the console-

Loaded plugins: refresh-packagekit

After a long wait yum failed with following error message on console-

[vinod@localhost ~]# sudo yum update
Loaded plugins: refresh-packagekit
Could not retrieve mirrorlist http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-9&arch=i386 error was
[Errno 4] IOError: <urlopen error (110, 'Connection timed out')>
Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora. Please verify its path and try again


OK, so yum was not able to get through proxy, but when I tried to access the same URL using wget-

[vinod@localhost ~]# wget http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-9&arch=i386

it was able to access it. Then what could be wrong :-/

After pondering for sometime, I realized that proxy configuration was done using a non-root user while yum was running as root (due to sudo). Environment variables configured for a user are not carried forwarded (to another user) by Linux when user is changed using su or sudo command. Configuring the proxy as root solved the problem and yum successfully updated system.

Monday, August 03, 2009

Getting started with Redmine

For sometime I was looking for a project management software, which can provide an integrated view of most of the project related artifacts/activities. Redmine was the most impressive tool, I came across. It has issue tracking, wiki, forum, documents, integration with third party tools (source repositories, LDAP etc.), plugin to integrate with Hudson and many more features. It has plugin based architecture, so possibilities are almost endless.

Redmine is written in Ruby (Ruby on Rail) and I know nothing about that other than spelling :-) I had to install several packages to get started with it. Redmine stores its data in a database and when it comes to open source DB, PostgreSQL is always my first choice. As a practice I prefer to serve all web applications through Apache and here I found an Apache module called Passenger, which can serve Ruby applications.

Here are my notes, which I took during installing Redmine and supporting applications.

  1. Install PostgreSQL for Linux
          $ ./postgresql-x.x.x-x.bin --mode text

    Follow the installer instructions to complete the installation. Make sure that PostgreSQL accepts connections from other than 'localhost' else you can't connect to DB from any other machine. This can be done by editing 'pg_hba' configuration file.

  2. Install Ruby, Redmine needs ruby 1.8.7-
          $ tar zxvf ruby-1.8.7-p174.zip
          $ cd ruby-1.8.7-p174
          $ ./configure --prefix=/opt/redmine/ruby-1.8.7
          $ make
          $ make install


    Add ruby to your classpath before executing further installation steps.

  3. Install ruby-gems, say rubygems-1.3.4
          $ unzip rubygems-1.3.4.zip
          $ cd rubygems-1.3.4
          $ ruby setup.rb

  4. Install rake
          $ unzip rake-0.8.7.zip
          $ cd rake-0.8.7
          $ ruby install.rb

  5. Install rails (Ruby On Rails) version 2.1.2 (required by Redmine)
          $ gem install rails -v 2.1.2

    The GEM needs internet connectivity to download and install the packages. Though there are ways to install packages locally, after downloading them manually. As I am new to Ruby so preferred the easiest installation method.

  6. Install PostgreSQL adapter for Ruby
    Add PostgreSQL's 'bin' directory in PATH before executing following command-
        $ gem install pg

  7. Install redmine

    • Unzip the downloaded archive
      $ tar zxvf redmine-0.8.4.tar.gz

    • Create 'redmine' database user
      CREATE ROLE redmine LOGIN PASSWORD 'redmine' NOSUPERUSER NOINHERIT CREATEDB NOCREATEROLE;

    • Create 'redmine' database
      CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;

    • Define PosgtreSQL DB in '/opt/redmine/redmine-0.8.4/config/database.yml'
             production:
               adapter: postgresql
               database: redmine
               host: localhost
               port: 5432
               username: redmine
               password: "redmine"

    • Create the database structure, by running the following command under the redmine installation directory. It will create tables and an administrator account.
          $ rake db:migrate RAILS_ENV="production"

    • Insert default configuration data in database, by running the following command:
          $ rake redmine:load_default_data RAILS_ENV="production"

  8. Install Passenger module to enable Apache to serve ruby applications
        $ tar zxvf passenger-2.2.4.tar.gz
        $ cd passenger-2.2.4/bin
        $ export APXS2=/opt/redmine/apache-2.2.11/bin/apxs
        $ ./passenger-install-apache2-module

  9. Configure Apache to server redmine or any other ruby application using passenger
    To publish a rubby application under a sub-uri, create a symbolic link to application's public directory under web root directory. Thats the way passenger works, pointing directly to application's public directory will not work here.

        $ ln -s /opt/redmine/redmine-0.8.4/public redmine

    Here is a sample configuration text from Apache's httpd-vhosts.conf file to serve Redmine-

        NameVirtualHost *:80

        LoadModule passenger_module /opt/redmine/passenger-2.2.4/ext/apache2/mod_passenger.so
        PassengerRoot /opt/redmine/passenger-2.2.4
        PassengerRuby /opt/redmine/ruby-1.8.7/bin/ruby

        <VirtualHost *:80>
            ServerAdmin webmaster@mydomain.com
            ServerName redmine

            DocumentRoot "/opt/apache-2.2.11/htdocs"
            RailsEnv production
            RailsBaseURI /redmine

            ErrorLog "logs/error_log"
            CustomLog "logs/access_log" common

            <Directory "/opt/redmine/redmine-0.8.4/public">
                Options FollowSymLinks
                AllowOverride None
                Order deny,allow
                Allow from all
            </Directory>
        </VirtualHost>
Now Redmine is available for action. Next steps could be configuring to integrate with LDAP and few more things or installing some plugins to enhance the functionality. Next I am looking for ways to migrate issue tracker from Bugzilla to Redmine, to have everything under one roof.

Saturday, June 06, 2009

Spell checking with FCKeditor

FCKeditor is an excellent tool for providing rich text editing experience on web. Best part is that it works almost out of the box, there is very little to configure. Spelling checking is an exception here. Though spell checking also works out of the box, but with Internet Explorer only, which is not the only browser out there. Recently I used FCKeditor in a Java web application and had to integrate the spell check functionality as well. The spellar pages + aspell + PHP combination works pretty well for this task. FCKeditor comes with perl, PHP and Cold Fusion scripts for spell checking, I used PHP. In this post I will try to outline the steps required to make spell check working in FCKeditor.

1. Install PHP
PHP installation (I did it on Fedora) is pretty simple, just download the source and execute following command sequence-

tar –xvzf php-5.2.9.tar.gz
cd php-5.2.9
./configure --prefix=/path_to_install \
         --with-apxs2=/apache_install_dir/bin/apxs \
         --disable-cli \
         --disable-cgi
make
make install
For more details about PHP installation see PHP documentation.

2. Integrate PHP with Apache
Apache needs to be instructed to invoke PHP interpreter for all requests for PHP files ('.php' extension). First we need to include PHP module by adding following line in /apache_install_dir/conf/httpd.conf-
LoadModule php5_module modules/libphp5.so
In same configuration file add PHP handler-
<Directory "/apache_install_dir/htdocs">
     . . . .
     . . . .
     <FilesMatch \.php$ >
          SetHandler application/x-httpd-php
     </FilesMatch>
</Directory>
3. Install aspell and dictionaries
Aspell provides dictionaries for all major world languages. Installation of aspell and its dictionaries is fairly straightforward. After downloading aspell and dictionaries execute following command sequence for each of the downloaded archive-
tar –xvzf archive_name.tar.gz
cd archive_name
./configure
make
make install
4. FCKeditor Configuration
By default FCKeditor is configured to use 'ieSpell', change it to use 'SpellarPages' instead. Also make sure it uses PHP and does spell checking in FireFox. Following properties needs to be changed in 'fckconfig.js'-
FCKConfig.SpellChecker = 'SpellerPages' ;
FCKConfig.SpellerPagesServerScript = 'server-scripts/spellchecker.php' ;
FCKConfig.FirefoxSpellChecker = true ;
Now configure the language and 'aspell' path in 'spellchecker.php'-
$aspell_prog = 'aspell';
$lang = 'en_US';

Now we are ready to test the application and see spell check in action. All software versions being used for this post are outlined below-
  • Apache 2.2.11
  • PHP 5.2.9
  • FCKeditor 2.6.4 (with bundled Spellar Pages)
  • Aspell 0.60.6
  • Tomcat 6.0.18
  • Java 6 update 13
  • Fedora 9
To know more about using Apache to serve Java application see Apache in from of Tomcat and JBoss.

Sunday, May 17, 2009

Install Linux (Ubuntu) from USB drive

Recently one of our old laptop was crashed, so I had to re-install the operating system. We lost the Windows XP CD came with it, so installed XP from another CD. New installation was not ready to accept the keys mentioned on the sticker at the bottom of the laptop. So I decided to install Ubuntu 9.04 using a USB drive. This document has detailed information about USB installation. As no Ubuntu installation was available at that time, so creating a boot USB drive from downloaded ISO file was the only option and UNetbootin did the task nicely on Dell Latitude D630. But IBM ThinkPad R51 refused to boot from the USB disk (Kingston DataTraveler 4GB), anyway I was prepared for such failures and tried with another USB drive (Sandisk Cruzer micro 2GB), which worked well. On first boot system recognized my wireless network and connected instantly along with nice sound blowing from speakers.

My experience with USB installation was pretty nice and it took just 15 minutes for the whole exercise. Ubuntu installation was much easier then Windows XP.

Friday, September 26, 2008

Proxy setting on Linux

If your Linux box is behind a proxy server then to access the internet, proxy configuration will be required. The 'http_proxy' and 'ftp_proxy' environment variables hold the information about proxy server. Just execute the following commands-

$export http_proxy=http://<proxy-server-ip>:<port>
$export ftp_proxy=http://<proxy-server-ip>:<port>


Now wget, yum, apt-get etc. can use these variables to access http/s and ftp URLs out of office LAN. If proxy server needs authentication credentials then pass them as shown below-

$export http_proxy=http://<user>:<password>@<proxy-server-ip>:<port>
$export ftp_proxy=http://<user>:<password>@<proxy-server-ip>:<port>


To avoid executing these commands every time you login or reboot the machine then add them in ~/.bashrc file.

Tuesday, July 29, 2008

SVN with Apache + LDAP

We have been using CVS at work for long, though personally I am a big fan of SVN. Lately we thought to catch up with the SVN buzz and I was asked to have a Proof Of Concept before we officially move to SVN. Installation of SVN with Apache was pretty straightforward. Though LDAP integration was also simpler but at times it failed without any obvious reasons. Here are the steps for the entire process on Windows XP-

1. Install Apache 2.2.
2. Install SVN 1.5 by unzipping the distribution.
3. Add SVN\bin folder to PATH.
4. Copy mod_dav_svn.so to modules directory of Apache.
5. Add following line in Apache conf file-
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so

# Following are required for LDAP authentication
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule ldap_module modules/mod_ldap.so

6. Download [svnindex.css and svnindex.xsl] from http://svn.collab.net/repos/svn/trunk/tools/xslt/
and put them in 'htdocs' folder of Apache. This will do nice listing of SVN contents.

7. Add the repository location in http conf file, this will have LDAP auth as well

#Location of repository
<Location>
DAV svn

SVNParentPath C:\svn
SVNListParentPath on
SVNIndexXSLT "/svnindex.xsl"

AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative off
AuthName "My SVN Setup"
AuthLDAPURL ldap://host:3268/dc=X,dc=Y?sAMAccountName?sub?(objectClass=user) NONE
AuthLDAPBindDN myUserID
AuthLDAPBindPassword myPassword
Require valid-user
</Location>

7. Run 'httpd' command from Apache

VOILA! YOU ARE DONE

I gave it a try on Fedora 4 as well, which comes with Apache 2.2 and SVN 1.4 pre-installed. Only thing that was missing was there 'mod_dav_svn'. Getting that to with YUM is pretty simple, just do-
yum install mod_dav_svn

Here we were using Active Directory as our LDAP server. Initially I used the port 389 in the AUthLDAPURL shown above and it worked fine for first 2 weeks but after that it failed without any obvious reasons with this error message in Apache log files-
[ldap_search_ext_s() for user failed][Operations Error]

It made it to work for brief periods by re-starting the Apache. Re-starting is not an option in production. After googling for some time I found suggestions to use port 3268 instead of 389. More than 2 weeks has been passed since I switched to port 3268 and it is working fine till date :-)

My next step will be to convert some CVS repositories to SVN. Will update soon about the results of this conversion.

Friday, August 04, 2006

Switched to 64bit Linux

I bought a new shiny AMD Athlon64 3800+ 64bit machine with NVIDIA GeForce6100 GPU. After inserting the Ubuntu 6.06 CD the installation was a breeze, much simpler than the Windows one. Ubuntu detected all hardware without any problem.

The honeymoon ended in 10 minutes when system refused to accept any input from keyboard and mouse. Hard re-boot was the only option to get out of the deadlock. System was never ran more than 15 minutes at a stretch. Google search hinted about possible graphics card driver issue.

The software install and update feature of Ubuntu is great, far better than Windows updates. This article has a good info, how to install NVidia binary drivers. After installing latest graphics drivers system is running flawless.

Now I have abandoned the Windows and switched over to Linux :-)