Monday, September 10, 2007

Opensolaris on VMWare on WinXP

I was thinking about installing OpenSolaris and or Ubuntu on my laptop (Toshiba m200) which does not have a CD/DVD drive. It seemed non-trivial to boot any installer in this setup. Also I did not know how long my interest would last with new OSs, and did not want to have zillions of partitions lying around.
I had heard about virtualization using VMWare but always thought you had to pay for it. Recently found out that you actually don't. Considered 3 VMWare products
  1. VMWare Player: Can play client OS Snapshots, but cannot create one. (Free)
  2. VMWare Workstation: 30 days free trial, you could create a client snapshot with this and use Player.
  3. VMWare Server: Less user friendly (they say) than Player , but can support multiple client OSs. (Free !!!!)
Went with 3. Decided on installing OpenSolaris (Solaris Express, Developer's Edition) first.

My machine specs 1.5GHz Centrino, 1GB RAM, 40GB disk (of which I had used up 20GB for XP).

Googled and came across "Dave's Blog" on the subject, and followed it (along with the pointer to his "older post"). It went without too many problems. A few things I learnt along the way

Terms: Host OS: WinXP. Client OS=Guest OS =VM = Virtual Machine: OpenSolaris
  • OpenSolaris with Sun Studio needs 768MB RAM. Have at least during install. If you have 1GB like me, you are going to face some slowdown switching between XP and the client OS. But once you have it installed you can lower the memory usage. 512MB works good for me.
  • Setting the login resolution was painful, it seemed to set it too big. You have to go into /etc/X11/xorg.conf and comment out any resoluion large than your max resolution.
  • Had some problems with enabling audio in OpenSolaris. It comes up Muted and cannot be changed. Got it working accidentally when I updated /etc/user_attr for dtrace and logged out and in. Maybe logging out does fix it.
  • Get a large disk allocated for the client. It seems hard to increase it later, though you can add "virtual disks".
  • Unless you have a lot of spare disk, avoid allocating all of this disk up front.
  • Better to allocate in disk in 2GB chunks (an option when creating the Virtual Machine). Lets you backup to DVD easily as well as copy to FAT32 external drives and move between PCs and Apple Mac s if you do desire.
  • Create swap=2X the RAM you allocate.
  • Once you install most things on the VM, take a snapshot in case you screw up the virtual machine later, you can revert back.
Pros:
  • Can change your mind and delete the VM at any time.
  • Can snapshot the machine state (only 1 though).
  • Can copy and clone the VM at any time (better to shutdown the VM first).
  • Can have a variety of OSs on one machine, can try out different OSs and decide for oneself which one you like.
  • No headache of obscure drivers for the client OS (can be a problem for OpenSolaris).
  • Can install the guest OS (VM) on an external drive and thus save disk space.
  • Really useful if you do not have a bootable CD/DVD drive on you laptop like me.
Cons:
  • Slow, espcially when handling OS related apps. YouTube videos not watchable on a browser in the client OS. For work, development etc the speed is enough though.
  • Transferring files painful accross host and guest OSs, or between guest OSs. You have to ftp. You could probably share a virtual disk and use it to copy stuff, but it probably has to FAT32 (with its limitations). I have not tried that yet.
  • Bringing up and Suspending a guest OS is slow. It helps if you have RAM > all the guest OSs you are running.
After Opensolaris worked, installed Ubuntu on a USB external drive as well.


Monday, June 4, 2007

OS X Tiger and bad sectors on the hard drive

Last week, my Mac suddenly started beachballing and got on progressively slower and slower. I could not reboot from the disk, and was worried that my disk had crashed and I would need to invest in putty knives etc to open and replace the hard drive. Here is my course of action to get my Mac working again.

  1. So, the disk is not very well. Booted into single user and try "fsck -fy /dev/disk0s3" (/dev/disk0s3 was my drive, other's may have a different ID, do a df to check). Did not help.
  2. Read somewhere about "fsck_hfs -r /dev/disk0s3" which had magically repaired catalogs etc. Could not repair it and gave me an "Invalid sibling link" and other errors.
  3. Booted off the install disk (press C while booting) and tried the disk repair utility. Gave similar messages to 2. (probably the same tool, different interfaces). Bottom line, said could not repair disk.
  4. At this point I had given up keeping the data on the disk intact, and went for an erase and install from the install disk. Took a while. One problem was that a repair unmounted the drive and had to erase it to get it mounted again. Not a big deal.
  5. Booted up fine, and I thought I had solved my problem. Started restoring files from backup disk, and suddenly started getting beachballs and system slowdown. Checked /var/log/system.log and found the dreaded disk0s3: I/O error. Booted off the install disk again and ran disk repair and found the same "Invalid sibling link", disk cannot be repaired messages from disk utility.
  6. Tried 5, and number of times and convinced myself that until I started moving lots of data on to the disk, after an erase and install, everything worked OK. This was strange as a crashed disk should not let me get that far. But possibly the failure on the disk was intermittent and sooner or later I would hit it. But it was strange that I could download and install my needed utilities and run after a clean install and it would work fine, until huge disk transfers.
  7. Posted my problem at a number of websites and had one good hint regarding something which had come to my mind, but I had not followed it through. Do a zero out data followed by erase and install. The person who advised this also told to zero out the free space on the drive, ie zero out everything. (Zeroing once is enough).
  8. THE REASON: Apparently OS X (Tiger) does not deal with bad sectors on the disk very well, through its disk repair utilities. So if you have a few bad sectors on the drive you may never be able to tell OS X not to use them. Consequently, it will work until the OS uses this bad sector in a critical way (like in a catalog, or file table) and it goes from bad to worse from there. Zeroing out the hard drive seems to mark these bad sectors so the OS does not use them anymore.
  9. This did seem to conform to the symptoms I saw with the clean install working, and then failing later.
  10. Tried it out, and the Mac has been up for the last 4 days working fine.
So I have postponed buying the putty knives for now, although bad sectors on the disk is not good news, and I will probably have to invest in a new disk at some future time. Will backup my stuff more regularly for now.

The zero out, erase and install did not seem to be very well known as a solution to disk crashing problems. People usually invest in disk repairing tools after the first few steps fail.

Saturday, February 17, 2007

Auto WOL on DD-WRT on Linksys WRT54GL

I am running a webserver on my desktop, to host a website from home. One of the problems I faced, is that I have to now leave my desktop "on" all the time. Between the higher electricity bill and depreciation on the desktop, I wondered if I was saving much hosting from home.

So when I bought the Linksys WRT54GL and installed DD-WRT on it recently, I thought I would try to set it up to wake up the computer on a Port 80 (http) access if it was in "sleep" mode.

For DD-WRT and Linksys routers, see http://www.dd-wrt.com/

DD-WRT allows you to write shell scripts on the router and I thought I would use this facility and use the builtin commands. Ideally I would want a trigger on a port 80 access on the router, but this might be a little inefficient since it would happen on every port 80 access and I could not find a way to trigger a script in DD-WRT.

So I thought instead that I would parse the syslog to detect port 80 activity. I could then control things like how often I check for activity etc. Here is the script I came up with

#!/bin/sh

INTERVAL=5
NUMP=3
OLD=""
WOL=/usr/sbin/wol
TARGET=192.168.1.100
MAC=00:00:00:00:00:00
logfile="/tmp/www/wol.log"

while sleep $INTERVAL
do
NEW=`cat /var/log/messages | grep ACCEPT | grep "DST=$TARGET" | grep "DPT=80" | tail -1 | awk '{print $3}'`
SRC=`cat /var/log/messages | grep ACCEPT | grep "DST=$TARGET" | grep "DPT=80" | tail -1 | awk '{print $10}' | sed -e "s/SRC=//g"`
LINE=`cat /var/log/messages | grep ACCEPT | grep "DST=$TARGET" | grep "DPT=80" | tail -1 `
if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
echo "$SRC $LINE" >> $logfile
RET=`ping -c $NUMP $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`
if [ "$RET" -ne "$NUMP" ]; then
echo "$SRC causes WOL at" `date` >> $logfile
$WOL -i 192.168.1.255 -p 7 $MAC >> $logfile
sleep 5
fi
OLD=$NEW
fi
done


TARGET is the LAN IP of your webserving machine, and MAC is its MAC Address. INTERVAL is how often you want to check for a transaction. To get the syslog in /var/log/messages, enable syslogd in DD-WRT with an empty field for IP address. I also had to set the log level to High and at least log all ACCEPT s in the log settings.

I create a logfile in /tmp/www to debug the script, the logfile references can be deleted if you want to make the script smaller to fit in nvram. The script does not send a WOL if the webserving machine is not in "sleep" mode. I use the built in WOL command on DD-WRT.

For more on DD-WRT scripts check http://www.dd-wrt.com/wiki/index.php/Index:Scripting

There is a lag now, when the computer is asleep to access a page on the computer. However I find that in most cases, the browser timeout is long enough to wake the computer up and deliver the webpage.

Comments and improvement suggestions are welcome.