Thursday, December 28, 2006

A simple way 2 fix DMA problem of HDD in windows XP

Windows XP has a somewhat bad (IMHO) feature
that sets off the DMA of hard drives and CD/DVD drives when it gets CRC error in
reading the filesystem. This frequently happens when you are having subsequent power
cuts or if you have a bad sectors in your drive. And thus PC crawls when we want
to access data from that drive, as OS then retrieves data in PIO mode.



This problem has been bugging me for some time. So hacked my way into "regedit"
and finally made this script. This script deletes the registry entry that Windows
uses to calculate what addressing mode to use when accessing the drives. So upon
running the script, just rebooting PC will
force windows re-detect the drive resulting in restoration of UDMA mode 5 for the
hard drive.



Here is the code


####################

REG DELETE HKLM\SYSTEM\CurrentControlSet\Control\Class\
{4D36E96A-E325-11CE-BFC1-08002BE10318}\0001
/v "MasterIdDataCheckSum" /f



REG DELETE HKLM\SYSTEM\CurrentControlSet\Control\Class\
{4D36E96A-E325-11CE-BFC1-08002BE10318}\0001
/v "SlaveIdDataCheckSum" /f



REG DELETE HKLM\SYSTEM\CurrentControlSet\Control\Class\
{4D36E96A-E325-11CE-BFC1-08002BE10318}\0002
/v "MasterIdDataCheckSum" /f



REG DELETE HKLM\SYSTEM\CurrentControlSet\Control\Class\
{4D36E96A-E325-11CE-BFC1-08002BE10318}\0002
/v "SlaveIdDataCheckSum" /f

####################



Put this code fragment inside a text file and rename it to
"dma_restore.bat" or something like
it. Make sure you change the extension to ".bat".
Upon running the file, you may see some errors like "Error: the
system was unable to find the specific registry key or value". Do not worry
about it. Just
reboot
and your PC should be
fine in the next run.


Saturday, October 21, 2006

Take care of your hard disks with hdparm

The main problem that we all face with our hard disk is bad sector and subsequent data loss for that. Everybody know what is the blow of such data loss, specially if you are using your PC as a web server or database server.

There are various reasons for which your hard disk can get bad sectors. The most prominent of them is sudden power failure. As the disk constantly keeps spinning at 5400-10000 rpm depending on hdd model, if the disk is being accessed (data being written and read) when the power failure occurs, the head may write down abnormal data and bad sector can occur from that.

Now a days, most OS by default takes advantage of a feature called write-caching incorporated in modern hard disk drives to boost write performance. While increasing write throughput, the feature indirectly increases the risk of data corruption and bad sectors as your drive keeps constantly writing to disk.

So its a very good idea to disable write-caching in your hard drive if your disk has sensitive data. To accomplish that we are going to use a very handy tool in UNIX, hdparm.

'hdparm' is a tool designed to manage every setting of your hard drive. With this tool, you can tune your hard drive to your style. With some settings activated your hard drive will give you highest performance (with the risk of data loss when power failure occurs) and with others you can ensure maximum safety of your data at the expense of performance.

