Archiv der Kategorie: Linux

Automate all the things!!!

Recently, I have been doing a lot of work a server administrator would normally do. I set up a continuous integration system and played around with virtualization at work and deployed a couple of python apps for a side project. Being a software developer, this has been both a challenging and fun experience. It also got me thinking about all the buzz about dev-ops you read nowadays. Dev-ops (development and operations) refers to a company structure where the development and server administration teams work very closely together or even without a clear distinction between the two fields. I am very much in favor of close collaboration, but the approach also has its caveats.

As a developer, my main responsibility is to create and maintain good software and although I know the basic concepts I am not trained in systems administration. Yes, I can install a server and get my application running. I will also go ahead and disable root login via ssh to prove my security lectures were not a complete waste of time. But without following the subject closely and practice and improve my skills on a day-to-day basis, like a full-time sys-admin would, it is very hard to bring a system in a state where security best practices are followed, redundancy is properly implemented and good sleep can be found at night.

A picture of me while installing Buildbot on a Vagrant machine.

For this reason it is the least we can do as developers dropped into the engine room to document very carefully what we do. Because what will happen is, we will get it to work, walk away and forget about it. Then a week later something will break and we’ll have to put on the old sys-admin gloves once more only to redo the whole research and learning process again. Or maybe somebody asks you how you set up the external juggly-tubes on that one server. „The what? Gee, I don’t remember.“ A good documentation – a recipe on how to get a specific job done – can save the day.

And the best documentation when it comes to server administration is automation.

Automation comes in many shapes and forms depending on the job and the personal preferences of the people involved. It can be an elaborate shell script or a complex automation tool. In any case you’ll end up with something that describes the task you were trying to complete and it also does complete the task. Perfect.  Next time somebody calls you to tell you the fancy new app on the virtual cloud docker thing has crashed you can just press a button and automagically re-deploy the thing.

So, please don’t have any machines in an undocumented state running in your production or development environments and best make sure everything is properly automated and the process is reviewed every now and then.

Encrypted Dropbox Backups

Data backups are probably one of the most annoying topics in the world of computers. Yet they are a necessity if you want to minimize your risk of data loss. There is tons of commercial products that do the job and probably more strategies employed than people living on earth.
So I just want to describe my approach and if someone comes across this I am happy to hear about your opinion in the comments!

I generally divide of all the files on my computer in three tiers:

  • Completely reproducible: Everything that is reproducible with low or no effort. For example all the stuff that comes with a Linux distro, binaries, etc.
    This tier obviously needs no backup.
  • Large non-reproducible files: Music, Pictures, Movies, etc. Everything that I want to keep but it’s too large to just keep it in a Dropbox folder or something comparable.
  • Small non-reproducible files: Mostly documents like invoices, CVs, config files. These files are small and thus easier to handle in terms of backup.

So with two different tiers of files that need backups I also have two different strategies that I use:

External hard drive Backups

I have a little one liner shell script that just calls rsync with a couple of parameters and creates a copy of all the files in my home folder. The files in the exclude list file are skipped, for example the „Downloads“ folder where I generally have large stuff that I don’t really need lying around. Have a look at the script here.

There are two Problems with this approach:
First: It’s not technically a backup, it’s just a copy. A „real“ backup has to be incremental, such that I could go back to any snapshot I ever took. With a copy if you ever damage an original file and run a backup that file is lost. But I decided that it is good enough for me.
Second: It’s not off site. It does not protect my data from a fire or a very thorough thieve who steals both my computer and the external hard drive.

Encrypted Dropbox Backups

Dropbox is a service that I guess many people use for file backup and it’s great and easy to use, but unfortunately in the post-Snowden era we have to assume that everything that is on Dropbox is readable for at least the US-Government agencies. If you properly encrypt your data before you send it to Dropbox however you’re good to go.
That is if we assume that the employed encryption algorithm is unbroken. If you followed the Snowden revelations you might feel uneasy to trust any kind of encryption, but just as Bruce Schneier says: I trust the mathematics.

