Friday, December 26, 2008

Day two: Back2Basics Linux


Having vowed not to spend my 10-day winter vacation doing anything serious, I decided to play a bit with Linux, apart from reading the novel "She" by H. Rider Haggard (of Allan Quartermain fame) and revisiting the Beatles' album collection I got hold of just before setting off from college.

Anyhow, one of the first things I did when I got home was to strip off /everything/ from my ancient Ubuntu installation in the PC at my home, and essentially removed ALL the packages other than the important core and base and essential ones. This brought me down to the beautiful command line at the next reboot, and then I to do a little tweaking with the /etc/init.d/rc to display some messages and request for user login, instead of asking for root login (it was configured to spawn /sbin/sulogin, instead of login) and such. All this led to a cool "Back2Basics" Linux, which still takes around 800 MB because I haven't removed a LOT of unneccesary libraries incase I break something (I've done that once before). So I'll proceed to do the stripping work soon (hehe). I got hold of this O'Reilly book on Building Embedded Linux Systems sometime back and it lists this minimum required directory structure for the root (/) filesystem, and another book on Embedded Linux (whose publisher I cannot recall) which listed the bare essential binaries and the corresponding libraries required. So I'm planning to base the stripping-down on the guidelines in these books, and of course using the ldd command to find the dependencies of the desirable binaries incase I want something extra. I replaced the GNU utils with Busybox yesterday. My target is to just have the Kernel Image, Busybox, Perl, and Java. Lets see what comes of it. ;-)

Also, I'm working on a new categorized layout for this blog, something I'd developed two years back but never implemented. Its going to automatically pick the most popular categories and show posts filed under those in square boxes, and the more popular categories will be higher up in the boxed, 3-column layout.

Cheers
Shashank

Monday, December 22, 2008

Network scanner script

One of the more useless handiwork of a wasted 2 hour lab session:

A shell script for scanning the network with Class C IP Addresses from 192.168.0.1 to 192.168.255.255 and listing the active IP addresses. It writes it to a file called IP_list as well as echoes it.

ip_scan.sh:
-------------------------------------------------------------------
#!/bin/bash

# A Useless network scanner
# by Shashank Shekhar
# - Scans the Class C network from 192.168.0.1 to 192.168.255.255
# - Note: Ping doesn't always return the true state of a network node
##

for ((i = 1; i < 256; i++))
do
for ((j = 0; j < 256; j++))
do
ping -c 1 -w 1 192.168.$j.$i > opFile
cnt=$(grep -c -i " 0% packet loss" opFile)
if test $cnt -eq 1
then
echo "192.168.$j.$i is there" >> IP_list
echo "192.168.$j.$i is there"
fi
done
done
Cheers
~Shashank
PS: I was so bored.

Edit: Evil text-garbling spirits, Stay Away!

Sunday, December 21, 2008

Life in other places. What is Life?



The question of whether there is life in other places in the Universe requires a fundamental question to be answered: What is the definition of life?

This is not a spiritual discussion on Life and its meaning, but for those who thought it was, do read on. Fresh viewpoints are always stimulating for spirituality.

People tend to have very varied and often biased views with regards to their definition of Life. Most would think of a grotesque humanoid form with a head, two arms, two legs as an instant reaction to the question, while others might take more colorful forms: octopuses, crabs, giant ants etc. These have been covered extensively by countless science-fiction material, books, movies etc. These view points are flawed at several places:

a) These replies do not even answer the question: "What is the definition of life". These just provide the answer to the specific question: "What would living beings look like in some alien planet". A sea of difference.

b) They all assume that the physical and environmental conditions required for life are similar to that of the Earth. The fact that life could exist at 12,000 degree centigrade is just absurd, in these viewpoints. But living cells have been found on Earth in the most extreme conditions [1].

c) They all assume that "Life" is Carbon-based, and in-fact, material. What I mean is, they assume that the dependence of Living beings on Water, Oxygen and Nitrogen is universal. This "life" that people talked about involved Amino acids and nitrogenous compounds forming the basic genetic material and cell structures that coordinated to form the diverse life-forms that we know of. But this entire set of known life-forms are mostly based on Nitrogenous compounds with dependence on Hydrogen, Oxygen and Carbon. Assuming that life could evolve only from these is a precarious one.

