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

Friday, October 10, 2008

How to boot from USB in xVM VirtualBox


I've looked around the internet a lot and mostly didn't find any working solution apart from trying to make an image/virtualDisk from a raw physical disk (USB). I was basically experimenting with writing simple bootloaders in assembly language, and wanted to rapidly test and make changes to the code without rebooting my system again and again to try booting. The obvious solution is to use a Virtualization tool like VMWare or xVM VirtualBox by Sun (the latter is free), but the trouble is that neither of them support booting from pen-drives and I have long forgotten the existence of floppy drives, and have thus no way of directly writing to a disk and virtual booting straight-away, without creating an new image of the disk each time I make changes to it. So I decided to write to my USB pen-drive directly and try booting from it. It works when I boot the entire computer with it, but VMWare and VirtualBox do not have the option of booting from a USB device.

So messing around xVM VirtualBox 2.0.2 36488 for Windows yesterday, I was pretty surprised to find my USB Pen-Drive listed under the field of Floppies! That is,

a) Create a new Virtual "Machine"
b) Click on the "Floppy" link in the main screen (right panel)
c) Enable "Mount Floppy Drive", and from the drop-down list in "Host Floppy Device", select your USB drive's Drive Letter (haven't tried it in Linux, I guess you'll have to select the correct device like /dev/sdxx)

That's it. Try starting the Virtual Machine now.

Its quite wierd, and I'm still wondering why my USB drive gets listed under floppy, but it works for me! Neither VMWare Workstation, nor xVM VirtualBox permit booting directly from the USB otherwise.

Cheers
Shashank

Sunday, October 05, 2008

Of the Elusive Breakfast Syndrome


I really have a problem, or rather had one. It is an uninteresting topic for anyone but me, but I haven't managed to have breakfast on any weekend this ENTIRE semester i.e. in the past 4 months. I have never managed to wake up before the closing hours (9 am) of the hostel mess (often I directly wake up for evening snacks on weekends, let alone breakfast and lunch). I have even attempted, several times, to stay awake the entire night, till the golden moment when the clock struck 6:45 am, and each time some odd conspiracy of Nature conspired against me. Once I watched a movie till 6:35 am, and then pondered over how to pass the intermediate 10 minutes, and then continued pondering as I next regained conciousness at 10:30 am. Then once I managed to sleep off on the floor of my room, beside my door, while trying to open it to leave for the mess, again at 6:35 am.

Today, however, I grabbed Fate by the wrist and bent it to my will! I left my room at 6:30 am, as I was sure I wouldn't manage to survive any longer after watching Lord of the Rings III (for the 5th time), and also figured that I probably wouldn't sleep off in the corridor beside the mess, though I'm not sure I'd put that past my capabilities. Anyhow, here I was - unshaven, unkempt, with a haggardly-desperate look, sitting outside the stairs of the mess waiting for it to open. Then I tried walking around the area a bit, and I discovered I didn't like the cold air too much, and again returned to my patient look-out post. And then, the Gates of Destiny opened! And I had wonderful breakfast, and Tea! One of the greatest battles of will and destiny in my life had been fought, and I had emerged the victor - a fed victor at that. :-)

Shashank
PS: I haven't gone loopy. Food breaks the best of men, I'm just a mere, humble mortal.

Saturday, October 04, 2008

DMOZ Local Directories and BatchDMake


Today morning I finally settled in to perform a long-pending weekend house-cleaning job, except that the cleaning work was electronic, i.e. my computer. It is a common scenario to find your files so badly scattered around the hard-disk, inspite of some organization scheme that we all implement. Years ago, I saw a nice scheme Roshan, a friend of mine, implemented. He created directories and sub-directories based on topics and categories, like "Science", "Computers", etc, and Science would contain "Physics", "Chemistry" ... while Computers would contain "Programming", "Internet" and so on. It was a complete hierarchial structure, and I've been using it on my systems too ever since I saw it there.

But, its hard to maintain my directory, as creating such a structure is a rather tough task. You could either create an entire directory structure before-hand, with empty folders waiting to be filled, or you could create new folders as and when you require, in the correct category of course. The latter option obviously seems more efficient, as you don't have an empty mammoth directory structure, but a dynamic and to-your-taste structure. But after several years of trying out both, I have found that the first approach is much better. When you are, say, saving a file from the Internet, you often don't have the patience to ponder over the hierarchial relationship between "Geese Hunting" and "Duck Hunting", and whether you should create a new directory for each, or just club them into one single directory called "Bird Hunting". This inherent impatience of people when using files, as understandable and natural it is, is THE reason why files are scattered and chaotic. Thus I have concluded that people need an existing order to follow, that is as extensive and accomodating as it can be, but also flexible in order to allow people to delete and modify and create new topics and directories.

With this long discourse on the philosophy of file management in mind, I sat about thinking! :-D