So I wrote a little script that collects all those smaller files I want to backup, packs them into a tar-gzip archive with a time stamp in the filename, passes this to gpg, which uses the CAST5 Algorithm to encrypt the tar file using a user supplied password.
Finally, the encrypted file is moved to the Dropbox directory and thus automatically uploaded to Dropbox. Have a look at the script here.

I don’t have s strict rule when I execute those script, I just do it sometimes when I think of it, which obviously is not optimal and I will try to find a doable way of doing it more regularly.

So that’s it, please let me know what you think about this in the comments or describe your approach.

So I left Arch Linux… what’s up with that?

About a year ago I started this blog, primarily as a sort of public collection of notes on how to do things on Linux, especially Arch Linux.

At the time I was annoyed by a lot of decisions Canonical made with Ubuntu, which I had been using for quite a while. So I made the decision to retake the control I felt canonical was taking away from users by switching to Arch Linux. This article is essentially a summary of my experiences with it and an explanation on why I am not using it anymore.

When my new laptop arrived in January of last year I immediately installed Arch Linux on it. For someone like me who’s Linux installation experience is basically „insert an Ubuntu live CD and click install“ it was quite a challenge, but the Arch Wiki provides an amazing guide that made me succeed eventually (The Arch Wiki and Forum are in my opinion two of the best places in the internet to get help with Linux, not only Arch).

The Awesomeness

  • It’s customizable: The main reason for me to try Arch Linux, as I said earlier, is it’s customizability. You have to hand pick the software packages you want to be installed. This includes the Window Manager or Desktop Environment of your choice. So in the end you wind up with an operating system really suited for your needs.
  • It’s up-to-date: Arch is a rolling release distribution, which means that once an update for any package becomes available it will (almost) immediately be available for Arch users. Release cycle oriented distributions like Ubuntu also have an update function for bug fixes and security updates, but „bigger“ updates will only be introduced in the next release of the distro. (There are of course ways to still get the latest version of almost everything, but it requires knowledge and work and kinda conflicts with the whole idea of a release based distribution)
  • It’s a great source of knowledge: The process of installing Arch Linux alone is probably one of the most effective ways to learn how Linux works and is configured. And even the running system sometimes requires you to dig deep into the file system to tweak a config file. I have learned much about Linux during my time with Arch, most of it on the Arch Wiki and forum.

So I ran Arch for the better part of 2012 and was quite pleased with the things I mentioned earlier, but there were also some things I did not like so much.

The Annoyances

  • Stuff breaks… often: Arch is bleeding edge. You get every update almost instantly… what?… I said that already? Yeah, it’s a big plus, but also in stability and convenience terms it’s a pain in the butt. You have to be on guard every time you update your system, you have to follow the mailing list and there is a good chance you have to fix something after the update. Again, thanks to the Arch Community those fixes are almost always available in the forums, but you still have to do them.
  • Your system is unique: And that makes it sometimes a bit harder to troubleshoot stuff. Especially if you are not sure what’s causing your problem. Other peoples solutions might or might not apply to your setup. Of course this is not an Arch exclusive problem, but my guess is that is happens more often than with more restrictive distributions.

The last two points are only a problem if you do not have fun fixing problems and learning stuff (which I did) or if you simply don’t have the time (this one applies to me). I do all my work for the university on my laptop and it needs to work all the time. Also I use it as an entertainment device to watch movies, listen to music or play games. (Boy, has Linux gaming taken off lately 😀 ) And if I want to do one of those things, it needs to work.
I hate it to sit down and write some code only to find out that the last system update has broken the compiler or something.
So, Arch Linux, it’s not you, it’s me! There is nothing wrong with how Arch is, but it has just turned out not to be the right thing for me now.

