Sunday, November 11, 2007

Linux is fun for me

Do you've a SysRQ button on your keyboard? No. You must've the PrintScreen button, next to Scroll Lock? Yes. Then you can try out kernel keyboard shortcuts.

The fastest (and most unsafe) way to reboot your computer is
to press these these combinations, one after one.
Alt+SysRQ+s - Sync data to disks for all mounted disks immediately.
Alt+SysRQ+u - Remount all filesystems as readonly.
Alt+SysRQ+b - Reboot immediately.

There're a lot of kernel functions availible, depending upon your kernel version.
You can find them in kernelsource/Documentation/sysrq.txt file.

You can enable all of kernel functions by,
echo 1 >/proc/sys/kernel/sysrq

Pressing Alt+SysRQ+h should tell you about various sysRQ functions availible (in dmesg output). For example, on my system (Feisty Fawn), they are
SysRq : HELP : loglevel0-8 reBoot Crashdump tErm Full kIll saK showMem Nice powerOff showPc unRaw Sync showTasks Unmount shoW-blocked-tasks

The saK (secure access key) can be used to allow secure login. The output of kernel functions, if any, goes to /var/log/messages (or dmesg).

Wednesday, November 7, 2007

Google will free the mobiles

Google has unpacked the gPhone using Android. Its the next biggest thing in mobile industry. Having your phone run open source code and hacking it the way we hack Linux. Well, it looks promising now.

The Open Handset Alliance founded by Google includes big names from the mobile world - Nvidia, Intel, Motorola, Samsung, LG, Qualcomm etc. Together these companies shall come forward to manufacture and design gPhones, that will run the open system called Android.

Now, gPhone ain't a phone like iPhone. Its not even a phone for that matter. Its just a prototype. Their idea is to have thousands of gPhones, just like we've thousands of Linux distros! The handsets shall be coming to market next year.

Well, some big players are still missing. Nokia, Sony Ericcson, Blackberry, Apple, Verizon and AT&T. And yes, Microsoft.

A video by the developers introducing Android
Another video by kids, who want their phone to make coookies for them.
Open Handset Alliance
Official Google Blog: Where's my Gphone?

Google had acquired Android Inc. two years ago, in a very quiet manner. Android is being developed as a mobile platform to be released under Apache v2 license. The complete documentation and Android SDK shall be released on November 12, 2007.

We know there've been other initiatives as well. OpenMoko, Qutopia, and now Android. The mobile shall be finally freed!

Sunday, November 4, 2007

TuxCoders made it at Nerdz!

We're excited. We're happy! And we're the winners. At Nerdz 2007, Jamia Hamdard!

For those who don't know, Nerdz is the annual technical fest organized by Department of Computer Sciences at Jamia Hamdard. They host a variety of contests, including on the spot programming, overnight coding, debugging etc.

So we were the team known as TuxCoders. We were four - me, shamail, aaveg & bharat. And we bagged three prizes! So we really rocked!

Envision, the predesigned software contest. Shamail & Aaveg presenting JamP2P. There was no second thought about being the first.

Crack the Shell, the unix shell programming contest. Me & Shamail. And we won by a big margin! Who needs to say more?

Google Dance, the googling competition. Google and find answers to weird questions. Me & Bharat. And we got the second prize, again!

It felt somewhat deceiving, when we had to pay 500 bucks as the participation charges. It seemed a big risk! However, our confidence rose as the day passed. And the end, we bagged three trophies! And free food for the two days for all participants! So we made a good deal in the end.

Nerdz '07 was a success, and we enjoyed a lot! I wished we had more guys from our college. But there's always a "next time"! But now, its time to celebrate! TuxEnjoy!

Sunday, September 23, 2007

Get rid of RAID!

RID. That is RAID without the A. I'll show you how you can experiment with RAID without having multiple drives, which are, not-so-inexpensive actually.

If you don't know what is RAID, a half-an-hour glance through this TLDP guide will get you going. RAID is actually the feature of Linux that helps you append multiple drives (or partitions on different drives) as one device, with different kinds of features. RAID can also mirror your drive data, and protect your data from crashes.