I do not claim to have the correct answer. The purpose of this article is just to try to broaden the scope of thought and opinion of what is living and what is not.

What is Life? The property that makes entities living. Thus if a set of rules determine that the entity in question is "living", then it has "Life". Hence the question narrows down to determining the set of rules that declare an entity living or non-living.

This is where things get fuzzy. I'm afraid there will never be a conclusive, definitive and "correct" answer, but just our viewpoints. Just like our viewpoints of what is "right" or "wrong" determines laws and so-called morality.

I think an expanded and relatively broad-minded checklist for a single "living entity" would be:

a) Should be responsive to external environments and stimuli
b) Should be able to self-sustain for as long as possible in the environment
c) Should be able to change itself and adapt in order to continue existence

Is reproduction a necessity to certifying something "living"? Probably not. Because a single male or female of the human species, or any sexually reproducing species, cannot reproduce without involving two entities. Thus a single man would not be able to reproduce alone, and would hence be declared non-living by following that logic.

Note: Do not read the following lines if you have had enough mind-expansion for the day.

This expanded view brings us to a series of interesting ideas. Could life forms exist in electromagnetic waves? Why make the assumption that life needs to have material composition? Electromagnetic waves are doomed (in a way) to keep propagating ahead in space until their energy is absorbed by any entity they collide with. But what prevents us from calling a man who keeps running non-stop until he vaporizes by running into a blast furnace as living? You'd say he's living even though he's constantly running non-stop because he can change himself, he's interacting with the environment and external stimuli, and because he is... well a man!

But similar is the case of an electromagnetic wave. Its a bundle of energy, like every man or for that matter, "matter". If some quirks of nature in some part of the Universe would cause these bundles of energy to self-sustain on loss of energy, and suit themselves to the surroundings, all while running along at the speed of light constantly, would they be called Living? I believe they would, and should.

Cheers
~Shashank
PS: Image: X-ray of the left hand of a ten year old boy with polydactyly.

Friday, December 12, 2008

The Curse of the Gravel Machine

Trudging through college life, we come across several obnoxious myths, stories and legends belonging to our college. One such legend I came across is that my college is a cursed one. The curse is that the moment it stops constructing something new, building a new annexe block, pulling down a perfectly nice place and building another... the moment it stops constructing... It will cease to exist! Just like that. God's WILL.

Obviously its obnoxious and untrue, or so we'd hope as long as we're here. But the construction bug has bitten my college since before the guards were toddlers (or so they say), and you're bound to collect different proportions of sand, cement and pebbles in your slippers depending on which path you take across the hostel campus.

Oh and I'm on a break from blogging, which is an odd statement to make since I blog in intervals of decades anyway. I'm also on a break from nosy-technical-fun-&-games since there are a couple of exciting new projects I and my friends have embarked upon which is taking up all my time.

Cheers
Shashank

Sunday, November 23, 2008

Some sad news

Been busy with exams, and work on the latest project which we're submitting for this year's Google Product Prodigy. But this post is not about that.

This post is about the tragic passing of my friend, Ishan Goel, who passed away a few days back. He was just 20. He was a colleague in the Sun Ambassador programme, i.e. he was my colleague at the Sun Open Source club we were founding here at college, and worked very hard with me in making the Software Freedom Day (September 2008) a success, and also a member of our last year's Google Product Prodigy team (which I covered in great detail in a series of blog posts previously), which we worked for close to 6 months together. A brilliant and immensely creative fellow, and a "Linux Helpline". This is not an obituary, or any formal note of sort. It's just hard to absorb this. My hand still tries to dail his number whenever a problem with my Linux system occurs.

~Shashank

Saturday, October 18, 2008

Hello World! iPodLinux - Java style!


October's been a good month for me, and better for my iPod. iPodLinux.org is back online and they've released a couple of pretty neat tools, and updated builds. Loader 2 (the new bootloader) is great - no more messing around with complicated wheel/key combinations to select the boot OS. Loader 2 gives you a GRUB-like list of installed OS images on the iPod disk, and can read kernel images from ext2 and ext3 partitions, as well as FAT32 (W95). So this effectively removes the need to re-create the firmware each time a kernel update takes place. All you need to do is use ipodpatcher (which originally was used for installing Rockbox) and install Loader 2, which will now get merged with the Apple Firmware.

