Archive for March, 2009

The one about my “Joy Machine!”

Tuesday, March 24th, 2009

What I always wanted was a “joy machine”. That is, a system that would always be on, would act as a server and give me room for experiments. Of course, that system would be based on Linux. It just gives a lot more room for customization, hacking and experimentation.

The first thing that I thought of doing was to make a second desktop PC and just leave it always on. But, I needed this to be a “quiet” system. Event the humming of the cooling fans can become very frustrating when you are trying to sleep and even though I don’t really mind the noise, it is a cause of headaches over time. I had an old Pentium 2, 333 MHz processor and motherboard, a spare IDE hard-disk and 256 MB of RAM, so I decided to create a headless (that is without a monitor and keyboard) system based on that hardware. My initial plan was to set it up in some special protective casing on the balcony of my apartment, but I ended up using an empty firehouse casing and installing the system next to the apartment entrance at the stairs.

Rigging the case to house an old motherboard, two hard disks (one at first) and a power supply unit was trivial but very fun!

Inside this box is living a Debian system. Initially I installed Debian etch but I recently upgraded to lenny. Usage and administration is performed remotely through ssh. Apart from being a Linux enthusiast’s playground, the machine also serves as DNS server for my local LAN, NFS and Samba to serve files, MySQL/Apache/Python/Ruby/PHP for web development.  Also,  it contains several subversion repositories for my pet projects. The home directory is mounted on a LVM partition. That makes it a whole lot easier to expand the filesystem size in the future. It is also very useful for doing large downloads, e.g through bittorrent (using rtorrent) or rapidshare (shell script around,  wget) with the help of the screen utility.

Even though the system is low spec it performs superbly. The memory usage is always topped and the swap is rarely touched. It even manages to stream 1080p video with ease. One time, after an experiment with LVM went wrong, I had to boot the system with an Ubuntu Live CD to do some restore work. I hooked the machine with a spare display, a keyboard, a mouse and a really old x2 CD-ROM drive. Booting to the live CD using a x2 drive and with a 333 MHz processor took a few minutes but the astonishing thing was that even though the system has only 256 MB of RAM, it actually managed to load Gnome and also open various applications like Firefox! Too bad I didn’t make a screenshot of it.

All in all, playing with the system is most fun, it really is a “Joy-Machine”!. It is also a perfect example of how old, low-spec hardware can be put to use with Linux (one could of course use some other open source OS like FreeBSD or OpenBSD). You wouldn’t be able to setup a system like this with a Microsoft Windows Server. Compared to M$ Windows, Linux is usable on a broader spectrum of hardware.

Raising Elephants Is So Utterly Boring!!!

Friday, March 20th, 2009

What do elephants have to with me? Ehmmm, nothing! This post is not about elephants, of course, but about a not so well known feature of the Linux kernel which has to do with safe system termination or reboot.

Raising Elelephants Is So Utterly Boring

Raising Elelephants Is So Utterly Boring

Suppose you do something silly, like load an unstable kernel driver, or you use unstable versions of some applications or simply you stumble upon a weird bug, and suddenly your system appears to have hanged. Hmmm… what to do? If you were in a Windows environment, you would probably hit the notorious Ctrl+Alt+Delete key combo to get the task manager appear on screen. Then, you would either kill the process that’s causing all the fuss or you would hit reboot or shutdown to safely switch your system off without risking data corruption. I’m sure that everyone who uses windows has been in a situation where simply hitting Ctrl+Alt+Delete did not work, the task manager was nowhere and they were forced to hit the “evil” reset button in dreadful fear and guilt of doing something that could render precious data corrupted.

Unfortunately,  you cannot do anything else in that sort of situation. That is, if you are a windows user…