Now if u want maximum safety for your data, just run the following in root shell (be warned that you won't get maximum performance from your drive):

#hdparm -W 0 /dev/hda
[Note: replace hda with your drive identifier]

This effectively turns write-cache off.

If you want to automatically deactivate write-cache off on your hard drive, then add these lines in /etc/hdparm.conf:

/dev/hda {
mult_sect_io = 16
write_cache = off
dma = on
defect_mana = on
}

On the other hand if you want to gain performance by pushing your hard drive to the edge (but this may make your hard drive more prone to data corruption in case of power failure):

#hdparm -d 1 -A 1 -m 16 -u 1 -a 64 -X udma5 /dev/hda

or add these lines in /etc/hdparm.conf:

/dev/hda {
lookahead = on
write_cache = on
read_ahead_sect = 64
dma = on
mult_sect_io = 16
interrupt_unmask = on
transfer_mode = 69
}

Your hard drive should be running in turbo mode by now (but you won't notice any difference if these settings were enabled by default).

--
Time heals every wound, but time itself is a wound that never heals.

Tuesday, September 12, 2006

Recover more space with localepurge

You read my last post about deborphan and debfoster and now wondering about other ways to recover more space, right?

Well my friends, you are in the right place.

After discovering the amazing capabilities of those two tools, I kept looking for something more and got localepurge.

Ever got annoyed to see those localized man pages we usually find in /use/share/doc that you never read? It's time to get rid of those.

#apt-get install localepurge

This will install localepurge in your system and prompt you to select the locale (preferably en_us and/or your own locale) for the man pages you want to keep in your system. After that, localepurge will automatically search the whole system for localized man pages and delete those.

In my case I was able to recover and huge 332 MB in the first run (Your mileage may vary). Sweet, huh!

Another sweet thing is, localepurge will automatically remove localized man pages when you install new packages in your system.

swapon

Ever been in a situation where you need a bigger swap file than what you already have and and don't know what to do?

Suppose, you have recently installed a program in your unix box that needs at least 1GB of swap space but you only allocated 256MB  for your swap partition when you installed your unix distro, or you even forgot to allocate a swap partition during the installation process because you were in a hurry and now your favourite programme slows down frequently. Thinking about reinstallation?

Well, think again!

There is a handy tool in unix called swapon that can solve your problem in a few seconds.

Here is how I added a 512MB extra swap space in my debian system:

  • First I calculated the file size in KB. 512 * 1024 = 524288
  • Then I ran these in root shell (This creates the swap file):
#dd if=/dev/zero of=swapfile bs=1024 count=524288
#mkswap swapfile -L linux_swap
  • Then I instructed my debian to use that swap file:
#swapon swapfile

Walla! My system suddenly appears to have 512MB of extra swap space!

Now, one single step is missing. You don't wanna write swapon in shell every time your system boots, do you?
Just add #swapon swapfile to your system's startup scripts.

And if don't wanna use that swap file for some reason, #swapoff swapfile and delete that file (and don't forget to remove that startup script if you have added that)

Friday, September 08, 2006

deborphan and debfoster

Today I came across two cool utilities of Debian: deborphan and debfoster.

Deborphan finds 'orphan'ed packages in your system. It detects those packages that aren't being depended on by any other packages. So, if one doesn't want them, they are safe to remove.

#deborphan

This showed me those redundanat packages; I could've removed them one by one but I chose to remove them all at once by this command:

#deborphan | xargs apt-get -y remove --purge

[Note: I find it's always a good idea to keep a backup, just in case for if things get messed up. So I ran "#deborphan > change_list" to keep the name of the packages into change_list file, so that I reinstall them if I needed so.]

Debfoster, the other package does similar thing but in reverse manner, it checks those packages that are holding other packages installed as it depends on them. It then prompts the user whether he wants to keep or deinstall those packages with dependencies one by one.

#debfoster
kdegames is keeping the following 32 packages installed:
kasteroids katomic kbackgammon kbattleship kblackbox kbounce
kdegames-card-data kenolaba kfouleggs kgoldrunner kjumpingcube klickety
klines kmahjongg kmines knetwalk kolf konquest kpat kpoker kreversi ksame
kshisen ksirtet ksmiletris ksnake ksokoban kspaceduel ktron ktuberling
kwin4 lskat
Keep kdegames? [Ynpsiuqx?], [H]elp:

I chose N to remove those.

Using these two commands I have recovered a lot of disk space that was otherwise reserved by the programmes I never use.

Thursday, September 07, 2006

allbn2unicode

I have joined up with my friend salahuddin and lavluda to a project that is called 'allbn2unicode'.

This project has following objectives:
  1. Create a C based multiplatform converter that will convert from bijoy, alpona, etc encoded files to unicode format.
  2. Upon completion of the first objective, create a GTK based GUI for unix platform and MFC based GUI for windows platform.
  3. Upon completion of the second objective, extend support for doc, odt, rtf, etc file formats.
So far we have implemented the following features:
  1. a command line version that inputs a file and outputs in another
  2. a simple plug in system that enables the possibility to convert between any formats
We are working hard to make it a complete software package.

Additional Notes:
  • The project is codenamed 'Rebirth"
  • Our team members have contribited in the following parts:
    1. Salahuddin created the base structure of the programme, the I/O system, the base algorithm of wide character I/O.
    2. Lavluda created the plugin system, added structured data manupulation and various refinements.
    3. Zaher (me) revised the basic alogorith, introduced the dynamic memory allocation system, reworked the plugin system, improved the searching algorithm, and various speed impvovements.

Installed ATI fglrx driver succesfully in Debian 'etch'

Everybody knows that installing ati's closed source driver fglrx in
unix is a bit hairy. I know several people who have smoked their box
in the process (that also includes me!). (debian unstable now includes
the fglrx driver, but i find it better 2 install the latest driver from
the card manufaturer)

Well after a lot of fiddling (or should i say a few crashes!) I was
able to install it withput any problem.

Here is the procedure I followed:

1, downloaded the latest version from ati's website. (8.27.10-1)

2. #sh /tmp/ati-driver-installer-8.27.10-x86.run --buildpkg Debian/etch

3. #dpkg -i fglrx-driver_8.27.10-1_i386.deb
fglrx-control_8.27.10-1_i386.deb fglrx-kernel-src_8.27.10-1_i386.deb

4. #apt-get install module-assistant

5. #module-assistant prepare

6. #module-assistant update

7. #module-assistant build fglrx

8. #module-assistant install fglrx

9. #depmod -a

10. #aticonfig --initial

11. #aticonfig --overlay-type=Xv

12. #mkdir -p /usr/X11R6/lib/modules/dri

13. #ln -s /usr/lib/dri/fglrx_dri.so /usr/X11R6/lib/modules/dri

the driver installation was complete by now.
I checked if the driver installation was successfull by doing a reboot
and #fglrxinfo in the terminal.
I also ran #fgl_glxgears; i saw three gears spinning.

Working in Blender

I have started working in blender, a very poweful tool for creating animations.

Burnitup

This is a perl script i created as a test to write data and audio (creates audio cds) files 2 cd writer. This is a simple script that uses cdrecord's engine.

The main attraction of the script is that it supports 'digital mastering', a feature long been used by audio cd manufactures. This is really a hidden feature of cdrecord, but many people does not know about it. In order to use the feature, your burner must support it, of course. To my knowledge, only Yamaha's writers support this feature currnetly; but i believe most other manufactures will incorporate this feature into their burners soon.

I have created two versions of the script: burnitup_norm and burnitup_ultra. the norm version first creates an image in the current folder and then burns the image thus proving you an opportunity to reuse the image (.iso) file. On the other hand the ultra version writes to cd from source folder, does not created any image or tempory file. Use this one if you dont have enough extra space in your hard drives.

The source code of the burner is as follows:

[Note: 1. You have 2 call the script with '-burn' switch to write 2 the cd, otherwise it wont write anything, just do a simulation. This is a safety feature.
2. The ultra version has some minor gliches, (it needs you to manually input track size in sao mode) i'll automate that part when i have free time.
3. Currently it can write only one track per session.
]

source code of burnitup_norm.pl:



#code starts here
#!/usr/bin/perl

#use to get options
use Getopt::Long;

#specify your default options here

$device_default = "/dev/ide/host0/bus1/target0/lun0/cd"; #my cd writer's id
$mode_default = "tao"; #default writing mode
$driveropts_default = "burnfree"; #default driver options
$type_dafault = "data"; #default cd type


#end of default settings

#specify the options
GetOptions( "help" => \$help,
"master" => \$master,
"mode=s" => \$mode,
"speed=i" => \$speed,
"type=s" => \$type,
"source=s" => \$source,
"multi" => \$multi,
"tracksize=s" => \$tracksize,
"burn" => \$burn,
"device=s" => \$device);

if ($help){
print "Welcome to burnig world with Burn It Up\n";
print "\n";
print "You should specify these options:\n";
print "--help :shows this help\n";
print "--device :specify the cd-recorder eg /dev/hdc\n";
print "--mode :this can be tao(track at once, sao(disk\n";
print " at once) or raw96r\n";
print " Note: choose sao for digital mastering\n";
print "--master :use digital mastering\n";
print " Note: 700mb cd becomes 595mb\n";
print "--speed :set writing speed 1-50\n";
print "--type :this is either data or audio\n";
print "--source :the path of the source dir\n";
print "--multi :choose if you want to create a multisession disk\n";
print "--tracksize :needed for sao(disk at once) mode.\n";
print "--burn :this will really burn the cd otherwise, it writes\n";
print " in simulation(dummy) mode.\n";
exit;
}
if($device eq ""){
$device = $device_default;
}

if ($source eq ""){
print "Burn It Up: No sourec dir specied. Please enter the source dir path\n";
exit;
}

if ($speed == 0){
print "Burn It Up: No writing speed specified. Please specify the wrinting speed 1-48x\n";
exit;
}

if ($mode eq ""){
$mode = $mode_default;
print "Burn It Up: No writing mode specified. Using primarily tao mode.\n";
}
if ($master){
$driveropts = "burnfree,audiomaster";
$mode = "sao";
print "Burn It Up: Digital mastering enabled. Switching to sao mode.\n";
}
else{
$driveropts = $driveropts_default;
}

if ($mode eq "sao"){
print "Burn it up: You must specify the track size using the --tracksize paramater.\n";
print " You can retrive the tracksize value from below:\n";
print " write as this --tracksize XXXXs\n";
$status = system("mkisofs -R -J -q -print-size $source");
if($tracksize){
$tsize = "tsize=$tracksize";
}
else{
$tsize = "";
#exit;
}
}

if ($type eq ""){
print "Burn It Up: No cd type specified. Writing data cd.\n";
$type = $type_dafault;
}

if ($multi){
$opt1 = "-multi";
}
else{
$opt1 = "";
}

if ($burn){
$dummy = "";
}
else{
$dummy = "-dummy";
}

$status = system("rm -f temp.iso && mkisofs -r -R -J -o temp.iso $source && cdrecord -v -$mode $dummy $opt1 speed=$speed driveropts=$driveropts dev=$device -$type $tsize temp.iso && rm -f temp.iso");
die "Writing CD failed. cdrecord exited with Status Code $?" unless $status == 0;
#code ends here



source code of burnitup_ultra.pl:




#code starts here:
#!/usr/bin/perl

#use to get options
use Getopt::Long;

#specify your default options here

$device_default = "/dev/ide/host0/bus1/target0/lun0/cd"; #my cd writer's id
$mode_default = "tao"; #default writing mode
$driveropts_default = "burnfree"; #default driver options
$type_dafault = "data"; #default cd type


#end of default settings

#specify the options
GetOptions( "help" => \$help,
"master" => \$master,
"mode=s" => \$mode,
"speed=i" => \$speed,
"type=s" => \$type,
"source=s" => \$source,
"multi" => \$multi,
"tracksize=s" => \$tracksize,
"burn" => \$burn,
"device=s" => \$device);

if ($help){
print "Welcome to burnig world with Burn It Up\n";
print "\n";
print "You should specify these options:\n";
print "--help :shows this help\n";
print "--device :specify the cd-recorder eg /dev/hdc\n";
print "--mode :this can be tao(track at once, sao(disk\n";
print " at once) or raw96r\n";
print " Note: choose sao for digital mastering\n";
print "--master :use digital mastering\n";
print " Note: 700mb cd becomes 595mb\n";
print "--speed :set writing speed 1-50\n";
print "--type :this is either data or audio\n";
print "--source :the path of the source dir\n";
print "--multi :choose if you want to create a multisession disk\n";
print "--tracksize :needed for sao(disk at once) mode.\n";
print "--burn :this will really burn the cd otherwise, it writes\n";
print " in simulation(dummy) mode.\n";
exit;
}

if($device eq ""){
$device = $device_default;
}

if ($source eq ""){
print "Burn It Up: No sourec dir specied. Please enter the source dir path\n";
exit;
}

if ($speed == 0){
print "Burn It Up: No writing speed specified. Please specify the wrinting speed 1-48x\n";
exit;
}

if ($mode eq ""){
$mode = $mode_default;
print "Burn It Up: No writing mode specified. Using primarily tao mode.\n";
}
if ($master){
$driveropts = "burnfree,audiomaster";
$mode = "sao";
print "Burn It Up: Digital mastering enabled. Switching to sao mode.\n";
}
else{
$driveropts = $driveropts_default;
}

if ($mode eq "sao"){
print "Burn it up: You must specify the track size using the --tracksize paramater.\n";
print " You can retrive the tracksize value from below:\n";
print " write as this --tracksize XXXXs\n";
$status = system("mkisofs -R -J -q -print-size $source");
if($tracksize){
$tsize = "tsize=$tracksize";
}
else{
$tsize = "";
exit;
}
}

if ($type eq ""){
print "Burn It Up: No cd type specified. Writing data cd.\n";
$type = $type_dafault;
}

if ($multi){
$opt1 = "-multi";
}
else{
$opt1 = "";
}

if ($burn){
$dummy = "";
}
else{
$dummy = "-dummy";
}

$status = system("mkisofs -r -R -J $source | cdrecord -v -$mode $dummy $opt1 speed=$speed driveropts=$driveropts dev=$device -$type $tsize -");
die "Writing CD failed. cdrecord exited with Status Code $?" unless $status == 0;
#code ends here

Back to Blogging

After a failed attempt last year to get back to blogging, I'm trying it again this year. I really wanted to get back, but got busy will...