Monday, December 22, 2008

Force-erasing a DVD+RW

Actually, rather than calling it "force-erase" it's better off being called as trickery.

From the Wikipedia article about DVD+RW,
DVD+RW supports random write access, which means that data can be added and removed without erasing the whole disc and starting over (up to about 1000 times).
While that 'add and remove without erasing the whole disc' thing sounds great, what if you want to erase the disc securely?

Try erasing it with say, K3B, and it'll bail out saying erasing will be done in the background; meaning that if you have 4.4GB of stuff on the disc and you overwrite it with a smaller amount, the old data is still there - Old data which you want to get rid of for some reason (security is a good excuse).


The simplest way of totally erasing a DVD+RW is by writing a 4.4GB ISO which has nothing but 0's in it.

So, from a terminal create the above mentioned disc image using dd.
dd if=/dev/zero of=/tmp/BlankISO.iso bs=1000000 count=4700
Now you just have to burn this ISO file onto your DVD+RW and you have a completely empty disc.

P.S : Blanking a DVD+RW actually defeats the purpose of using a DVD+RW but sometimes you just can't help it.

Cheers!

Sunday, November 9, 2008

A killer umount script

I was just plain sick of the dreaded "Device is busy" message while unmounting the CD drive so I thought I'd do something about it.

#!/bin/bash