Linux users can feel a lot safer than their friends, the windows users, for their daily chores, because there is more to Linux than hitting a Ctrl+Alt+Del combo each time something becomes unresponsive. Healing a system that appears to be hanged is a series of actions, each action to be taken if the previous fails. Now, here’s what to do in such a case:

  1. If you are in a desktop session, running GNOME, KDE or any other window manager, press Ctrl+Alt+F1 or F2 or F3… or F6. In Linux user sessions run in virtual terminals. Virtual terminals 7 and above are reserved for graphical sessions running on X, and terminals 1 to 6 are for console sessions. A user can switch any time between any virtual terminal by hitting the Ctrl+Alt+F# key combo, where # is the number of the virtual terminal. So, hitting Ctrl+Alt+F1 for example will switch to console mode and a login prompt will appear. Login, and use the standard shell tools, like top and ps to determine what process is causing the problem and kill it with the kill utility. Then logout and press Ctrl+Alt+F7 to get back to you desktop session.
  2. If the system refuses to switch to another VT (virtual terminal) try to kill the X session by hitting the Ctrl+Alt+Backspace key combination. This will effectively kill every graphical application and restart the X Server. In the end you should be brought back to the login screen.
  3. If step 2 fails, then try pressing Ctrl+Alt+Delete. The system will beep and initiate the reboot sequence.
  4. If you don’t hear a beep, or if you do hear it but the computer is not rebooting after some time, hit the Ctrl+Alt+Delete combo once more. CAUTION! This will do an unsafe reboot. If the system has not unmounted the filesystems in use skip to the next step.
  5. Something went extremely, horribly wrong. 99% of the time step 1 should suffice. However, even if all of the above fail to give a result, don’t worry. DO NOT in any case hit the reset or power off button. The kernel has a small communications channel open at all times. Even if everything goes wrong you will be able to use this channel to send commands to the kernel.  These commands are sent by holding Ctrl+Atl+PrintScrn/SysRq and pressing a letter designating the command. What you need to do is to remember that Raising Elephents Is So Utterly Boring. The first letters of each word is the sequence of commands you must issue to trigger a safe reboot.  In other words, if everything else fails hold down Ctrl+Alt+PrintScrn/SysRq and press R E I S U B by waiting a few seconds between each key-press to allow the kernel to finish executing each command. R E I S U B is easily remembered through the mnemonic; Raising Elephants Is So Utterly Boring. Or, you can think BUSIER spelled backwards. I prefer the elephants though Smile.

The sequence of the commands executed are:

Ctrl+Atl+PrintScrn/SysRq + R: Get control of the keyboard device.
Ctrl+Atl+PrintScrn/SysRq + E: Send the SIGTERM signal to all processes except init (PID 1).
Ctrl+Atl+PrintScrn/SysRq + I: Send the SIGKILL signal to all processes except init.
Ctrl+Atl+PrintScrn/SysRq + S: Sync all mounted filesystems. This will flush any unwritten data to your devices and thus prevent data loss or corruption.
Ctrl+Atl+PrintScrn/SysRq + U: Remount all mounted filesystems in read-only mode.
Ctrl+Atl+PrintScrn/SysRq + B: Immediate system reboot.  The previous commands must be executed before this one to do a safe reboot.

There are also other commands you may send, but these are the ones needed to reboot in a system hang.

More info on these magic commands can be found here.

So, if you ever get into a tough spot when using your tux machine you won’t have to worry, remember the elephants Grin.

The one about Centriment

Saturday, March 14th, 2009

You may be wondering, what is centriment?

Well, it’s a name that just popped into my head one day while playing with some code. If someone asked me to tell him what this invented word means, I’d have to say that it is the feeling that a programmer, a hacker, gets when he is on roll and knows that the hack he is doing right now is super-cool. It is the eureka moment you get when you suddenly realized the solution to a bind-boggling problem. It is the feeling you get when you hunt down and squash to mere pulp the most annoying bug you were ever faced with after a couple of days of exhausting debugging. In other, simpler, words it’s the joy of  hacking.

When I finally decided to setup my own blog, it was clear to me how it should be named. Hence, centriment.com. In this blog I will try and share my experiences and opinions in the field of computing.

If you are also wondering about the subtitle, “stories of the spirit living inside the computer”, it is a tribute to the wizard book (Stucture and Interpretation of Computer Programs) and its authors, Harold Abelson and Gerald Jay Sussman, one the best computer books I ever read (still reading it actually Razz).

The one about “Hello World”

Thursday, March 12th, 2009

Hello World!!

This is my first blog post! I am very excited about starting my own blog. I have been a software engineer for many years now and I have always thought about sharing my experiences in the field of computing with others, through a place of my own, but I never seemed to have the time to get down with it. Finally, I’ve setup my own domain, installed wordpress, installed a theme and while writing this I am still experimenting a bit with it.

Since the first thing we do when learning a new programming language is to write a “hello world” program, and this is the first post in this blog, this is about… “Hello Word”!

And here it is in C, the first “real” programming language I’ve learned:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("Hello Word!");
  return EXIT_SUCCESS;
}

Here it is in C#:

using System;
public class Application
{
  public static void Main(string[] args)
  {
    Console.WriteLine("Hello World!");
  }
}

And here it is in Python:

print "Hello World!"

Every time you start to learn a new language or system you begin by making a simple “hello world” application. It is not useful, it does not do anything, it’s plain stupid code. However, it’s all the most exciting because that’s when you start learning something new and unknown to you. Even such simple code has a lot of knowledge to convey to its author. First of all, you learn if the code has to be compiled and interpreted, if it is compiled to machine code or some other intermediate language executed by a virtual machine. You are also exposed to the basic rules and coding styles. You learn if a language is object oriented, loosely or strictly typed.

Soon after that, you start writing a little less trivial things and start feeling like a kid with a new toy. As you learn even more, you start feeling like a little god that can meddle with his own privately created universe.

And now this is my “hello world” in the blog world!

Remember your “hello world!”s?