Skip navigation.

Sign up | Lost password? | Help

Posts tagged with "linux"

Faster startup and shutdown

, , ,

Linux boots in 5 seconds.

Well, it's about time! This recent focus on bootup and shutdown times is quite welcome.

I remember when my old 1MHz Apple 2 used to boot up within about 5 seconds off a floppy disk. Sure, things were less demanding then, but CPU and I/O were also much slower. I'm quite certain that my old 386-33 used to boot Windows 3.1 to a usable point much quicker than my 2.2GHz Core2 Duo boots WinXP.

Glossing over the details, what it amounts to is that my computers are effectively slower in use than they used to be. All the progress in hardware performance has been more than offset by slowdowns in software.

It's not just desktop PCs either. My ADSL modem router takes several minutes from switch-on until it's ready to work. The reason is that it's using a general-purpose operating system, an embedded Linux. The problem is it's not a general-purpose computer. It's very much an application specific computer. It should be ready to work in a second or two. It's a similar deal with my network printer adapter, and my Wifi APs.

When I compare those devices with some network enabled things I've built myself (an NTP server and UPS monitor, both Ethernet TCP/IP devices), using no operating system, each of those boxes is fully operational less than a second after switch on. I don't expect that sort of performance from a general-purpose computer, but I do expect that sort of thing from a specialised box.

Getting back to the 5 second boot. This is exactly the sort of thing that Linux needs. It makes it a point of distinction compared to any other desktop operating system out there. People want to DO things with their computer, not sit and wait for it to boot. If people could walk up to their desk, turn their computer on, and have it ready to do things by the time they sat down in front of it - they would flock to such a thing.

It also makes it so much more appealing to embedded developers. I'd be stoked if my ADSL modem, NAS and Wifi APs could be operational in 5 seconds. In fact, the guy who did the 5 second boot admit they could make it boot even faster. Plus embedded devices probably won't need to launch an X-Window manager! p:

Update Tiddlywiki Java Saver

, , , ...

I was poking around the TiddlyWiki Trac site and noticed a new ticket #253 opened on my Java saving code.

Apparently one or more of Gentoo Linux, the Linux JVM, or Opera for Linux require the saving code (and probably the loading code too) to be wrapping in a PrivilegedAction class into order to execute, regardless of Java security policy settings.

The ticket included some code, but sorry "thomaskammeyer", I don't like your style! :eek:

Here's my new Java code:
import java.io.*;
import java.security.*;

public class TiddlySaver extends java.applet.Applet {
  class PrivilegedLoad implements PrivilegedAction {
    private String filename;
    private String charset;

    public PrivilegedLoad(String filename, String charset) {
      this.filename = filename;
      this.charset  = charset;
    }

    public Object run() {
      try {
        if (charset.length() == 0) {
          StringBuffer data = new StringBuffer();
          BufferedReader r = new BufferedReader(new FileReader(filename));
          String line;
          while ((line = r.readLine()) != null) data.append(line).append("\n");
          r.close();
          return data.toString();
        } else {
          File f = new File(filename);
          FileInputStream i = new FileInputStream(f);
          byte[] b = new byte[(f.length() > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)f.length()];
          int offset = 0;
          int num = 0;
          while (offset < b.length && (num = i.read(b, offset, b.length - offset)) >= 0) {
            offset += num;
          }
          i.close();
          return new String(b, 0, offset, charset);
        }
      } catch (Exception x) {
        x.printStackTrace();
        return null;
      }
    }
  }

  class PrivilegedSave implements PrivilegedAction {
    private String filename;
    private String charset;
    private String data;

    public PrivilegedSave(String filename, String charset, String data) {
      this.filename = filename;
      this.charset  = charset;
      this.data     = data;
    }

    public Object run() {
      try {
        File f = new File(filename).getCanonicalFile();
        f.getParentFile().mkdirs();
        if (charset.length() == 0) {
          int e, s = 0;
          BufferedWriter w = new BufferedWriter(new FileWriter(f));
          do {
            e = data.indexOf('\n', s);
            if (e == -1) e = data.length();
            w.write(data, s, e - s);
            w.newLine();
            s = e + 1;
          } while (s < data.length());
          w.close();
          return Boolean.TRUE;
        } else {
          FileOutputStream o = new FileOutputStream(f);
          o.write(data.getBytes(charset));
          o.close();
          return Boolean.TRUE;
        }
      } catch (Exception x) {
        x.printStackTrace();
        return Boolean.FALSE;
      }
    }
  }

  public String loadFile(String filename, String charset) {
    return (String)AccessController.doPrivileged(new PrivilegedLoad(filename, charset));
  }
  public int saveFile(String filename, String charset, String data) {
    return ((Boolean)AccessController.doPrivileged(new PrivilegedSave(filename, charset, data))).booleanValue() ? 1 : 0;
  }
}
Here's the above compiled into a new JAR: TiddlySaver.jar
To Jeremy: If you're reading this, the build script needs a small change: The jar command needs to refer to all class files, i.e. "TiddlySaver*.class".

I've tested this on my WinXP machine using the standard policy and it worked fine, but could not test on MacOS or any flavour of Linux.

I'm Never Upgrading Linux Again!

,

Hot on the heels of my last Linux disappointment (FC5s lack of smbfs support) is the tale of what happened when I did what I thought was the sensible thing and let yum do a general update.

