Posts Tagged 'linux'

Using kexec for a fast reboot in Archlinux

If you ever wondered how some distros achieve the trick of bypassing the BIOS when rebooting, it’s done using something called kexec, which wikipedia defines as:

[…]a mechanism of the Linux kernel that allows “live” booting of a new kernel “over” the currently running kernel. kexec skips the bootloader stage (hardware initialization phase by the firmware or BIOS) and directly loads the new kernel into memory, where it starts executing immediately.

In archlinux, you can achieve this with the package kexec-tools, which you can install as usual with:
pacman -S kexec-tools

kexec-tools is integrated with the archlinux initscripts, so that the kexec command line tool will by default go through the normal shutdown procedure before rebooting. You can find more information as ever on the excellent Archlinux Wiki. There are some scripts there which look pretty useful, but I started using kexec direct from the command line after reading the man page, and then wrote a short script to cover the form I was using each time.

#!/bin/dash

imgname=/boot/kernel26${1:+-$1}
krnname=/boot/vmlinuz26${1:+-$1}

exec kexec --type=bzImage --reuse-cmdline --initrd=$imgname.img $krnname

I saved this as ~/bin/kxreboot. You can either just use this without parameters to boot the default kernel, or you can add a single parameter – for example, if you do kxreboot mainline it will boot vmlinuz26-mainline with initrd kernel26-mainline.img

You might also ask, “Why would I want a fast reboot? I never reboot!”. Fair comment. I run the testing repos, so kernel and udev upgrades come along quite frequently. Also, my motherboard doesn’t recognise my USB keyboard on boot, which makes a BIOS boot a bit of a pain as I have to find a PS/2 keyboard. Last but not least, everyone loves faster, right?

Advertisements

cal – A command line calendar

If you already know about cal then you can move along, but if not please allow me to share this hidden gem with you.

(I find that the *nix command line is peppered with commands like this which are amazingly useful, and if you come from a *nix background they will be second nature to you. If, like me, you are a refugee from another OS, you may not have found some of them yet.)

With cal, it’s easier to show what it does than to explain it.

[~] $ cal
      May 2010      
Mo Tu We Th Fr Sa Su
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

cal by itself gives you a calendar for the current month.

[~] $ cal -3
     April 2010             May 2010              June 2010     
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
          1  2  3  4                  1  2      1  2  3  4  5  6
 5  6  7  8  9 10 11   3  4  5  6  7  8  9   7  8  9 10 11 12 13
12 13 14 15 16 17 18  10 11 12 13 14 15 16  14 15 16 17 18 19 20
19 20 21 22 23 24 25  17 18 19 20 21 22 23  21 22 23 24 25 26 27
26 27 28 29 30        24 25 26 27 28 29 30  28 29 30            
                      31                                        

cal -3 gives you a 3 month view.

What if you want a different month? No problem. cal mm yyyy will do it. Note that you need to use four digits for the year!

[~] $ cal 05 2009
      May 2009      
Mo Tu We Th Fr Sa Su
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Finally, cal -y will give you a year’s calendar. I won’t show an example here for reasons of space, but just try it for yourself. Naturally, you can do something like cal -y 2011 too.

There are a couple more options, so as always read man cal for the gory details.

How to remove thumbnails from a directory containing images

Following up from my last post about grabbing images from a squid cache, I needed a better way to remove thumbnails than just looking at file sizes.

I decided to try and get the image dimensions and then look at the mean width/height value.

This was what I came up with:-


#!/bin/bash

for file in *; do
    size=$(identify -format "%w %h" "$file")
    w=$(echo $size | cut -f 1 -d " ")
    h=$(echo $size | cut -f 2 -d " ")
    mean=$(( ($h + $w)/2 ))
    if (( mean < 300 )); then
        echo "$file $h $w $mean"
        rm "$file"
    fi
done

You will need the excellent ImageMagick package, which is available in most distros.

pptp

I have to interact with a lot of Windows systems, so pptp is the norm.  I’ve often tried to configure IPSEC but to honest, I’ve never made it work!  I read up on it, understood it in theory and then sat down to try again.  But heterogenous systems (Linux, my router, their router, etc.) all seem to present a different set of incomprehensible options with different names.  In the case of the routers, add questionable documentation.

Anyway, I just discovered the networkmanager-pptp plugin.  First, I installed network-manager-pptp and pptp-linux.  You need to make sure that your wired interface is configured to roam, otherwise you will not see the options for VPN configuration.

After that, I configured my VPN but couldn’t work out how to make the option appear to connect to it.  After some Googling, I found the answer:-

sudo /etc/dbus-1/event.d/25NetworkManager restart
sudo /etc/dbus-1/event.d/26NetworkManagerDispatcher restart

I suppose a reboot would have done it but I like to avoid those!

Now, I can just click and connect instantly.  Very neat!

MS SQL Server with Linux

I was wondering if this is possible, and it seems that it is.  I am using Ubuntu 7.10.

First I installed unixodbc and tdsodbc packages.  Then I mainly followed the instructions here starting at the “Configuration” part.  These were the key, because in my ignorance I tried editing odbc.ini directly and was also looking at /etc/freetds/freetds.conf which I don’t think is actually used when running with ODBC.

I can now use:-

isql <dsnname> <username> <password>

…and get a console to type arbitrary SQL in.  I tried using OpenOffice.org’s oobase, and although it connects and shows me a list of tables, it can’t seem to query any of them due to malformed SQL.  I’m not sure where the problem lies, but I was just experimenting.

Ideally I’d like to find something a bit like SQL Server Management Studio Express as a front-end, because I use that a lot.  I run a work site hosted on ASP.NET with a MSSQL backend, and I often have to run raw SQL to get around the lack of proper admin pages because the lazy developer (i.e. me) hasn’t written them yet.

While browsing package lists, I spotted mention of GNOME Data Access (gda) which has a freetds backend, so I will check that out too.

More links:-