Archive for October, 2008

Doing it the hard way, rather than the really hard way

October 31st, 2008 by Sjan Evardsson

When I shut down the server, prior to moving, I installed an extra hard drive I had laying around before packing it up to be shipped. With the move, and all the work and busy running about since then, I managed to forget that there was a 40GB drive, just waiting to be used.

The other day, I noticed in my daily email from the emerge –sync that cron runs, that it was unable to complete because there was not enough space on the disk. I logged on and df -h showed me that, yes, the drive was full. I did some cleanup and maintenance on the drive and managed to clear out about 1GB of space. This is important, because I needed to increase the size of my boot partition. When I first built this server (using Gentoo 2006.0) I had been having terrific results with a tiny little 32MB boot partition. Now I was having problems, because the boot partition didn’t have enough room to build the initrd for 2.6.27-gentoo-r1. I’m not sure why, but for some reason every kernel I have tried to compile after 2.6.25-gentoo-r1 (including r2, r3, r4, and r5 of the same kernel branch) would create an initrd that was in the 25MB range. Well, that plus a kernel and the configs and you have a no-go on a 32MB boot partition.

Anyway, after cleaning up the drive I was going to use parted to shrink the root partition and grow the boot partition. But parted requires that ext2 and ext3 partitions always start from the same block. Not a problem, the plan was to shrink the root partition, move the swap partition there and then grow the boot partition. Then the really hard part would have come – finding another drive (since this one was too small) and taking the entire server down for a rebuild. Ugh.

So I fired up parted and did a print all to see the block numbers for my partitions, and there it was, 40GB of unused space on another drive. (You probably heard the facepalm from wherever you are and wondered what that noise was.)

So, using good old cfdisk I created 3 partitions on the new drive, a 19GB ext3 partition, a 20GB ext3 partition and a 1GB swap partition. I copied the contents of /usr to the first, and the contents of /var to the second and used a little command chaining to put those where they belonged. (If you are curious, it went something like mv /usr /usr.old && mkdir /usr && mount /dev/hdd1 /usr followed by the same sort of chain for /var and then restarting a few services that point to files in var or usr).

I then did a swapon /dev/hdd3 swapoff /dev/hda2 and then edited fstab to match the new layout. Now for the fun part. Since I didn’t see a way in parted to delete a partition I shrunk the old swap partition down to 1MB, and then resized the boot partition to fill the new space. I did run into an issue where parted gave the error “Error: Filesystem has an incompatible feature enabled.” I found the fix for that to be using tune2fs to turn off resize_inode. That means no online resizing, but since this is not on an LVM that is not an issue. So, run tune2fs -O^resize_inode /dev/hda1 and then run parted and whoosh! A larger boot partition that will fit the massively fat initrd I am trying to stuff in there, and things are better. And with /usr and /var split off onto the new disk the root file system disk now has 11GB of space available.

And, in the spirit of doing things the hard way, I am posting this from my iPhone while laying about waiting for the stomach cramps to subside enough to sleep. (I hate this flu.)

Learning Python

October 8th, 2008 by Sjan Evardsson

I was asked today “How do I learn python?” (I’m not making this up, that is a direct quote lifted right out of the chat log!)

Of course my first response was “start at python.org” (as it would be.) That is all well and good, but I started thinking about what specific things helped me? So, here are some specifics that might work well for you if, like me, you learn about half and half from reading (theory) and doing (practice.)

The first step, of course, is to download Python. You don’t need a fancy IDE to develop in Python, although if you have one you are comfortable with and use all the time, chances are that it has a Python plugin. (I know Eclipse does, and I believe NetBeans does, and jEdit has a Python client plugin that lets you run Python code right in the editor.) If you don’t want to muck about with an IDE, though, Python comes with it’s own lightweight editor, IDLE. Open it up, play around a bit.

Ok, so you’re looking at IDLE thinking “well, there isn’t much here is there?” You’re right – time for step two. Head over to the beginner’s guide and go for it! There are tutorials aimed at people who are new to Python and to programming in general, and people who are new to Python but not to programming. There is even a list of Python courses you can buy, and a fairly large list of introductory Python books for those who learn best that way. There isn’t much I can say that isn’t there already. I kind of wish that I had started there myself. When I started playing with Python I skipped over this and went straight for the documentation and googling for specific answers, as I was trying to build a script that I needed at the time to parse 1 -2 GB log files. Java was too much tool for the job, I didn’t have access to a beefy enough Linux box to do it in Bash and PHP was doing nothing but running out of memory. It made for a bit of a rough entry into Python, but I kind of like that sort of challenge.

Which brings us to step three – build something. No, not a “Hello World” app, but something useful, in the immediate sense. Something that will make you smile, or make your life simpler, or even something that will allow you to tick off an item on your to-do list.

So what (besides the end of my rambling in parenthetical asides) are you waiting for?