(UPDATE: Finally added a css once again! - 21/12/09 )
Monday, December 21, 2009
Website updated
(UPDATE: Finally added a css once again! - 21/12/09 )
Wednesday, December 16, 2009
Wikileaks blocked by BSNL - India follows China in censorship
Wikileaks blocked by BSNL - India follows China in censorship
Friday, October 9, 2009
My new Nokia 5800 Xpressmusic
After unpacking I plugged in an Airtel 2G SIM and the 8GB MicroSD that came with the device. Unfortunately the state owned BSNL is the only mobile service provider in India providing 3G connectivity. Though BSNL has excellent 2G coverage all over the country, their 3G coverage is limited only to few cities. Other operators are yet to receive licenses to roll out 3G networks. So for the time being, I'll have to remain contended with 2G services, which means no high speed data and no video call.
The sound quality of the device didn't really disappoint me, however being an Xpressmusic phone, I had expected better quality headphones. The HS-45 headphone that comes with it, is of average quality. I plugged in my friend's Sennheiser headset and the audio quality simply blew me away. So there is nothing inherently wrong with the device's audio output, it is just that the supplied headphones are of mediocre quality.
The inbuilt browser is nice. Adobe Flash is properly supported (in fact excellent flash support, one can watch YouTube videos smoothly over a WLAN connection).
GPS reception is good, I could get my location even indoors. However the initial lock-in time is variable. Sometimes is takes upto 5mins to lock-in to the satellite signals, whereas at other times it takes less than a minute. However with AGPS enabled, startup becomes lightning quick. AGPS allows the device to download the ephemeral data about the GPS satellites from Nokia's AGPS server through the internet, rather than decoding the same from the GPS signals. AGPS works only if a cellular packet data connection is available (for some strange reason it can't use WLAN).
The Nokia Maps application is utter crap, atleast for me. It doesn't provide any detail about any location in eastern India. On the other hand Google Maps just rocks. In the satellite view, I could even figure out the room of the building, where I was. Google Maps also provides turn by turn navigation instruction for traveling from point A to point B on the map. With inbuilt Google Latitude, selected friends can see my instant location on the planet at anytime and I can see them on the map as well.
The inbuilt mail client is simple with minimal features but works quite well. I configured it for periodically monitoring my Gmail Inbox and a few other IMAP Folders and alert me whenever a new mail arrives.
The music player app is good enough for playing wma, mp3, aac, aac+, awb and perhaps someother formats as well. However syncing the music folder with my GNU/Linux computer was a bit troublesome. I'll write about this in a subsequent post. Initially I had to use Nokia Music(part of Ovi Suite) on Windows XP to transfer tracks.
The device comes with a subscription to Nokia music store, which allows downloading of first 100 tracks from the site free of cost. Unfortunately all the songs in Nokia's music store incorporates Microsoft's DRM, making them unplayable in my GNU/Linux laptop. Really annoying! I can't freely play songs that I have legally downloaded.
Anyway as a concluding remark, I must add that the phone is quite hackable(though nothing compared to a Freerunner!), in the sense that Nokia freely provides the SDK/S60 emulator as well as the Symbian C++, Open C++ and Java API for accessing the device features. Nokia has also ported Python to the S60 platform and I could easily get a Python shell running on the device. I could access the shell through a serial console emulated over a bluetooth link. The well documented APIs, helped me to very easily write simple Python scripts to play around with the sensors(accelerometer, rotation, ambient light, proximity and gps positioning) scattered throughout the device. I haven't written any full fledged application, but the potentials are limitless.
My new Nokia 5800 Xpressmusic
Saturday, April 11, 2009
Making inactve USB Hard Disk spin down automatically in Linux.
I have a 400GB Seagate IDE HDD connected to Mars, our hostel's file-server using an USB enclosure. The USB enclosure is a cheap "Made in China" product. Consequently it has some special "features". One such notable "feature" is that the disk is kept spinning by the controller even if there has been no disk I/O for a long time. I have three other USB disks connected to the same machine, a 1TB Seagate FreeAgent Desk External Drive, a 500GB Maxtor Basics External Drive and a 2.5" 60GB Fujitsu SATA Disk inside a Transcend USB enclosure. All of these spin down themselves if there has been no I/O for sometime. Keeping the hard disk spinning unnecessarily for ever, not only wastes power but also overheats the drive, thereby reducing its life.
I tried noflushd, which is supposed to force idle hard disks to spin down, but found it to be of no help. USB enclosure generally work by performing an SCSI emulation over USB. sdparm is an utility which can be used to send simple SCSI commands. A peep into its manpage revealed that the disk could be ordered to spin down by sudo sdparm -C stop /dev/sdb1 where sdb1 is the required disk (the disk has a single partition, "sdparm -C stop /dev/sdb1" and "sdparm -C stop /dev/sdb" did the same thing here, however if there are multiple partitions, it is more meaningful to specify "/dev/sdb" rather than "/dev/sdb1", since it is the disk that stops spinning).
However I need to do this automatically whenever the disk is idle. First, it is necessary to check whether the disk is active or idle. Info about disk I/O is available from /proc/diskstats.
cat /proc/diskstats | grep sdb1
shows info about sdb1, the output is something line this:
8 17 sdb1 210583 56943 24739612 2328860 11777 24804 292648 69260 0 1209770 2397450
It has several fields after "sdb1", denoting the following:
Field 1 -- No. of reads issued
Field 2 -- No. of reads merged
Field 3 -- No. of sectors read
Field 4 -- No. of milliseconds spent reading
Field 5 -- No. of writes completed
Field 6 -- No. of writes merged
Field 7 -- No. of sectors written
Field 8 -- No. of milliseconds spent writing
Field 9 -- No. of I/Os currently in progress
Field 10 -- No. of milliseconds spent doing I/Os
Field 11 -- weighted No. of milliseconds spent doing I/Os
Field 9 is of importance here, a nonzero value indicates disk activity. Any particular field can be dug out easily using grep and AWK (mawk interpreter is the obvious choice here).
cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }' does the trick.mawk '{ print i }' prints the ith field.The variable NF is equal to the number of fields. We are interested in the field 3rd from the end. Hence $(NF-2).
Now this is probabilistic, if there is no I/O in that particular instant
cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'will yield
0. To ensure that the disk is really inactive, the check has to be carried out quite a few times.There is another pitfall, there are 4 USB disks connected to the machine. Which one would be named sdb is not fixed. At every reboot this may change. On the other hand uuid of a disk never changes (unless the partition table is modified). So the name of the disk has to determined from its uuid. grep, AWK, and sed comes to our rescue once again.
DISKNAME=`ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__`
What this essentially does is explained below.
"ls -l /dev/disk/by-uuid/" gives the following output
sambit@mars:~$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 0db6e806-8d4b-4968-8ccc-c00af59bb065 -> ../../sdc1
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4294e561-df28-4ddd-a689-0aba31d4d663 -> ../../sda2
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4cb989c6-87b7-4179-bb4d-81b2b0193ab2 -> ../../sdd1
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 4cf2093e-f08c-4127-ae75-fff11edd81ae -> ../../sdd2
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 87ba9975-056d-4635-85e4-53f1c76d57fb -> ../../sda3
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 a74b47fb-a33c-4a5a-ad62-0bc831f6ffda -> ../../sdd3
lrwxrwxrwx 1 root root 10 2009-04-07 14:20 af0c007b-a15c-4661-84eb-7dc689dec861 -> ../../sda1
lrwxrwxrwx 1 root root 10 2009-04-10 22:09 c5df6a02-b7a6-4f39-ad26-7eb915b76709 -> ../../sdb1
narrows it to:
ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709"
lrwxrwxrwx 1 root root 10 2009-04-10 22:09 c5df6a02-b7a6-4f39-ad26-7eb915b76709 -> ../../sdb1
prints the last field:
ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }'
../../sdb1
Finally sed puts some finishing touches, by replacing "../../" in "../../sdb1" with "".
ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__
sdb1
So putting everything together, the script at-last looks something like this:
#################################################################################################################################
#!/bin/bash
DISKNAME=`ls -l /dev/disk/by-uuid/ | grep "c5df6a02-b7a6-4f39-ad26-7eb915b76709" | mawk '{ print $(NF) }' | sed s_\.\.\/\.\.\/__`
let a=0
#check 100 times with 0.1s gaps,
#and go on adding
for i in `seq 0 100`
do
let a=`cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'`+a
sleep 0.1s
done
echo $a
if [ $a == 0 ]
then
echo "No Activity"
sdparm -C stop /dev/$DISKNAME
else
echo "Disk Active"
fi
exit 0
#################################################################################################################################
I added this to crontab and made it run hourly. The hard disk can rest in peace for sometime in between heavy work now.
Making inactve USB Hard Disk spin down automatically in Linux.
Saturday, February 7, 2009
IISERK Haringhata Campus
The location didn't quite disappoint me, though many "mall hoppers" and a few "privileged ones" (their homes are in Kolkata) who earlier could slip into the comfort of their homes every weekend easily were unhappy, it has become a bit more difficult for them to do so now. However one thing that I really miss is the 2Mbits connection. There is no broadband connection yet in the hostel, and currently we are trying hard to manage using a 17KBytes Wireless Dialup connection over CDMA. There is little chance of getting any high speed connection in this remote location. The administrative building does have a decent leased line, but it is at a few minutes of walking distance from the hostel making it difficult to land up there late at night.
Apart from this annoyance, life is quite peaceful here. Being located far from the city, the night sky remains glare-free, which provoked a few of my friends to plan to buy a telescope for star-gazing. I am too looking forward for this.
IISERK Haringhata Campus
Thursday, January 8, 2009
Adventures with IPv6
The job is partly done.
The nameserver, webserver, network router and firewall are working quite well.
The website can be accessed here http://oak.ipv6.iiserk.net(Provided you have IPv6 connectivity). It runs on a rickety PIII running Ubuntu 8.04.1 and connected to my friend's home ADSL connection. Power failure are quite a common affair in our region (in almost the whole country, to be honest!) and there is no power backup for the server, so if it appears to be down, kindly check back sometime later.
The nameserver ns1.ipv6.iiserk.net manages the DNS records for the subdomain ipv6.iiserk.net.
I hope to get the mailserver up and running quite soon.
I'll also come up with a detailed documentation on how I got the things running, sometime in the near future.
Anyway for this half-crappy IPv6 implementation, I got this from Hurrican Electric Internet Services:
(It is a certificate, but removed the JScript, as it was causing the page to load slowly)
It started with "newbie" level, and is improving!
More on IPv6 soon... may be in a day or two.
Adventures with IPv6
Sunday, December 21, 2008
Linux Hard Disk Issue - Excessive Load_Cycle_Count
Prologue: My 2 year old laptop's harddisk had died a few weeks ago, and I replaced it with a Seagate Momentus 5400.3 160GB SATA Drive. I have been running only Linux for a long time on my laptop. (Running Ubuntu Intrepid at present)
While trying to ascertain the cause of this premature death, I came to notice the abnormally high Load_Cycle_Count. This can be checked using smartmontools by issuing the command
sudo smartctl -n standby -a /dev/sdawhere /dev/sda has to be replaced with the appropriate disk name. The option -n ensures that if the disk is already in standby, smartctl doesn't wake it up. A little bit of Googling returned quite a lot of stuffs about this issue. Laptop Harddisks, in order to improve power efficiency while on battery, have quite aggressive power management features by default. Now this is not really bad. When the disk is not accessed for sometime it spins down itself. So far so good, the disk stops spinning unnecessarily thereby cutting down power consumption. However no sooner than the disk stops spinning, something causes it to spin up again. This not only defeats the whole purpose of spindown, but also causes unnecessary wear and tear of the disk components. Most modern HDDs have a mechanism which parks the head (loads it up a ramp) when the disk spins down. The head is unloaded back over the platter, once the disk spins up again. However each load and unload cycle causes wear of the loading and unloading mechanism. Seagate HDDs (most others as well) have specifications of maximum of 60,000 load unload cycles. This is quite high. But what I found in my case was, the Load_Cycle_Count was increasing at the rate of about 5-6 per min. That meant the head was parking and unparking every 10sec on avarage. This was quite alarming.
To stop such insane behavior, I set the Advanced Power Management to 254 using hdparm. A value of 254 meant least aggressive power management. By default Ubuntu sets it at 128. This did stop the Load_Cycle_Count from increasing increasing insanely. But the disk now stopped spinning down, and its temperature was shooting up. Within a hour it went up above 60degC (room temp was around 20degC). Now that is even more alarming than the increasing load cycle count. The rated maximum operating temperature for my drive is 60degC. Operating at high temperature severely shortens the life of the disk. At a power management value of 180, the temperature settled at around 55degC. This was better, but not quite good, the disk was 35degC above ambient temperature. During peak summer, the ambient temperature at Kolkata hovers around 40degC. So my disk will get fried up in the summer if I use my laptop in a room without airconditioning.
So preventing the disk from spinning down is not a solution. It has to be ensured that once the disk spins down, it stays like that as long as possible, without spinning up.
I needed to find out who was accessing the disk so frequently. iotop is a nice utility for this. wpa-supplicant was at the top of the list. I am using a wireless connection, and wpa-supplicant frequently logs something. Next was gconf-d, followed by gnome-do and console-kit-daemon. As soon as the disk spins down, one of this will try to do a read/write causing the disk to spin up again. On top of that, every time the disk is accessed, kjournald will write the filesystem journals, update the atime, ctime and mtime of file inodes. All these together keep the disk always busy and wakes it up as soon as it tries to catch a nap.
However there is a utility called laptop-mode-tools which performs some tweaks and tries to keep the hard disk in standby mode as long as possible.
To enable it, first install laptop-mode-tools.
sudo apt-get install laptop-mode-toolsThen it has to be enabled in /etc/default/acpi-support by changing the line
ENABLE_LAPTOP_MODE=falseto
ENABLE_LAPTOP_MODE=trueI changed the configuration file a bit, so as to optimize things as far as possible.
The configuration is there at /etc/laptop-mode/laptop-mode.conf
###### Config file for laptop-mode-tools ## Verbose output on VERBOSE_OUTPUT=1 ## Laptop mode enabled always ENABLE_LAPTOP_MODE_ON_BATTERY=1 ENABLE_LAPTOP_MODE_ON_AC=1 ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=1 # When to enable data loss sensitive features # ------------------------------------------- # # When data loss sensitive features are disabled, laptop mode tools acts as if # laptop mode were disabled, for those features only. # # Data loss sensitive features include: # - laptop_mode (i.e., delayed writes) # - hard drive write cache # # All of the options that follow can be set to 0 in order to prevent laptop # mode tools from using them to stop data loss sensitive features. Use this # when you have a battery that reports the wrong information, that confuses # laptop mode tools. # # Disabling data loss sensitive features is ACPI-ONLY. # Disable all data loss sensitive features when the battery level (in % of the # battery capacity) reaches this value. # MINIMUM_BATTERY_CHARGE_PERCENT=3 # Disable data loss sensitive features when the battery reports its state # as "critical". # DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=1 # The drives that laptop mode controls. # Separate them by a space, e.g. HD="/dev/hda /dev/hdb". The default is a # wildcard, which will get you all your IDE and SCSI/SATA drives. # HD="/dev/[hs]d[abcdefgh]" # The partitions (or mount points) that laptop mode controls. # Separate the values by spaces. Use "auto" to indicate all partitions on drives # listed in HD. You can add things to "auto", e.g. "auto /dev/hdc3". You can # also specify mount points, e.g. "/mnt/data". # PARTITIONS="auto /dev/mapper/*" ASSUME_SCSI_IS_SATA=1 # Maximum time, in seconds, of work that you are prepared to lose when your # system crashes or power runs out. This is the maximum time that Laptop Mode # will keep unsaved data waiting in memory before spinning up your hard drive. # LM_BATT_MAX_LOST_WORK_SECONDS=900 LM_AC_MAX_LOST_WORK_SECONDS=600 # # Should laptop mode tools control readahead? # CONTROL_READAHEAD=1 # 10MB readahead in laptop mode LM_READAHEAD=10240 NOLM_READAHEAD=128 # Disks will be mounted with noatime in laptop mode, atime updates to file inodes will be # stopped. CONTROL_NOATIME=1 # Don't use relatime instead of noatime USE_RELATIME=0 # set hdd timeout CONTROL_HD_IDLE_TIMEOUT=1 LM_AC_HD_IDLE_TIMEOUT_SECONDS=60 LM_BATT_HD_IDLE_TIMEOUT_SECONDS=30 NOLM_HD_IDLE_TIMEOUT_SECONDS=7200 # set HDD power management CONTROL_HD_POWERMGMT=1 BATT_HD_POWERMGMT=1 LM_AC_HD_POWERMGMT=127 NOLM_AC_HD_POWERMGMT=254 # enable write cache CONTROL_HD_WRITECACHE=1 NOLM_AC_HD_WRITECACHE=1 NOLM_BATT_HD_WRITECACHE=0 LM_HD_WRITECACHE=1 CONTROL_MOUNT_OPTIONS=1 # # Dirty synchronous ratio. At this percentage of dirty pages the process # which calls write() does its own writeback. # At 80percent of dirty pages disk write is performed. This holds up things in memory and # prevents frequent disk writes LM_DIRTY_RATIO=80 NOLM_DIRTY_RATIO=40 # # Allowed dirty background ratio, in percent. Once DIRTY_RATIO has been # exceeded, the kernel will wake pdflush which will then reduce the amount # of dirty memory to dirty_background_ratio. # Once writeout has commenced write as much as possible to disk, without keeping back anything. # So this has been set to 1 percent LM_DIRTY_BACKGROUND_RATIO=1 NOLM_DIRTY_BACKGROUND_RATIO=10 # # kernel default settings -- don't touch these unless you know what you're # doing. # DEF_UPDATE=5 DEF_XFS_AGE_BUFFER=15 DEF_XFS_SYNC_INTERVAL=30 DEF_XFS_BUFD_INTERVAL=1 DEF_MAX_AGE=30 # # This must be adjusted manually to the value of HZ in the running kernel # on 2.4, until the XFS people change their 2.4 external interfaces to work in # centisecs. This can be automated, but it's a work in progress that still # needs some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for # external interfaces, and that is currently always set to 100. So you don't # need to change this on 2.6. # XFS_HZ=100 # # Seconds laptop mode has to to wait after the disk goes idle before doing # a sync. # LM_SECONDS_BEFORE_SYNC=2
After enabling laptop-mode, the hdd is being able to sleep peacefully for quite sometime in between spinups. Also the operating temperature is rarely exceeding 50degC now. The load cycle count is still increasing but at a much slower rate. Hopefully this HDD is going to last longer than the previous one.
Linux Hard Disk Issue - Excessive Load_Cycle_Count