The Podzilla interface has been improved too, and lots of annoying little problems have been ironed out mostly. The text-input is (or atleast, feels) WAY better now, and I can actually input something meaningful in a meaningful amount of time. Here is the text file I "typed" (with awkward scrolling and tapping) on my iPodLinux's PodWrite with a "Scroll with Prediction" text-input mode:

first.txt : "This isn't bad at all. The prediction algo is pretty good as far as this text input session is concerned. Took me 10 minutes to input this on the iPod, but I'll improve I guess."

Then I finally got my first Java program running on the iPod! After encountering wierd errors and battling nasty iPod text-input mechanisms for months, things have finally come to a closure. The latest build of podzilla, makes things easier, and thus enabled me to run Java programs using the K Virtual Machine (kvm) by Sun Microsystems. I got hold of the kvm binary from some place, but I don't think its available on the Sun website anymore, which is pretty odd. But this is how I got my "Hello world" in Java working on the iPod:

1. Install iPodLinux by using the latest Podzilla and loader.
2. Download kvm from here. Put the kvm binary into your iPod's /bin folder and make sure it has execute permission.
3. Write your java code, but keep it simple. KVM just supports basic I/O, data types, Vector, Stack and a couple of other simple things. No graphics, gui etc. For e.g.:

Test.java:
public class Test {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}


4. Then compile the code to the JDK 1.4 format:

#javac -source 1.4 -target 1.4 Test.java

5. Finally, create a script file in gedit or vim called, say, Test.sh:

Test.sh:
kvm Test


6. Save the script file in the same folder as the Test.class file, and give both Test.sh and Test.class execute permissions:

#chmod +x Test.sh
#chmod +x Test.class


7. Put all these files in some folder in the iPod's Linux partition. I put it in "/home/shashank/java" (on the iPod partition, not your own system! Also avoid spaces in your folder path.). Then boot into iPodLinux and open the folder where you placed the files using the File Browser, and scroll to "Test.sh", and keep the "Select" button of the iPod pressed until the context menu shows up. Then select "Execute" and select "Read output". Voila! You should get the two words: "Hello World!" on your screen!

No cross-compilation, no recompiling of gcc to work with ARM7 processors (most iPods run on ARM7 processors, thus C code compiled on your PC will not work on the iPod). Life is easier with this if you want to do simple programming. Maybe if someone wrote an extended Virtual Machine, with more libraries, then it would make this a pretty solid platform.

BTW, the above steps have been written assuming you have a Linux/UNIX machine. If you have Windows, a VMWare or xVM VirtualBox image of some Linux distro on your Windows machine would make life tonnes easier compared to trying to use Windows' limited functionality with everything in life in general.

Cheers
Shashank

Thursday, October 16, 2008

Possible loophole with dd command in multi-user Linux servers


Possible loophole with dd command in multi-user Linux servers

I didn't think this would be a big deal, but I noticed that several remote logging Linux servers permit users to have an unlimited disk quota, which can easily be exploited using a command like:

~$dd if=/dev/zero of=null.bin

It doesn't require the user to 'sudo'. I checked it out in one of the remote access servers that need to be logged in to using Telnet, and I executed this command and was surprised to see it being permitted and having a free and unchecked run. Effectively, /dev/zero is a virtual disk that can generate a series of 'zero' bytes, and the 'dd' command will copy from the input file (i.e. /dev/zero) to the output file (null.bin here) and will not terminate until it reaches the End of File of /dev/zero. And because I didn't give it any count or bytes limit (which can be done using the bs=xxx and count=xx parameter), and since it never reaches the end when reading from /dev/zero, it will effectively create a massively huge file within seconds, and fill up an entire normal-sized hard-disk in about a minute and a half! I tried it out and in less than 7 seconds, I had created a 962 MB null.bin in my home folder. And then I tried on a virtual machine (Ubuntu 8.04 Hardy Heron running in VMWare on Windows) I had created, with a fixed disk-space of 3 GB, and in about 10-15 seconds my 'dd' command died with a "No space left on disk" error message.

I'm not sure if its really a loophole or not, but it certainly made my home directory expand to 1.2 GB unchecked within seconds in a remote telnet login to a Redhat Server. If it is a loophole, I think it could be solved by assigning a strict disk-quota to each user, encompassing the total areas where he can write to.

~Shashank