October 2008 Archive

Linux Viruses?

October 22nd, 2008

I don’t run any anti-virus software on my laptop, for one I run Linux but the main reason is that I’m careful what I do. I open all my emails in plain text, don’t run file sharing software and so on. Of course it’s currently true that in-the-wild viruses on Linux are almost unheard.

It’s long been argued by opponents of Linux that the lack of Linux viruses is only because virus writers target the largest user base, meaning Windows, not because Linux in inherently more secure. But I wonder with mobile phones becoming more powerful, Linux being relatively bigger in the mobile phone space and the reports that in future virus writers will target phones if this will be put to the test.

Google recently released the source code for their Linux based Android platform and they obviously hope that by creating an open framework they will appeal to many manufacturers and grab a slice of the market. If virus writers start to target Android then maybe the argument regarding Linux security can be laid to rest one way or the other.

Trying to Write a Shutdown Script

October 21st, 2008

I’ve been trying to create a python script runs on shutdown or reboot. First I tried using the init system by placing the script into the /etc/init.d directory and then creating symlinks to the rc0 and rc6 directories so it runs shutdown and restart (all as root).

# cp myscript.py /etc/init.d
# ln -s /etc/init.d/myscript.py /etc/rc0.d/K10myscript.py
# ln -s /etc/init.d/myscript.py /etc/rc6.d/K10myscript.py

This doesn’t work, at least on Fedora, I think due to the fact that the init system checks for the presence of a file in /var/lock/subsys. Essentially the system checks whether a service is running (the lock file exists) before deciding to run the script.

In this case I would have to add my script as a service using chkconfig -add that starts on boot and creates the lock file. This is fine but what if I just want to run a simple script and not a service.

Next I looked at Upstart, the replacement for init scripts developed by Ubuntu but now the default in Fedora 9. This is compatible with the old init system but much more flexible. Following this great guide I tried to implement this using Upstart. Here’s my script saved in the /etc/event.d/ directory.

# Run my script on shutdown, reboot and runme events
start on runlevel 0     # Shutdown
start on runlevel 6     # Reboot
start on runme          # testing event
script
exec "/home/username/network_usage.py"
end script

I tested the script by emitting the runme event.

# /sbin/initctl emit runme
runme
network-usage (start) waiting
network-usage (start) starting
network-usage (start) pre-start
network-usage (start) spawned, process 3673
network-usage (start) post-start, (main) process 3673
network-usage (start) running, process 3673
network-usage (stop) running
network-usage (stop) stopping
network-usage (stop) killed
network-usage (stop) post-stop
network-usage (stop) waiting
initctl: runme event failed

Basically the script fails. I tried to run a bash script that calls the python script but that also fails. Upstart seems really easy to use and it’s much easier to test since you can create fictional events but I’m frustrated by my inability to run a simple python script.

I realise that I could write a bash script instead of a python script and it will probably work, or I could put my script in .bash_logout but that would run on user logout and not only on shutdown and reboot.

If anyone has a solution I’d be happy to hear.

Upgrade Java with Netbeans Installed

October 17th, 2008

Yesterday I decided to upgrade my Sun Java JDK install, it was at version 1.6.0_06 but I’ve now installed 1.6.0_10.

As a side note also this shows how lazy I get with Linux when you are used to having all your software upgraded automatically. In this case I have to install the Java JDK myself so like most users I’m not that good at updating software, especially when it’s not something I can see, unlike Firefox or some other GUI application.

There are many pros and cons of the Linux vs the Windows way of installing software but there’s no denying that updating software centrally keeps the user far more up to date, and so secure, with no effort at all on the users part. Ironically this is probably something Windows users need more than Linux users.

Anyway, back to the point. After upgrading I ran the usual /usr/sbin/alternatives command to use the new install as my default Java. But after checking some applications that depend on Java I discovered that Netbeans would not start due to the following error:

$ /opt/netbeans-6.1/bin/netbeans
Cannot find java. Please use the --jdkhome switch.

Sure enough providing the new JDK location successfully started Netbeans.

$ /opt/netbeans-6.1/bin/netbeans --jdkhome /opt/jdk1.6.0_10/

This was fine but I wanted the change to be permanent but couldn’t find a config file in my $HOME/.netbeans directory. It turns out the file is located at /netbeans-install-directory/etc/netbeans.conf, in my case /opt/netbeans-6.1/etc/netbeans.conf

Edit the following line as root and save the file to make your change permanent

# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="/opt/jdk1.6.0_10"

The Flexibility of Linux

October 15th, 2008

After writing about the new netbook craze and thinking of buying one I’ve been spending some time researching the options. If I do buy one I’m pretty certain that I’ll be installing a new distribution on the device since the Linux distributions they ship with seem a bit limiting for me.

It’s for this reason I’ve looked into how easy it is to replace the distros and one thing becomes very clear, Linux itself is immensely versatile and the community around Linux is incredibly productive and inventive.

Just looking at the Eee PC and Acer Aspire One there dozens of sites with modifications, hacks and plenty of resources being put into tailoring distros to work flawlessly with these computers. Both Ubuntu and Fedora have projects being worked on to the Eee PC while the Aspire One has the same