That’s why I eventually decided to ditch Arch and switch to Linux Mint for now. I am now running Mint 13 Maya Cinnamon Edition and am quite happy with it.
I am almost sure that I will come back to Arch someday though!

Thinkpads throttle CPUs down when battery is removed

I was pretty sure that the proper way to treat your laptop battery, if you want a long fulfilling life for it, is to remove it from the laptop when you are connected to an AC adapter. After all the lifespan of a laptop battery (or any rechargeable battery) depends largely on the number of charging cycles. Now if you leave the battery in the computer when it’s connected to the AC adapter, it will drain it just a little bit and then recharge it again over and over. This is true at least for the default setting of Lenovo ThinkPads (as you can read here).

Now let me back up here a little: Today I noticed one of my current programming projects performance dropped significantly over night. I ran a benchmark last night and the same this morning without any major changes, but got much worse results. So I looked for the reason in the code, reverting my recent changes (which should not affect performance at all, but just to be sure). Just before I started to believe in black magic and question my sanity, I thought maybe the reason isn’t in the code after all but my computer is just somehow slower. So I did a little research and finally noticed something odd in the output of cpufreq-info for all 4 cores:

  analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 10.0 us.
  hardware limits: 800 MHz - 2.30 GHz
  available frequency steps: 2.30 GHz, 2.30 GHz, 2.00 GHz, 1.80 GHz, 1.60 GHz, 1.40 GHz, 1.20 GHz, 1000 MHz, 800 MHz
  available cpufreq governors: powersave, ondemand, performance
  current policy: frequency should be within 800 MHz and 800 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 800 MHz.

What? „Frequency should be between 800 MHz and 800 MHz?“ That’s a rather tight margin! Of course this would explain the performance drop, but where does this come from? Changing the governor or setting the frequency manually did not change anything. Some web research showed that I was by far not the only one experiencing the problem and that can have multiple reasons. Explanations include kernel bugs and overheating CPUs. I could exclude the overheating and did not want to believe in kernelbugs yet. So I looked on and finally found an issue affecting Lenovo Thinkpads exclusively:

According to this article from ThinkWiki, the included AC adapters 65W are not enough to provide enough power to the system when it is on full load, so the BIOS decides to set the frequency to the lowest value and keep it there, if no battery is found. The article also offers a quick fix to this: Add processor.ignore_ppc=1 to your parameters in /boot/grup/menu.lst and everything will be fine. I tried it and yes, it really fixes the problem, but it’s not supposed to be safe as it doesn’t change the fact that the adapter doesn’t supply enough power. So when on full load the system can crash, I guess. So far it hasn’t for me.

So this leaves me with three options:

  1. Use the fix described above and risk the possibility of crashes.
  2. Leave the battery inserted always and risk decreasing it’s lifetime.
  3. Buy a stronger AC adapter. There are 90W and even more powerful ones available (but the 90W is enough for the T420; see this thread)

I have not decided yet, but am probably going with option three, since the extra adapter costs less than 20€.

Anyway, I’m a little angry at Lenovo now. I mean if they ship an inferior Adapter with my laptop, they could at least tell me. (People in this thread argue, that it is not inferior, because it is smaller and lighter and thus easier to carry.)

Merging multiple images to one document file

Recently I read an interesting article in a newspaper (you know, printed on paper and such…. oldschool). I wanted to show it so some friends and so I scanned it, giving me five jpeg files.

Remember those?

To make the reading more convenient for my friends I wondered if there was a way to merge them into one document file, preferably PDF.

The solution I found is no dirty hack and probably widely know. I however was unaware of it until today and it is so beautifully easy that I wanted to share it with you.

The savior once again is ImageMagicK. If you don’t have it installed, it is available via the extra repo. Then simply execute the command:

convert page1.jpg page2.jpg […] pageN.jpg article.pdf

And that’s it. Isn’t it beautiful?

Btw: This is only one of a million applications for the ImageMagicK package, which is definitely worth having a look at.