if [ $# -gt 0 ]; then

PROC=$(fuser -m $1)

for var in $PROC; do
sudo kill -9 $var
done

fi

sudo umount $1 || echo "Failed to unmount $1"

I saved the file as kumount (lets call it - Killer umount) in /bin.
Make it executable.

chmod a+x /bin/kumount

Now just test it.
I plugged in my audio player, started playing some music in Audacious. Ran the command

kumount /dev/sdc1

... and bang! Audacious got killed and the device unmounted.
Of course, this has many downsides.. Especially when you're copying stuff to a device but I'm sure nobody would kill-unmount devices when they're actually in use ;-)

Tuesday, August 26, 2008

Extracting contents of .deb packages

Commands to decompress .deb files :
mkdir /tmp/foo
cd /tmp/foo
ar vx /home/user/foo.deb

tar vxf data.tar.gz
Contents will be extracted in the current directory. Use the binaries and/or configuration files at your disposal.

Sunday, August 17, 2008

A simple IRC Logger-bot in Bash

The script :

## Bot.sh - begin
#!/bin/bash
config=/tmp/ircbot

echo NICK ircbot > $config
echo USER username +iw ircbot :$0 >> $config
echo JOIN #orkut_linux >> $config

tail -f $config | telnet irc.freenode.net 6667 | while true
do read MESSAGE || break
echo $MESSAGE >> irclog.txt
done

rm $config
## EOF

Make Bot.sh executable:

chmod +x Bot.sh

Now all that's left is to run it.
Enjoy!

Saturday, August 16, 2008

ACPI Suspend/Resume

Suspend to RAM or Suspend to disk on GNU/Linux with an ACPI enabled kernel:

First, we find out what sleep state the system supports by running
echo /sys/power/state
And we finally put the system to sleep by doing (as root) :
echo -n "X" > /sys/power/state
Where X is one of the sleep states obtained from the before mentioned command.
mem / standby - Suspend to RAM (standby)
disk - Suspend to Disk (hibernate)

Example : ( '#' prompt denotes that i'm root already)
# cat /sys/power/state
# mem standby disk
# echo -n disk > /sys/power/state # for suspend to disk (a.k.a 'hibernate')

NOTE : For suspend to disk to work correctly, pass the resume kernel parameter at boot.
kernel /vmlinuz-2.6.25-custom root=/dev/hda1 ro resume=/dev/hda4
Keep in mind that this resume partition must be a valid swap partition.

Friday, June 13, 2008

Installing Slackware 12 on a software RAID device

This HOWTO assumes that you're going to perform a fresh installation of Slackware 12. So lets start :

In this howto, i install Slackware on 3 sofware RAID0 configurations using mdadm. One for /, one for /home and another one for /mnt/extras.

Boot up the Slackware DVD
and log in as root.

Use cfdisk to create the partitions on the harddrives :

The partitioning scheme for my 2 x 80GB SATA harddrives :

/dev/sda :
sda1 Primary Linux ext3 139.83
sda2 Primary Linux raid autodetect 5116.13
sda3 Primary Linux raid autodetect 59411.20
sda4 Primary Linux raid autodetect 15356.60


/dev/sdb :
sdb1 Primary Linux raid autodetect 5116.13
sdb2 Primary Linux raid autodetect 59411.20
sdb3 Primary Linux raid autodetect 15356.60

sda1 is a 140MB partition dedicated to hold the kernel image as well as the bootloader since no bootloader i know of can boot off a software RAID 0 array.

Build your arrays with Multiple Devices Admin (mdadm) program ( level=0 : Striped/RAID0, level=1 : Mirrorred/RAID1, level=4/5/6/10, man mdadm for more help on this )
  • mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda2 /dev/sdb1 # for root
  • mdadm --create /dev/md1 --level=0 --raid-devices=2 /dev/sda3 /dev/sdb2 # for home
  • mdadm --create /dev/md2 --level=0 --raid-devices=2 /dev/sda4 /dev/sdb3 # for anything else ;)

Now fire up the installation as usual (# setup)
Now, when it comes to selecting partitions, pick /dev/md0 as the target for "/" (root)
As you progress in the installer, create the mountpoints :
  • "/home" for the device "/dev/md1"
  • "/boot" for the bootloader on "/dev/sda1"
  • "/mnt/extras" or anything else for "/dev/md2" [this step is optional]
Install everything as you normally would.
Now we mount Slackware (/dev/md0) and the boot partition and chroot into the system
  • mkdir /mnt/md0
  • mount /dev/md0 /mnt/md0
  • mount /dev/sda1 /mnt/md0/boot
  • chroot /dev/md0
Now we are in the OS installed on our software RAID array. Next we mount the Slackware DVD, install and setup GRUB (because i prefer GRUB to LILO ;)
  • mount /dev/cdrom /mnt/cdrom
  • cd /mnt/cdrom/extra/grub
  • installpkg grub*.tgz
  • grub-install --root-directory=/boot /dev/sda # WARNING : GRUB goes into sda's MBR
  • cd /boot/boot/grub
  • touch menu.lst
Create boot entries in menu.lst for GRUB to boot (# nano /boot/boot/grub/menu.lst)
My /boot/boot/grub/menu.lst looks like this :
timeout 10
title Slackware Linux 12.0
root (hd0,0)
kernel /vmlinuz root=/dev/md0 ro
boot
Save & Close.
Just to make sure that fstab mounts the right arrays in the right places, its better to take a look at it is in /etc before we boot into the system (# nano /etc/fstab)
My /etc/fstab looks something like this (Your's probably should look something similar to this ) :
/dev/md0 / ext3 defaults 1 1
/dev/sda1 /boot ext3 defaults 1 2
/dev/md1 /home ext3 defaults 1 1
just type 'exit' to get out of the system and into the DVD, unmount all the drives and reboot.
  • exit
  • umount /dev/sda1
  • umount /dev/md0
  • umount /dev/md1
  • umount /dev/md2
  • reboot
Now if all went well, your Slackware should boot normally that too from a RAID array! ;)
Enjoy !

Apache 2 + PHP 5 on Slackware 12

Installing Apache HTTP Server
  • tar zxvf httpd.tar.gz
  • cd httpd
  • ./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-deflate
  • make
  • make install
  • echo "/usr/local/apache/lib" >> /etc/ld.so.conf
  • ldconfig
For Apache to run at boot :
  • echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local
Installing PHP 5
  • tar zxvf php.tar.gz
  • cd php
  • ./configure --prefix=/usr/local --with-config-file-path=/etc --with-apxs2=/usr/local/apache/bin/apxs --disable-debug --enable-memory-limit --enable-inline-optimization --enable-magic-quotes --enable-mbstring --enable-track-vars --enable-xml --with-dom --with-xml --enable-sockets --with-zlib --with-gettext --with-pear
  • make
  • make install
  • cp php.ini-recommended /etc/php.ini
Edit /etc/php.ini and do the following:
  • change "short_open_tag" to On
  • change include_path to ".:/usr/local/lib/php"
Edit /usr/local/apache/conf/httpd.conf and do the following:
  • add "LoadModule php5_module modules/libphp5.so"
  • add "index.php" to DirectoryIndex
Now, get back to your terminal and just run the following.
  • echo "application/x-httpd-php php" >> /usr/local/apache/conf/mime.types
  • sudo /usr/local/apache/bin/apachectl start

    Done.

Sunday, June 1, 2008

Installing a Pixart Imaging, CIF Single Chip Webcam

Summer, 2008
Blissfully unaware about Hardware Compatibility Lists in driver pages, i finally got myself a USB web cam. It was this little thing i thought would work without hassle. >>

Looks like i was wrong. A `lsusb` output on my Debian GNU/Linux box and this was what i got :


$lsusb
093a:2460 Pixart Imaging, CIF Single Chip

Looking all good, i headed down to Google to search for the vendor ID. I ended up with this (http://mxhaard.free.fr/download.html) page and found out that my cam was supported by the spca5xx drivers. Downloaded the tarball from the same site, wasted a couple of hours downloading hell lot of dependencies for the compilation and finally it compiled. ;)

It just didn't work no matter what. The cam was sitting there literally for months together until i found another blog deeply hidden in Google in which the guy had the same problem as mine and thank heavens he had a workaround too.

So this is what i had to do :


$ cd /path/to/the/tarball/
$ tar xvf gspcav1-20071224.tar.gz
$ cd gspca/modules/gspca/Pixart/


Once there, you need to edit a file called pac207.h
In Line 137, replace
if(id[0]!=0x27) with if(id[0]!=0x27 || id[1]!=0x08)
So you'll end up with this :
....
PDEBUG(2, " Pixart Sensor ID 0x%02X Chips ID 0x%02X !!\n", id[0],
id[1]);
if(id[0]!=0x27 || id[1]!=0x08)
return -ENODEV;

return 0;
....

Well, that's pretty much it. Just save the file, close and rebuild it with "make" and "make install" as root.
Plug in the cam and you'll see some messages appear in
`dmesg | tail` if your webcam was successfully detected and gspca driver was loaded right and yes the cam was working!

P.S : If your kernel doesn't auto-load modules, just do a modprobe gspca