Archive for the 'linux' 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. )

Death of PC Gaming May Mean Death of Windows

Wednesday, September 24th, 2008

In the past I argued that PC Gaming is far from being dead but the more I think about it the more I start believing that I was wrong. I don’t want PC gaming to be dead - I have been a PC gamer most of my life, and all my favorite games are PC titles.

  1. Upgrade Treadmill - It is getting progressively harder to keep up with the new hardware. Few years I was shopping around for a new video card and a I was looking up specs online, comparing prices on neweg and doing all kinds of research and I could not figure out what to buy. I ended up asking a friend who builds and sells tricked out gaming rigs (you know, water cooling, binged out cases and the works) for advice/ And I consider myself a knowledgeable computer professional. A Shamus wrote about this some time ago and it is getting progressively worse. At this point for example my brother doesn’t even bother reading the system requirements on the box because he knows he won’t understand them. He just asks me to investigate whether or not a given title will run on his machine before he buys it. Average customer won’t “upgrade” his video card - he will wait and buy a new computer when the time comes and hope that it will expect it to come with a video card that is able to play the newest games out there. Unfortunately this is not the case. A computer illiterate friend of mine bought a brand new, very expensive Dell which was advertised as a top of the line gaming machine. Few months later he bought Crisis and was disappointed and outraged that his brand spanking new gaming rig could barely run that game on medium settings. This is the sad reality which causes people to jump ship and buy a console. When you buy an xbox360 game you are guaranteed it is going to run on your xbox360.
  2. DirectX 10 - in addition to upgrading hardware, you are also forced to upgrade your OS. As far as I can tell, no one wants to run Vista these days. All my coworkers who recently bought new computers absolutely hate it, and keep telling me how happy they are our company is not migrating to that infernal system. But guess what? If you want the new shiny game to run on your PC, you may just have to switch to the big V and take the 80% performance penalty that comes with it. P
  3. Stable Development Environment - I’m going to link to Shamus once again because he explains it better than I ever could. Console developers can rely on a stable environment that never changes. They can optimize their code, polish their engines to perfection and squeeze every last bit of juice out of the hardware. PC game developers on the other hand tend to be stuck in a runt, always chasing the latest and greatest rendering/shading/mapping technology. Consoles simply offer friendlier developer environment and one where you can accurately test the game play experience you are delivering to the player. No wonder many development studios shift their focus towards consoles more and more
  4. Price - a $600 buys you a PS3, including software, a blue ray player, controllers and etc - in other words a complete gaming system. Or if you are a PC gamer you can spend that $600 on a new video card alone. I don’t like this, but you can do the math and see where this is going.
  5. DRM - most PC games these days ship with a draconian DRM, online activation, installation limits and hidden rootkits. Not only do you have to jump through hoops to get them installed and activated - they can also damage your CD/DVD drives, or make your system unstable and vulnerable to attacks. Console games have none of the above.
  6. Fewer and Fewer Exclusive PC Titles - at the moment, the only games that actually require you to own a computer are the popular MMO’s. Almost everything else gets released on at least one of the nex gen consoles almost simultaneously with the PC title or soon afterwards. Interestingly enough many of the MMO’s are not exclusive to the Windows platform. For example WoW will happily run on a Mac.
  7. More and More Exclusive Console Titles - this trend started long ago, and is becoming more and more prominent. A lot of popular games never get a PC version.
  8. Console to PC ports done as an afterthought - those console games that do get a PC release, often get a poorly done direct port, complete with a cobbled interface designed for a controller rather than a mouse, and wonky controls and many artifacts of the console-centric design. In most cases you are better off playing the original rather than torture yourself with the PC version.
  9. Demographic Shift towards Consoles - most people around my age and younger these days own a next get console. Some own both the xbox360 and PS3. Most people own a Wii in addition to their primary gaming console. Conversely few of these people actually own an up to date PC gaming rig. Some do, but most either have an older machine that won’t play newest titles anymore, or a lightweight laptop that has enough powa to run WoW but not much else. Younger people seem to eschew desktops altogether, and shop for computers that are most battery efficient, and have good ratio of size/weight and comfortable keyboard layout rather than checking the specs on the video card. You can see this trend when you go to a local Wallmart (or other high volume retail chain) for example. One close to me has a single wire rack in the corner of the gaming isle where you can find PC games. And you’ll be lucky to find anything other than WoW and it’s expansions there. Occasionally there are few boxes of new hot releases but most of the time it’s mostly the same old MMO’s, 1 or 2 WW2 shooters, and few RTS games which have “Age of” in the name. Each console on the other hand has it’s own isle full of games. Consoles are the mainstream market now.