The so-called "update" broke several things (that I know of). Awstats (a web server log analyser) broke, PHP stopped saving sessions, and Apache suddenly decided to forbid access to a folder. All those together were insignificant next to the disaster that unfolded when I discovered Samba was broken.

My FC5 machine is the file server of my network, and contains all the files for my business. No file access means no work. No work means no money.

After the update, Samba decided I was required to enter my username and password to access my files, but would not accept my correct details.

The Samba update looked like a minor bugfix update - just a tiny version change from 3.0.21 to 3.0.23. I would not have expected such a minor version change to cause such a major problem. Obviously the Samba guys managed to slip something big in! I spent nearly an entire day trying to figure out how to fix things, before giving up, wiping out 3.0.23 and reinstalling 3.0.21 from my FC5 CDs.

During my troubleshooting efforts I found some documentation on the Samba site that mumbled something about 3.0.23 requiring that some user groups be manually created and included instructions for doing so. They didn't work.

I can't afford a few hours downtime, let alone an entire day! I'm thanking my lucky stars I didn't have any deadlines this week, otherwise I probably would have been really stuffed!

I'm not the only one either. I was chatting with a fellow Samba user at a business I consult for and he'd had the exact same problem. And applied a similar solution!

I think it's appalling that a minor update can so totally break a working setup. Whatever new configuration was required to have the new version behave just like the old version should either have been automatically applied (perhaps just a new "fixed" config file created for manual merging with the existing config) or clear, working instructions should have been made available. So far this minor upgrade has defeated two experienced computer users, and I'm certain we won't be the only ones!

The lesson I've learned from all this is to not trust Linux updates. Once I get the system back up with everything stable again, I'm probably never going to do an update ever again!

Why Linux Isn't Popular

, , ,

Yes, this is a rant.

A few weeks ago I set up a new Linux box running Fedora Core 5 to replace an old Red Hat 6.1. New software, faster computer, etc, etc. What could go wrong?

For the first few weeks, nothing. I set up the web server, MySQL database and Samba file sharing. No worries. Then I acquired a NAS (Network Attached Storage) hard drive enclosure. This is a box into which you can install your own hard drive. It has an ethernet connector and a built-in Samba server (and FTP server), so you can just plug it into your LAN and access it like any other network share.

I did that and all my Windows boxes could see it no problem. Then I tried to mount it on my FC5 machine.

smbmount - "command not found". Huh? Samba's installed! A few minutes of Googling revealed the solution - mount -t cifs.

No so fast! "mount error 20 = Not a directory" :irked: Now what?

After much more Googling, it turns out the "smart" Fedora Core people have replaced smbmount with mount.cifs, except mount.cifs can't do everything smbmount can. Basically, CIFS != SMB. Only Windows 2000/XP do CIFS+SMB. Older Windows only do SMB, the same as my new NAS box. My old Linux box could do SMB, but not my new "upgraded" Linux box. :bomb:

What's even worse, is that it's just the mount command that can't do SMB. The smbclient tool can, as can the main samba file sharing (my Win98 box has no trouble accessing the FC5 file shares). Why why why?! Why cripple just this one corner of functionality?

After yet more Googling, it turns out I could probably get it working by rebuilding the kernel with smb support. I haven't built a Linux kernel since I built that old Linux box - more than five years ago. The procedure has no doubt changed a bit since then. I'd have to find the kernel sources, download them, figure out how to put my settings in, figure out how to put smb in (since it's not in by default), rebuild it (I don't think I bothered installing the C compilers on my new box, so I'd have to do that too). Then install it.

:no: What should have been a minute or two, has already taken up more than half an hour, and is now stretching into hours of hard work! Not gonna happen.

That, my friends, is why Linux is pants. Far too often the monkeys in charge get distracted by new shiny things and forget about the important stuff - like having things work.

Adding Reports to Logwatch

, , ,

I've recently set up a new Linux box to act as a home server to replace my ancient Red Hat 6.1 on a 486/66. One of the new features is the use of Logwatch, which is set up to run once a day and generates a single email gathering together various log file analyses and other status reports. I've also got a domain name with DynDNS. My modem/router is capable of automatically updating my home IP address with DynDNS, but I had noticed the odd occasion when it hadn't.

So naturally I wrote a little script to do a DNS lookup of my DynDNS domain name and compare it with my ISP-assigned IP address. I popped that into cron.daily and started getting two emails a day. Getting one email a day would be much better - rolling my script into logwatch seemed the perfect solution.

The problem is the Logwatch customization documentation is a bit heavy going. Especially when all you want to do is add a scripts output to the report. Just in case there's anyone like me, who would like to do such a simple thing, but haven't bothered because it wasn't spelled out for them, try the following.

Not including your script, only one extra file is required by logwatch. Put this file in /etc/logwatch/conf/services. Call it something like my-report.conf. It should contain at minimum something like:
Title = "My Report Title"
LogFile = NONE
Next comes the script itself. It goes into /etc/logwatch/scripts/services. It must be given a name that corresponds to the conf file you created earlier. In this case the name must be my-report. My script was already in /usr/local/sbin under a different name, so I just created a symbolic link to that.

Whatever the script prints to stdout, goes into the logwatch report. So simple!
December 2009
S M T W T F S
November 2009January 2010
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