Ubuntu 10.04 Boot Sequence

Just installed Ubuntu 10.04 Lucid Lynx (a Linux Operating System) – but want to default boot into Windows (or your alternate OS)?

Many people struggle to change the boot sequence on this version of Ubuntu, because this version uses Grub 2 – a newer version of the Grub boot loader.

Okay, technical details aside, it’s really easy to change the boot sequence.

This is what you need to do:

1. When the bootup menu pops up asking which operating system you would like to boot into, note the position of the Windows option (e.g. on my computer, it is on the 5th position).
2. Let the default Linux operating system log in (this would happen automatically
2. Once you enter your Ubuntu username and password (if you have set a password), and come to welcome screen, go to

Applications > Accesories > Terminal

3. In the terminal, key in this magic formula (this will lead you to the file you need to modify):

sudo gedit /boot/grub/grub.cfg

(You may be prompted to enter a password for permission to change this file. Enter your regular login password)

4. Look for the line which reads as follows:

set default=”0″

5. Change the “0” to the position of your Windows login
(Since the list is numbered starting 0, subtract 1 from the position of Windows login. E.g. Since my Windows login is on position #5, I would set this to:

6. Press the save button (or Ctrl-S)

7. Restart your computer, and you should be good to go!

Hope you find this helpful!

Posted in Tech. Tags: , . View Comments »

Why an in-home server can slow down the network

Even with the best (in-home) technologies, the server can hog your home network, and bring everything down to a crawl. Case in point, my 5MBPS connection started to feel like dialup, as I browsed in slow motion.
How can this happen? And how do you prevent this?

High active ip connections.

Here is what can happen with a poorly configured server:

Let’s say you setup a Linksys WRT-64G router which you use at home, with your new webserver on a lan port. Over time, your server will establish new connections with users (based on the apache settings). These connections, and the router timeout limits, can severely hamper the overall network performance.

The reason? Connections aren’t killed after they are used. And the router runs out of memory trying to keep track of all the connections.

The really odd symptom, is that when you open a new browser window, it struggles to connect to a website. But your other windows are running better.

Here is a simple remedy to the problem:

1. Router setting changes:

First lets check if your router is complaining:

a. Check in your router status page for the number of Active ip connections. Typically this should not be more than 30 per computer using the router.

b. If the Active ip connections, are high (500+), then check if most of the active connections are from your server (in dd-wrt, you can do this by going to Status > Click on the number against ‘Active IP Connections’.

c. If you find it is your server, you’ve hit jackpot. Time to set things straight:
Set the router to terminate unnecessary persistent connections.
You can do this by reducing the TCP and UDP timeouts (I recommend TCP timeout 600 seconds and UDP timeout 120 seconds).

This will prevent the router from keeping unnecessary connections on.

2. Server setting changes:

Apache likes to setup a lot of connections so you get a decent amount of multi-user performance from your website. If yours is a new website, likely it will take time to get bombarded by too many users.
Given that you want to share your home network with your server, these settings will help reduce the demand from the server:

a. Go to the apache config file (in ubuntu, it is: /etc/apache2/apache2.conf), and modify the mpm worker and preform modules as follows. (If you already have the same Server settings, then considering reducing them further)

<IfModule mpm_prefork_module>
    StartServers         5
    MinSpareServers      5
    MaxSpareServers      10
    MaxClients          100
    MaxRequestsPerChild  500

<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadsPerChild      25
    MaxRequestsPerChild   0

b. Restart your apache server (in Ubuntu: sudo apache2ctl restart)

That’s it! And your apache server will run much lighter now – especially with fewer extra servers lurking around.

3. Check if everything looks good:

You should now see a drop in number of active ip connections.
Also, soon your in-home network will get back to its peppy self.

I hope this helps you!

The mysql slow query log

The first step to tuning your database, is to find out what’s running slow.

I recommend doing tuning your queries before changing your MySql memory allocation, sessions etc.

Its always better to treat the problem ground up (by finding rogue queries) rather than put a quick fix and forget about it (e.g. allocating more memory or setting sessions). Over time, the quick fixes will lead you to buy more hardware and cost more.

1. Setup the MySQL Slow query log:

To setup the log, first uncomment the log_slow_queries and long_query_time parameters:

# Here you can see queries with especially long duration
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 5

This will set the slow query log to: /var/log/mysql/mysql-slow.log and will log any queries that take more than 5 seconds.

To start with, you should set the long_query_time to a higher value, so you don’t get overwhelmed with too many slow queries. Later you can bring this down to 2 seconds or so.

And later you should also set the ‘log-queries-not-using-indexes, to identify queries that will slow significantly as data load increases.

2. Restart mysql:

In ubuntu, simply run the command:

sudo /etc/init.d/mysql restart

This will restart the mysql server and start logging your slow queries.

3. Use your database, and keep checking for slow queries!

I hope this helps you in tuning your MySql database from the ground up.

LAMP: Why does a page take too long to open?

If you’re wondering why some pages take ages to open on your LAMP site, consider checking all the queries that hit your mysql database when you open that page.
Sometimes it is not slow queries, but too many reasonably fast queries, that are slowing you down.

Note: I suggest you try using your slow query log first! Here is a post that will help you.

For checking the database for all queries, you should be the only user on the database.

1. To know *all* that’s hitting your mysql database, simply uncomment this command in your my.cnf file (in Ubuntu, it is located at: /etc/mysql; you need to be root or run ‘sudo /etc/mysql/my.cnf’)

# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.

log = /var/log/mysql/mysql.log

2. Once you’ve uncommented this line, restart mysql server:

In ubuntu: sudo /etc/init.d/mysql restart

3. Clear startup logs:

Most likely you don’t want anything to do with the startup queries, so simply clear the log:

sudo echo ” ” > /var/log/mysql/mysql.log

4. Run your test: Go ahead and open your troublesome page in your browser.

5. As soon as the page is opened fully, copy out the log (here it copies to your home directory):

sudo cp /var/log/mysql/mysql.log ~/slowpage.log

If you have more troublesome pages, clear the log again and copy it to another location, for analysis.

6. Once you’re done with getting your logs, comment the log setup in my.cnf once more, and restart mysql again (steps 1 and 2). This will keep your mysql running fast.

7. Now go ahead and analyze what queries are run when you go to a particular page.

All the best with your tuning efforts!

Password Management Using htpasswd

In Linux, several components use non-system standard passwords.

Some of these are svn, and ftp (e.g. vsftpd).

Here are the basics to get you through setting and resetting these passwords:

For svn, refer this guide.

For vsftpd, refer this guide.

Basically, htpasswd can be used to create encrypted passwords for such modules. Here are some basics to htpasswd:

1. htpasswd uses a password encrypted file, using an SSL certificate.
You can create your own ssl certificate too. But for public/production environments, you’d want to get a certificate from a third party so users don’t get a security alert.

2. The first time, use the -c flag to set a password, as follows. You’ll need to do this as root (or prefix sudo in ubuntu)

htpasswd -c /etc/apache2/my_passwd.passwd username

3. Subsequently, use the -m flag to modify this file for adding/editing users:

htpasswd -m /etc/apache2/my_passwd.passwd username

LAMP Server Crash

If you did some optimizations by adding memory or RAM to processes, and the next morning, you find your server is no longer online: chances are it ran out of space and triggered the oom-killer.

oom-killer is a process that goes randomly killing processes to help the system survive.
After this occurs you should always restart as soon as possible.

Here is where you can find the logs in ubuntu, and how to identify if your system shutdown because of memory:

location of log: /var/log/messages (you will have to have super user permissions to view)
What you’ll see: Just before the server shutdown or went erratic, this message:

apache2 invoked oom-killer

To get out of this situation, try to put more conservative memory settings on your applications, or add more RAM!

All the best!

Posted in Tech. Tags: , , . View Comments »

5 features Ubuntu needs to compete

Though I dearly love Ubuntu, and many of its features make windows seem obsolete…
But no matter how much I’d like to bid Windows adieu… there are reasons I need to still hang on to Windows – and no, its not just because of Word.

1. IE Compatibility
It’s tiresome to go online and find a site (turbotax, netflix, web outlook…) which doesn’t work well with firefox – especially linux based firefox. Sure there are workarounds and spoofs, but that’s not a system working out of the box.

2. Multimedia experience
Ubuntu has some really neat multimedia features. Compiz Fusion adds mouthwatering features to your desktop – allowing you to rotate it like a cube for example.
But when I plug in an HDMI cable to connect a big screen tv, windows still supports the extension much better. My nVidia ubuntu driver asks for a restart, but doesn’t do anything even after that.
DRM support is not present, which means the music industry leaves Linux users with no form of entertainment. No rhapsody to go.

3. Application Setup
It takes a whole lot of effort to get some apps to work. Skype, for example, needs a whole lot of tweaking and driver upgrades before it can work. For an app that needs speakers and a mic for basic functionality, setup should not be so difficult.
The soundcard drivers and programs, though feature rich, are not seamlessly integrated yet.

4. Much needed Applications
Some applications are altogether missing linux support. For example, no iTunes, no Microsoft Office are completely missing (sure the MS Office issue has been beaten to death – but really, at least give us an application that formats word documents accurately!) – and I’m not even talking hit games like GTA.
And yes, Wine can help get some things working. But any serious OS can’t rely on workarounds.

5. Teething issues
Linux is lightweight, and efficient. Not!
That’s what I always believed, until I wondered why my computer was so sluggish, when all I was doing was browsing the internet. Turns out, the Adobe Flash plugin on linux is a resource hog. Even if its just pandora playing, or Rhapsody online, the cpu usage peaks, and everything slows to a crawl.
Its a known issue. But is anyone fixing it?

Most of these are minor issues, and most of them have workarounds. But the question is, if Ubuntu linux is really going to compete mainstream, these need to be addressed. Linux has come a long way since its inception and text based output. But it still needs some polishing before it can kill the competition.

Ubuntu 9.04 with Vista on Dell XPS m1330

Tired of Windows Vista slowness on my souped-up Dell XPS laptop, it was time I at least dual-booted into Linux. So I went ahead and downloaded a copy of Ubuntu to setup my computer.

To my delight, installing Ubuntu was a breeze! Though there was some back tracking I needed to do, this guide will help you get it setup in one shot. Once setup, everything on the laptop works – as if it is out of the box. This includes function keys, the mute/eject buttons and wireless.

You may face trouble with some applications though – be forewarned!

1. Make space for Ubuntu:

Shrink the volume size in Vista, so you can install Ubuntu

1b: Backup your data (Yes – ALWAYS play it safe :-) this will most likely go through just fine – but you want a backup for that hard disk crash you never planned for, anyway!

2. Write an Ubuntu Jaunty CD. You can try using Wubi – which is a windows Ubuntu installer. But I went the traditional way – this works just fine.

3. Boot into the CD (you might need to change boot sequence so your computer looks at the cdrom first)

4. Go through the partition steps and install Ubuntu into the free partition size you will see available.
Make sure you don’t assign all of it to Ubuntu – otherwise you’ll have trouble using Vista, or your install will fail.

5. Let ubuntu go ahead and install itself. I’d suggest giving it at least 20GB (I gave it over 100GB :-p

6. Now Ubuntu won’t be able to connect to wireless just yet (I have the default Broadcom wireless card).
So connect to an LAN cable and go to System > Administration > Update System

7. Go ahead and install all the updates (there were about 140MB of updates when I ran it).

8. Restart your computer, and presto: you have ubuntu working!
You might need to take a moment to get the wireless setup – by entering your wireless settings.

Posted in Tech. Tags: , , , , . View Comments »