These trends are scaring me. I don’t want PC gaming to die, but the facts above do not suggest a rosy future for the PC as a game platform. Unless something changes, consoles will take over and the number of original PC releases will dwindle. It made me think though - the imminent death of PC gaming may mean hard times for Windows monopoly.

Let’s face it, gamers make up a very large chunk of Windows user base. The biggest source of income for Microsoft is naturally the business sector. I don’t see them being pushed out of there any time soon. The home desktop market however is huge chunk of change for them, and loosing it could mean trouble for the high and mighty MS. Home market consists of three types of people:

  1. Clueless users who don’t know any better
  2. Gamers who elect to run Windows as a gaming platform
  3. People who would love to switch but are locked in
  4. People who simply prefer windows

Group #4 consists of MS fanboys, Visual Basic developers, or simply loyal customers who might have tried other alternatives but prefer to use windows for some reason. These people are stuck in their ways and will likely use Windows until the day they die.

Group #3 includes people who are locked into the OS because the software they use for their hobby/creative work is not available on other platforms and there are no good alternatives. Many of them might be open to an alternative OS if they can figure out a way to take their favorite software with them or find an alternative. Since projects such as Wine and Cedega are continuously getting better, and emulation is getting easier, and open source community is rolling out new projects to replace proprietary software every day the number of the people in this group is bound to fluctuate and fall over time.

Group #1 is the most flexible one. A clueless user is usually bound to windows because that’s the OS which came with their computer. They generally rely on relatives, friends or co-workers for tech support and generally don’t know how to use anything other than a browser. They’d be equally confused using Windows, Apple or Ubuntu so you can swap their OS at any time. I mean, if your user doesn’t know the most basing stuff like navigating the file system, copying files or changing basic display settings will it really be a big shock to move them to another platform? They still won’t know how to do these basic things, no? So what is the difference?

As long as they can still get to MySpace and Facebook they will be fine. In fact, a lot of members of this group actually buy Apple laptops these days and use them without realizing they use a different OS. In fact, I recently talked to someone who was convinced that everything looked so different on his new MacBook because it shipped with Vista. This is a market that can dwindle down to zero provided that there is enough computer savvy people out there willing to switch their clueless friends and relatives to a non-windows platform.

Then there are gamers, whose primary reason for using Windows is that it is currently a major gaming platform. What happens to this group when the PC Game market fades away into oblivion? There will be some reshuffling. Some gamers will decide to stick with windows and move to group #4. Others won’t know any better and will move to group #1. Some will remain stuck and will end up in group #3. The rest may jump ship.

Note that each gamer jumping ship may potentially pull several friends and relatives from group #1 with him. Why? Many gamers are computer savvy enough to provide free tech support to their close ones when needed. Enough gamers switching away from windows may whisk away a huge chunk of group #1 sales from Microsoft. This in turn may create a critical mass of Apple and Linux users forcing major software and hardware companies to acknowledge these platforms and make their products available for them. Thus members of group #3 may after a while find themselves unstuck. Perhaps the death of PC Gaming will be a first step towards a better world - one in which no software company has almost complete market monopoly.

Again, this is wishful thinking - sort of best case scenario if you will. Still, being a gaming platform is a major selling point for Windows. Apple marketing has already cornered the “all fun and no fuss, entertainment platform” market. Windows is already viewed as a primary work related OS by many people. If the PC games go away Apple may actually have a chance to crave out a nice chunk the household computer market for themselves. And where Macs go, Linux will follow since both OS’s are of the Unix’y kind.

Easy Way to Create Simple Linux Packages

Tuesday, September 23rd, 2008

I just figured out how to create an installation package in any of the popular formats (deb, rpm, etc..) in under 30 seconds. This method is probably not something you’d want to use for a serious project, but it is perfect for small scale things such as shell scripts, or various perl/python/ruby concoctions you want to distribute.

