Non-interactive router reboot HOWTO

7 04 2009

Hi everyone!

I’ve recently been having trouble with a router getting all bunged up due to the high levels of data passing through it. Invariably, I come in in the morning and we’ve lost access to the Internet from some of our stations until I’ve rebooted it. While I’m in the process of building a routing box for the network, I wanted to know if I could automagically have the router reboot itself well before anyone would be wanting access.

As with almost EVERYTHING Linux oriented, the answer is OF COURSE I CAN!

There’s a nifty little utility within Linux called expect. It comes as standard with Slackware, so no installation needed for me. It allows pre-programmed non-interactive access to normally interactive shells. The script I’ve written looks like this:

#!/usr/bin/expect -f
set address [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set routercmd [lindex $argv 3]
spawn telnet $address
expect "Login:"
send -- "$username\r"
expect "Password:"
send -- "$password\r"
# This command gets us out of the default menu and into a shell
expect "> "
send -- "sh\r"
expect "# "
send -- "$routercmd\r"
#exit
send -- "^D"
send -- "^D"

As you can see, expect is used as the script handler with the -f flag, which would usually point to a script file to be run.

The script really is incredibly simple…

It takes 4 arguments in this order:
address – The router’s IP,
username – The router’s admin username
password – The router’s admin password
routercmd – The command which you wish to run

In my case, I’ve set up a cron job to run daily at 4.40am (the default for cron.daily) which runs the command /usr/local/bin/routercommand.exp 192.168.1.1 **username** **password** reboot. I am yet to see whether 4.40am is suitable, but it’s a step in the right direction!

Anyway, I hope this has been of interest or maybe even use!

n00b

UPDATE – 09/04/09

This has completely fixed our problems with the router. We have seen flawless behaviour since. Whoo! Now if I could only get Smoothwall doing PPPoA with the router in bridge mode! Any ideas would be very helpful!

n00b

UPDATE – 24/04/09

It seems that all of these modem/routers which claim to fully support bridge mode are at best exaggerating. The best results it is apparent that you can expect is intermittency, which is TOTALLY USELESS in a production environment. The way forward is using a true PPPoA to PPPoE bridge modem. I’m using a Draytek Vigor 110, because by all accounts it ACTUALLY WORKS (shock, horror!).

Anyway… Just thought I’d feed you all that useful little nugget of knowledge. Hopefully I’ve saved even one person from losing sleep over it.

n00b





Slackware Bootsplash Howto

3 02 2009

Hi all. I don’t know about any of you, but the fact that the original bootsplash patch is becoming obsolete and being superceded by sucky… sorry, I mean splashy… really pisses me off. I love the simplicity and speed of bootsplash, and splashy has failed to deliver on almost every front. It’s slow, ungraceful, difficult to make really pretty, and what annoys me more than anything is that the verbose mode is utter crap. Kernel panics will never be easy to diagnose again.

I don’t install bootsplash often enough to know it off by heart, and I find that every time I install Slackware on a new system I want to put a bootsplash on I can never exactly remember how — cue many frustrating wasted hours trying to get it sorted. I’d imagine it’s a problem that I’m not alone in encountering, so for your intellectual enjoyment (and hopefully to help retain your hair’s colour!), here’s a full howto.

NB: If you are a newbie to compiling kernels, creating initramfs images and reconfiguring LILO, then consider seriously practising/reading up on them before attempting this, as you could render your system unbootable.

Step 1: Patch, configure and install the kernel.

You’ll need a working patch for the kernel you’re using. Sometimes a patch from a previous kernel will work, but always patch with the following tags first:

patch --dry-run -p1 < bootsplash-3.1.6-$(uname -r)

This will just test the patch. If you get any HUNK FAILED messages, then DON’T USE IT! Also, if you are trying a patch from a different kernel, then replace $(uname -r) with the patch’s kernel version.

You will now need to configure the kernel using your favourite .config editor. I’m a huge fan of xconfig (type make xconfig in your kernel’s unpacked directory). You will need to turn OFF the existing bootup logo and turn on the bootup splash screen. It’s probably a good idea to make sure you have initrd/initramfs support in there too.

Now compile and install your kernel. If you don’t know how to do this, Eric Hameleers (Alien Bob) has written an excellent guide on his Dokuwiki. Take heed of all of his warnings, as doing this wrong could hose your computer. See you after the KERNEL PANIC.

Now boot up your new kernel.

Step 2: Download, compile and install the splash util.

There are countless copies of the splash utilities scattered around the internet, and the places you’ll find them change regularly, so I can’t give you a direct link, but version 3.0.7 seems to be a pretty good bet, and easy to find.

Once you have downloaded the package, just typing make will result in a huge b0rk-fest. The only binary you need is splash, so just type make splash, and you should be ok. Now copy this into /sbin and that’s step 2 complete.

Step 3: Make your initramfs format initrd.gz

I find this is where the guides all start to tell fibs. They all tell you just to use the splash binary and redirect the output to a file. THIS DOES NOT WORK. The reason being that Slackware now uses an initramfs image for it’s initial ramdisk, which is a compressed cpio archive. Just using this file will not be recognised, and annoyingly there will be no useful pointers to show you what’s wrong.

First off, you’ll want to download a bootsplash from somewhere. Kde-look has some pretty nifty ones. Now create the directory /etc/bootsplash/themes. Put the files you downloaded in here in the format /etc/bootsplash/themes/theme-name/images and themes/theme-name/config.

UPDATE (8/7/2011):

If you are creating your own images to use as a bootsplash, you will need to make sure that they must be in YCbCr 221111 JPEG format, which means that they must use the JPEG file format, YCbCr color space, and subsampling must be set to 2×2, 1×1, 1×1. This is achieved in GIMP by choosing JPG format, and then under Advanced Options, selecting 2×2, 1×1, 1×1 (smallest file) from the Subsampling drop down box. Simple when you know how!

Now to actually create the initramfs. First of all, check for the existence of a file called initrd.gz in your /boot folder. If there is one there, then you should back it up before proceeding, as it will now be blown away. Navigate to /boot and type:

mkinitrd -c -k $(uname -r) -f filesystem on root partition -r /dev/root partition

There will now be a folder called initrd-tree in /boot. This will be the contents of your initrd. Navigate to this folder and use the following command:
splash -s -f /etc/bootsplash/themes/theme-name/config/bootsplash-1024x768.cfg > bootsplash

This has placed some information for the kernel on the location of the bootsplash theme in the cpio archive. You now need to place the bootsplash into the folder in exactly the same directory structure that exists on your filesystem. Create the folder /boot/initrd-tree/etc/bootsplash/themes and copy in the bootsplash theme you downloaded and installed earlier.

To finish off our penultimate step, go to /boot again and type simply mkinitrd to compress the contents of /boot/initrd-tree into the initrd.gz file you will now see in the /boot folder.

Step 4: Reconfigure LILO and reboot.

Ok, we’ve got to the point of no return. You have a working bootsplash enabled kernel and a brilliantly put together initramfs image. Now you’ll need to modify the /etc/lilo.conf section which points at your new kernel as follows:
image = /boot/vmlinuz-custom-2.6.27.7-1 # Or whatever your kernel image is called
root = /dev/hda7 # Or whatever your root partition is.
label = Slacksplash # Name it anything you like
initrd = /boot/initrd.gz
append = "splash=silent"
read-only

You will also need to configure LILO to boot in the screen mode for whichever resolution and bit depth the splash image is in. You can find a list of VESA screen modes here. You can either use the decimal or hexadecimal values. Lilo will understand both, but make sure you prefix the hexadecimal number with 0x… Here is an example:

# First of all in decimal:
vga=791
# This is the same as the following in hexadecimal:
vga=0x317

If you get the screen depth wrong, all will appear to go fine, but you won’t get a splash image. I have to fiddle with this almost every time I apply a bootsplash!

Once you’ve got it configured, run lilo. I tend to use lilo -c -v as -c speeds up the initial loading of the kernel (compact mode), and -v gives you a whole bunch of useful information to help troubleshoot any problems.

Now reboot, select your kernel from the list and admire all the beautiful colours swirling across your screen.

That’s it… Done. Any questions just leave me a comment.

n00b