So, to get started using RAID, you need multiple drives. Wait! Is that really true? Do you know about loop devices? That is, devices within devices. Can I fool the RAID by asking it to make an array from loop devices?

The answer is yes! Its possible! Here's a short experiment you can do to believe me!

First, let us create two files, that will act as two devices to RAID.
$ dd if=/dev/zero of=disk0 bs=1M count=256
$ cp disk0 disk1

The first command takes some time. Now you've two zero'd files, ready to be used as loop devices.

Using losetup, we'll setup the loop devices. If you're not already using any loops, you'll get loop0 and loop1 for the two files.
$ sudo losetup -f disk0
$ sudo losetup -f disk1

If they are successful, loop devices have been created. Just to check, you can run
$ sudo losetup /dev/loop0
$ sudo losetup /dev/loop1

Two loop devices ready! Its time to ask RAID to make an array out of them. This is simple, with a self-explanatory command, as
$ sudo mdadm --create --verbose /dev/md0 --level=raid0 --raid-devices=2 /dev/loop0 /dev/loop1
Take a deep breath, and read that command again. It's actually simple. If you're going along with me, you should see something like this,
mdadm: chunk size defaults to 64K
mdadm: array /dev/md0 started.

Great! We've made the RAID array device. Now its time we make it meaningful. Lets format it using ext3 filesystem!
$ sudo mkfs.ext3 /dev/md0
This writes inode tables, superblocks and creates journal. ( If you're just curious, let me explain that the "actual" writing was done on our files disk0 and disk1 )

Now we can just mount this device. Simply type,
$ mkdir myraid
$ sudo mount /dev/md0 myraid

If its successful, try moving inside.
$ cd myraid; ls
You'll see the lost+found folder there. Copy here a few big files to see it works actually. Unmount and mount again. It works!

To see that whether RAID has really done the job, you can
$ df -h | grep md0
/dev/md0 496M 11M 460M 3% /home/kazim/myraid

There we are, a drive with 496M!

Now you can do everything you wanted to do with RAID. For example, try to make the disk1 crash! Since we used raid0 level, a crash means no recovery! If we used raid4 with spare disks, we could even see recovery process going on!

How do you make disk1 'crash' ? Well, you should find a good answer yourself. For data corruption, you can destroy its superblock, or shred it, or do anything bad you can think of! RAID won't recover from a data corruption. But you can simulate hardware crash by using the --set-faulty option of mdadm. (Try crashing a mirror device on a RAID1 with a spare device and see how RAID recovers data.)

Specifically, however, if you try to delete the drives (while md0 running),
$ sudo rm disk0
$ sudo rm disk1

There'll be no data loss. You would ask, "why?". Well, go and revise your OS concepts. And you'll know why 'removing' is not 'crashing'.

Happy RAIDing!

Saturday, September 22, 2007

Web 2.0 - the hype?

If you still don't understand why humans have made so much hype about the Web 2.0, and you think that its a crap, you should watch

Web 2.0 - The Machine is Us/ing Us (YouTube Video)

Web is like growth of a civilization. The civilization of the netizens. And when we say 2.0, we appreciate our growth. We are more organised. We are teaching the machine.

Read Prof Wesch's blog, on what he has to say about the video he made.

We've seen revolutionary changes in the way we work on internet. We think the change deserves a name, Web 2.0.

Wednesday, August 29, 2007

unlikely() & likely()

This week wasn't really productive. No preparations for sessionals yet. Stayed up last night so missed the college today. And some idiot classmates must be thinking now that I was preparing hard for sessionals. Poor kids, ;-)

Actually, I tried my hands with Linux Kernel Development. And its such an amazing thing!!

For starting out, I downloaded the source of latest kernel as linux-
I unpacked it, and started reading code. And as some of you must have guessed it, it was beyond my limits of understanding.

Its quite difficult to start actually. Including the comments, the whole kernel code (latest) is about 7.3 million lines. Too much, na? The first version, 0.0.1 had about 10000 lines. I read somewhere that lately they've not been adding much to this code, but refining it and fixing bugs.

The Linux kernel is one of the best (or the best as they say) kernels around. It has got a great mix of good algorithms, and it has refrained from bad policies and poor design. Its monolithic and still quite modular.

Its well commented, and the code gives me a feeling that it can be understood, given time & patience. Well I've got some books too, notably Linux Kernel Development 2nd Edition, which will help me as I go.

There are some interesting things when writing kernel code. First, you can do everything and anything. Nobody will trap you or accuse you or kill you. No memory protection (as userspace has got), no faults and error trapping. You need to behave responsibly.

Second, you don't have the standard C library. No printf (though a printk is there). No great time saving functions. But fortunately, most useful ones are there in kernel headers (like string comparison etc.)

Third, you have a small, fixed-size stack. Unlike userspace applications, you just cannot allocate tons of variables! So every byte counts here.

Fourth, no floats in kernel code. No floating point arithmetic here. Because kernel has a do-it-yourself overhead. So, just integers and chars.

Finally, the one I found most interesting is about predictability. Conditional branches can be optimized as either very likely or very unlikely by GCC. The macros likely() and unlikely() do this work.

/* file is almost never NULL */
if (unlikely(file == NULL)) { .. }

/* the two sizes are almost always equal */
if (likely(new_size == old_size)) { .. }

Compiler will optimize these branches as the programmer has predicted. If prediction was good, it will improve performance. Otherwise it can degrade performance, too. You'll find unlikely() a lot in kernel code.

Its an intelligent piece of code. And so it requires a lot of time to study. Well, I am prepared for anything! Let's tame the beast!

Saturday, August 25, 2007

Get organised!

This one goes out to all my friends and foes who are a part of FLOSS community. Now is the right moment for all of us to get more organised. We don't have much time. Its now or its never. The FLOSS community is calling upon us. Get involved!

You are a free programmer or designer or developer. You are free to do whatever you want. You are free to develop software for yourself. You are free to make it big and better. But not for very long. Because as soon as you get a job, your freedom is lost. The fun for programming is over. Your spirit dies when you do it for money and position.

Imagine, you are a software engineer. Working for 9 hours a day. You just got a 100 page specification from your boss. You got a deadline. And now, painful days of working like a machine. 'Machine' because you are to do what you are told. You cannot innovate. You are not allowed to think. You ain't free. Your freedom sold in dollars.

Again, imagine you are an open source developer. The scenario is different now. You are working on a project you chose for yourself. You are enthusiastic about your work. You've new and great ideas and you are gonna implement them. The fun of programming is alive and everyday is a holiday. You innovate new things, and you find appreciation. You find greatness.

As Niyam (at ILUGD) puts it, "You are born unknown. You'll die unknown. You won't be great if you don't do great things. Join the free software community and get known. Then only you'll be called great. Find that greatness!"

As a student, you've taken the freedom you enjoy for granted. But once you've a boss, you are no longer free. You are a slave of your boss, and your boss is a slave of his boss.

You don't need to be a Linux geek to join us. All you need is a belief in software freedom. There's no second to waste. Rise against ignorance. Make everyone aware of free software. Participate in development! Get known. Get your friends involved. is near. Fasten your seat belts! We've to make it bigger than ever. Free your friends from proprietary software. Involve as many people as you can! Tell everyone what is free software. Tell them to use it. Invite them to Freed.

Gear up! The world is yours!

And don't hesitate to ask me if you don't know what to do.

Big Button - 120x60

Friday, August 24, 2007

To blog or not to blog

But that's not the question, since I've decided finally, after so many requests from so many people (read exaggeration), to blog. This is intended to be my technical blog, about all the funny and stupid and tragic things that I do with technology.

Why Tux Playground? Tux is the name of the penguin that first chased Linus Torvalds, and since then, the whole world has been chasing him, including me. Playground because its all about hacks and tweaks! I think thats all about it. See you again :-)