Before i start, I must confess that I never really made a deb package from scratch. I did create debs before with stuff like checkinstall. For example I do it every time I install ffmpeg on one of my machines because for some reason that package is horribly, horribly broken in the repos and half the features are disabled. If you want a working copy, you have to grab the source and roll up a deb yourself.

I never created a deb for one of my own scripts because I never needed too. Most of the time stuff that I write ends up being a single script or an executable, which I stick in /usr/local/bin or just keep it in the home directory. If I distribute it, I always figured someone else could do exactly the same - grab the binary and stick it somewhere in the path.

But the other day I was like “maybe I’ll just make a deb for this one script here since I already have like a whole project page for it. And so I googled “How to make a deb” and got tons of excellent tutorials, each of which was at least 50 pages long. I figured I was doing something wrong because a simple thing like creating a package can’t be that complicated and the creators of these extremely detailed howto pages must simply be suffering from the common case of verbal diarrhea which seems to plague at least every third linux user.

I mean, it took me 10 minutes to write and debug this script. If wrapping it inside of a deb takes 3 hours, then we are in trouble. Fortunately I’m a very lazy individual, and instead of trying to follow one of these gargantuan howto articles, I decided to find a quicker way and installed the EPM package:

sudo aptitude install epm

EPM basically builds packages for you almost automatically. All you need to do in terms of setup is to create a single .list file in the same directory as your project. For example for Twimi I created the following file:

%product twimi
%copyright 2008 by Lukasz Grzegorz Maciak
%vendor Lukasz Grzegorz Maciak
%description A minimalistic, command line Twitter updater.
%version 0.4
%readme README
%license LICENSE
%requires curl
 
f 755 root sys /usr/bin/twimi twimi

I think the above is pretty much self explanatory. The first 8 lines are metadata which will be embedded in the deb - you know, the stuff that you can read when you do aptitude show. The last line specifies what to do with the project files during installation. The syntax for this command is pretty much this:

f  mode  user  group  destination  source

You can find more info about other prefixes (there is c for configuration files, d for creating directories and etc..) by running man epm.list. All I needed was to copy a single shell script to some directory in your path, and then make it executable, and that was accomplished with the single line above. No need for any other tinkering. I saved the file as twimi.list and created README and LICENSE files because apparently epm expects them. You can leave them empty, but they need to be there for some reason.

Once you have all of this set up, you can create a deb by running the following command (where you’d replace twimi with the name of your project naturally):

sudo epm -f deb twimi

KABLAM! The deb will magically appear in a subdirectory named after your platform and architecture - for me it was linux-2.6-intel. Added benefit is that you can use the same .list file to generate other types of packages. Observe:

sudo epm -f rpm twimi

In addition to basic linux packages can apparently also make osx and bsd ones as well - but you will need the prerequisite package management tools for those systems installed. So I couldn’t really create an osx package (and I don’t own a mac so I don’t know how would I test it), but the option is there if you need it.

Undoubtedly someone will probably tell me there is an easier and more straightforward way to do this kind of stuff. This method worked for me, but if there is another more proper, and equally straightforward way I’d love to hear about it.

Twimi

Tuesday, September 9th, 2008

You might remember that like a 100 years ago I posted a small snippet of code showing you how to post Twitter updates using nothing but curl. Well, I took that snippet of code, polished it up a bit and re-branded it as Twimi and posted it on Google Code under GPL. I know, I know - the script proper is like 3 lines long and it doesn’t really do anything other than calling curl. I’m pretty sure you could whip up a way better script like 5 minutes. Why the hell would I put up something so trivial up there?

Well, for one I noticed that other people did the same thing. Both ktwitter and ZenTwitter are similarly simple, and yet they show up as “Linux Apps” on the Twitter Fan Wiki. Both scripts seem no more complex than what I wrote so why the hell not call my script an “twitter client app”?

The thing is that if you have a twitter client project which has it’s own website you can request a custom source parameter for it. So you can sort of brand it. Previously every time I posted using my script, the twitt showed up as “from web”. Now, it says “from twimi” and links to the google code page for the project which is a nice touch. So I pretty much uploaded it up there just to get that custom link underneath my twitts every once in a while. )