This is what I came up with: Why not use an existing MASSIVE topic-wise directory structure, which has been developed and nurtured for about a decade by tens of thousands of people across the world? That directory structure is the DMOZ Open Directory Project (http://www.dmoz.org) by the Mozilla Foundation (of Firefox fame). It forms the backbone of Google Directory and several other places on the internet, and is a collaborative and open effort at building efficient web directories. My interest, however, is not in the links to websites that is provides, but the topic-based organizational structure. And as luck has it, they offer a downloadable plain-text file containing the ENTIRE folder structure. Perfect. Its available at:
http://rdf.dmoz.org/rdf/categories.txt (57.4 MB)

Then I wrote a simple tool in Java called "BatchDMake", which will read a given text-file line-by-line and create the folders listed in it. Each folder path is listed in a separate line. For example, this is from the DMOZ dump:

Arts
Arts/Movies
Arts/Music
Computers
Computers/Artificial Intelligence
Computers/Games


The syntax for operating it is:

java BatchDMake [filename] [root folder]

The filename parameter is obvious, the root folder is the folder name relative to the current working directory in which it should create the folders listed in the text file. For e.g. using the downloaded DMOZ categories file:

java BatchDMake categories.txt dmozRoot

The source code for BatchDMake is available here, and the executable .class file is here.

I just created the ENTIRE folder structure of DMOZ on my hard-disk, it has about 770,000 directories & sub directories. A lot of them are useless ones, so I'll go about pruning the tree to come up with the most useful structure for normal users. Will post that one soon. In the meanwhile, you could try the DMOZ structure and use BatchDMake to create it on your system!

Cheers!
Shashank
PS: I even found the place I'm currently in!
root\Regional\Asia\India\Tamil_Nadu\Districts\Vellore
This is like exploring an uncharted world in your hard-disk! :-P

Thursday, October 02, 2008

Software Freedom Week 08 - Phew!


Note: This is a blog post I'd written in a state of half-sleep at 3:38 AM, 27th September, 2008. I slept off before managing to send it and forgot all about it, so here it is. :-)

Sitting at 3:38 AM, while browsing the Internet for some interesting articles, I found I had received a new mail. Looking into my Inbox, I discovered that the mail had been entered into my "Friend Networks" label, and it turned out to be an insistent invite (he had sent it thrice) from a friend in a social networking site, and the invite reads: "You have been invited by ____ to join the community: I LOVE FRUITS". Need I ask, "Huh?"

This was meant to be a blog on the "Software Freedom Week", which more or less got concluded today. Technically, it finishes tomorrow, but the only event we're having tomorrow is the passive collection of Abstracts for the Product Engineering contest and a party! So no crazy real-world events that require fighting with the "bureaucrazy" and stuff. The last one week has been a very hectic period, which reminded me of the days of our "IEEE Resonance", the two-day National Level Technical Fest, held in March earlier this year. That event was gigantic and I, as one of the 3 main organizers, probably lost several years of my lifespan due to the stress and workload that went into organizing that event.

This Software Freedom Week was organized together in a VERY short span of time. Really. It sets a sort of personal record, as the only Large Scale event I've organized within a span of 9 days. The other large events have me and the core team starting work atleast 3 months in advance. The entire idea that we Sun Campus Ambassadors have to organize a Software Freedom Day in our colleges by 27th September became clear only once we had done our Induction & Training programme at Noida from 5th - 8th September.

Our SFW went off pretty well! We managed to conduct several successful installfests, and installed and distributed openSolaris DVDs to atleast 30 folks! The other guys installed some distributions of Linux, like Ubuntu, Fedora and openSUSE. Then our Linux & Unix demos were quite successful with a lot of interested people turning up who managed to get an intro to the basics of the file structure and philosophy of the Unix operating system, as well as some common tools and commands. Our Programming challenge paper was very well appreciated by all the students as being "damn interesting to solve". The biggest success was the "Mobile Application development using NetBeans" workshop which I conducted yesterday evening (26th). The turnout was HUGE and the guys were amazed at the ease of developing MIDlet apps using the Visual Editor. There was a pretty strong request for conducting an advanced session for them soon as they wanted to learn more about this. :-) And just to recall that I myself had been trained at this for the first time 3 weeks ago in Noida!

Organizing large events at a very short notice leads to nightmarish organizational problems, and can easily spin out of control to lead to horrible mis-management and utter chaos. We came close to it during the hiccup that happened on the first day with the venue conflict with another department's research class, and it took us a great effort to continue with full speed throughout the week inspite of the regular, minor-but-painful hiccups that occured. We always managed to solve them somehow, but the fact that they appeared shows that a lot more work could have gone into the planning process. Yet, I do not regret anything, and even though I am so totally physically and mentally exhausted, I can still say that the SFW was one of the most challenging and awesome things I and my friends have attempted. And I enjoyed it and the great response it generated. But now we're planning a FAR larger thing in December. A sort of a Open Source Mega Fest at the top levels.

More soon, I'm too sleepy!

Cheers
Shashank
PS: No technical work has been possible over the past one week
PPS: Metallica released their new album called "Death Magnetic". Most of the songs are just average in my scale. I like "Cyanide" and the intro of "That was just your life". And Kirk Hammet is finally playing guitar solos again. His solos were cut out of the last album: "St. Anger", which was a welcome return to Thrash Metal. In my opinion, all the songs on the St. Anger album sounded like an army of tin-soldiers sprinting over a tin bridge, and a song playing in the distant background. Heh!