The openness offered by Linux and other open source projects allows users to re-spin existing Linux distributions to fit almost any hardware out there. Plus, from a technical perspective, I’m sure it’s much more rewarding to have complete freedom to create what you like.

Compare this to buying a netbook with Windows XP where you get a closed source OS that’s basically 7 years old and the only reason you’re allowed to get it in the first place is that Microsoft is scared to loose marked share to Linux while accepting that Vista is far too bloated to run on these netbooks.

On top of that Microsoft limit the netbook specifications to allow it to be licensed and there’s very limited possibilities for users to tweak XP for a specific netbook in the way one can for Linux.

Many people complain about the diversity in the Linux marketplace but as Linus Torvalds himself says, this diversity is good for the community and he future of Linux itself.

Will Oracle Bid for Red Hat

October 11th, 2008

There’s some speculation that Oracle will make a takeover bid for Red Hat, especially in the current financial crisis where despite good results Red Hats share price is plummeting.

Knowing how the Linux community reacts to these type of events I doubt this would be good news for Fedora. Looking at the bad press that Novell gets these days with it’s own boycott Novell website after their deal with Microsoft I could easily see people passing Fedora over and moving to another distro. Oracle is not exactly known for their openness and the loss of Red Hat, with it’s position as a flag bearer for the open source community, would be major blow.

Just to confirm how much Red Hat gives to Linux just look at the latest Linux Kernel Development report.

Boot Time Update

October 7th, 2008

After posting about my experiences trying to decrease my own boot times it was interesting to read this LWN.net article about two Intel developers getting Fedora to boot on the Asus EEE PC in under 5 seconds.

One item I found very relevant to my own experience was that they stopped the setroubleshootd service from starting as it took 5 seconds. Using both the Fedora and the vanilla kernel, stopping setroubleshootd shaved 4 seconds off my boot time, so now the vanilla 2.6.26.5 kernel boots in 29 seconds and the Fedora kernel in 39.

Of course not may people are going to go to these lengths to boot in 5 seconds but what matters is that they have shown it is possible and it sets a focus on the issues which will inevitably filter down to ‘normal’ users such as myself.

Compiling Your Own Kernel to Decrease Boot Time

October 3rd, 2008

After reading about Fedora and Ubuntu attempts to speed up the boot times I thought I’d see how my boot times compared, plus if there was anything I could easily do to improve mine.

First I installed Bootchart, it’s in the Fedora 9 repositories so it’s a simple install.

# yum install bootchart

That’s all the is to it, it even edits your grub.conf to append the init=/sbin/bootchartd to your currently running kernel (to stop Bootchart running each boot just remove this entry from your grub.conf).

After booting the Bootchart output is saved to /var/log/bootchart.svgz, but just running the command bootchart with no arguments will automatically parse the file and format the output into a svg file in your current directory.

Running a stock Fedora 9 kernel (2.6.26.5-45.fc9.i686) gave a boot time of 42 seconds, not that bad for a 5 year old laptop plus I’m running SELinux. This is probably because I have already turned off many services that I rarely or never use.

As a comparison I decided to download and compile a ‘vanilla’ 2.6.26.5 kernel from kernel.org. Running `make menuconfig` I was fairly ruthless with removing unneeded options and trying to compile most options into the kernel instead of into modules. For example my laptop has a pccard slot but I never use it so I removed support in the kernel.

Another optimization I tried was to remove all the debugging options under ‘Kernel Hacking’ and to remove the ‘Compile for size’ option under ‘General Setup’ so the compiler uses the -O2 flag instead of -Os, as the help says:

CONFIG_CC_OPTIMIZE_FOR_SIZE:
Enabling this option will pass "-Os" instead of "-O2" to gcc
resulting in a smaller kernel.

I didn’t change anything that affected the functionality of my laptop, it still works perfectly, plus I didn’t compile all options into the kernel (ipw2100 wireless to name one) or remove everything I could have.

The result of running Bootchart with the new kernel gave a boot time of 33 seconds. That’s a 9 second or 21% speedup! I must admit that it was more than I expected and it’s a good improvement for about 1 hours work. It would be even quicker the next time since most of the time was spent creating the .config file but I can just use that again next time.

Fedora 10 Feature List

October 1st, 2008

Looking at the Fedora 10 feature list a couple of things caught my eye. A rather significant one, for new users especially, is /sbin sanity whereby /bin and /sbin will be added to the PATH for all users. This will certainly help people when they see commands such as this on a website and cut and paste it into a terminal expecting it to work:

service httpd start

Of course this doesn’t work out of the box in current Fedora releases (it’s /sbin/service). It’s a small change but will make Fedora a bit more users friendly for new users.

Another notable one is Better Start-up that aims to reduce boot times on Fedora. I’m really glad to see that a lot of effort is being put into this area and I know Ubuntu are doing the same.

There were some interesting tests done on Phoronix (see the Fedora and Ubuntu comparisons) comparing boot times over releases for Fedora and Ubuntu. As well as having a much faster boot time it seems that Ubuntu has been better at improving performance over each release, I hope Fedora can rectify this over the next couple of releases.