The second reason for posting it there is perhaps some sort of small glimmer of hope that some shell scripting guru will be willing to contribute to it and add new cool features to it. Right now it is very simple an minimalistic. It is a starter script that you can take and modify to make your own curl based client. I’m not going to post the code here because you can just easily browse it on the project page. It’s only about 60 lines of code, not counting the comments, and GPL boilerplate. If you want to contribute let me know and I’ll add you to the project and you can hack away at it and perhaps the thing will grow on it’s own. I don’t really care for the direction we take it in. I don’t care if it grows a front end of some sort, or if you decide to toss curl in favor of something else.

I know this is not a real project. But, everyone knows a little bash, right? And everyone can write a better script than this in 5 minutes or less, right? So just do it!

Suggestions, comments and contributions are as always appreciated.

VirtualBox B0rken By Gutsy Kernel Upgrade

Tuesday, June 24th, 2008

I still have Gutsy on my work computer. I should really upgrade it to Hardy but unfortunately “dist upgrade in progress” is not really an acceptable excuse for not doing actual work so I keep putting it away. Ideally I could probably just run dist-upgrade during my lunch break, and then come back to a fully upgraded system. But every single dist-upgrade I did in the past required some babysitting so I’m not expecting this one to be any different. So for the time being I will stick with Gutsy - at least until I carve out a good chunk of time to devote to upgrading it, and potentially fixing anything that broke in the process.

Then again, maybe if I have upgraded earlier I wouldn’t have this VirtualBox issue today. At work I’m usually running a Windows XP instance inside VirtualBox so that I can access and use various Windows specific apps. Yesterday it just stopped working - it simply wouldn’t boot telling me that a wrong kernel module is installed. I wish I took a screenshot of the error message but I didn’t. Instead I started troubleshooting. First I needed to find out which version of kernel was installed on my machine:

lmaciak@malekith:~$ uname -a
Linux malekith 2.6.22-15-generic #1 SMP Tue Jun 10 09:21:34 UTC 2008 i686 GNU/Linux

It seems that my Kernel is 2.5.22-15. I vaguely remember pulling down some updates on Friday morning. A new kernel was among them, I believe. Next I took a quick peak on my VirtualBox installation:

lmaciak@malekith:~$ aptitude search virtualbox-ose-modules
i   virtualbox-ose-modules                   -
i   virtualbox-ose-modules-2.6.22-14-generic - virtualbox-ose modules for linux-image-2.6.22-14-generic
p   virtualbox-ose-modules-2.6.22-14-server  - virtualbox-ose modules for linux-image-2.6.22-14-server

It immediately became clear - there is a mismatch between my kernel and the installed modules. Unfortunately the only VirtualBox kernel modules in the repositories were the 2.6.22-14 ones. A 2.6.22-15 version simply doesn’t exist. Not for Gutsy at least and the Hardy release has to many unresolved independecies. So if you are still on Gutsy for some reason (like me) and you just updated your kernel (like me) you are now totally screwed (like me). The OSE version of VirtualBox just won’t work and there is no solution for this yet - and there may never be since Gutsy is on it’s way out.

There is a quick workaround though. Ditch the OSE version, and use the non-free binary under the PUEL License. I believe that my use of the software falls uder the “Personal use or Evaluation” clause since I’m not using it for hosting, and not sharing or distributing it. And I will likely only keep it only until I upgrade to Hardy.

If you are in the same boat, here is what you do. First get rid of your current VirtualBox installation:

sudo aptitude remove virtualbox-ose

Next, head over to the sun download page and grab yourself an appropriate deb file (pick Gutsy from the pull-down list). Install it via dpkg:

dpkg -i virtualbox_1.6.2-31466_Ubuntu_gutsy_i386.deb

It will go through the motions, and you may need to acknowledge one or two prompts as it configures appropriate kernel module. Once it is done, you should be all set. Please note that /usr/bin/virtualbox is unlinked replaced by /usr/bin/VirtualBox (note the camel case) which means any old aliases, shortcuts and key bindings will no longer work. You will have to manually adjust them. Other than that, the difference between the two versions in minimal. They use slightly different icons, and a different splash screen but for the most part it is the same software and you can easily use your regular VirtualBox images.

I hope this will help any potentially pissed off VirtualBox users who are still clinging to Gutsy for whatever reason. mrgreen