Archive for October, 2009

First I’ll say I’m nowhere near an expert on bluetooth with Ubuntu – or even bluetooth for that matter. What I’ve done is mash together a lot of different things until I found what worked for me. Your mileage my vary, but this is how I got my Plantronics bluetooth cellphone headset working with Skype in 64 bit Ubuntu Intrepid.

Please note – the bluetooth stack changed between Hardy (8.04) and Intrepid (8.10). This is for Intrepid.

Setup the bluetooth environment

First, of course, you must get bluetooth working and paired with your bluetooth headset. That part is actually pretty easy.

Make sure you have the following packages. I think bluez-alsa is the one that may not be installed by default, but go ahead and check them all:

sudo apt-get install bluetooth bluez bluez-gnome bluez-alsa bluez-gstreamer libbluetooth3

Once it’s all installed, create a file called .asoundrc in your home directory and place the following text inside it:

pcm.Headset {
  type bluetooth
  profile "voice"

I saw several HOWTO’s that talked about loading modules or otherwise affecting the audio drivers, but I found that with Intrepid, none of that was necessary.

Pairing your headset

I found that if you’d tried to pair your device before or otherwise went through an upgrade, it may be a good idea to remove all associations. BE ADVISED: this will remove ALL bluetooth pairings from your computer, so if your keyboard or mouse uses BT, don’t do this next step!

sudo rm -R /var/lib/bluetooth/*

Now, reboot and attempt to pair your device. One of two ways may work – you may simply trigger a pairing on the headset and a pop-up will automatically appear on your desktop offering to pair it. If that doesn’t happen, right click on the bluetooth icon in the tray and pick setup new device. You can probably figure out the rest of the pairing from there.

Test with ALSA

Once your headset is paired, let’s make sure it’s working through ALSA properly. Run the following. After a few seconds, you should hear whatever you say echoed back in your ear:

arecord -D Headset -f S16_LE | aplay -D Headset -f S16_LE

Hit CTRL-C to cancel the recording. If however you get Input/Output errors, try restarting the bluetooth service:

sudo /etc/init.d/bluetooth restart

Unfortunately I found that every time I turn off the headset, I have to restart the bluetooth service before it works again.

If you haven’t made it this far, I honestly don’t know what could be wrong – but feel free to discuss it in the comments with each other – someone may have a clue. For me, things worked at this point – I think. The problem is that I tried a LOT of different things before getting this far, and it’s possible I’ve left out a step I did without realizing it.

Install missing libraries

Now, I’m going to assume you already have Skype working on your 64 bit system using the static build of Skype for 64 bit Ubuntu installs. I’ll also assume that you already figured out that it’s not working with your bluetooth headset. If you run Skype from a command line you should see:

Cannot open shared library /usr/lib32/alsa-lib/

This is because Skype is looking for the 32 bit libraries.

The easiest way to install what you need is the same trick used for Tweetdeck. Download the GetLibs package and install it.

After getlibs is installed, run the following:

getlibs -p bluez
getlibs -p bluez-alsa

You may find you need to reboot one last time. Now in Skype set your audio source and output to “Headset” and run a test echo call. If all has gone well you should be up and running!


To make an ISO from your CD/DVD, place the media in your drive but do not mount it. If it automounts, unmount it. (ubuntu automount so you need to unmount, that’s quite easy, just choose the option unmount from the shell).

dd if=/dev/dvd of=dvd.iso # for dvd
dd if=/dev/cdrom of=cd.iso # for cdrom
dd if=/dev/scd0 of=cd.iso # if cdrom is scsi

To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.

mkisofs -o /tmp/cd.iso /tmp/directory/

This results in a file called cd.iso in folder /tmp which contains all the files and directories in /tmp/directory/.

For more info, see the man pages for mkisofs, losetup, and dd, or see the CD-Writing-HOWTO at

Nano is the default editor in ubuntu. This is how to change it to your preferred editor.

sudo update-alternatives --config editor

Choose preferred editor:

There are 4 alternatives which provide `editor’.

Selection Alternative
1 /bin/ed
2 /usr/bin/vim
*+ 3 /bin/nano
4 /usr/bin/emacs21

Press enter to keep the default[*], or type selection number: 2

LVM is a great tool for volume management. You can easily add a new (virtual) harddisk to a existing logical volume.
With fdisk -l you can see what devices are available. Choose the right one and execute:

fdisk /dev/sdb

Create a new partition which fills up all the free space with the type Linux LVM (HEX: 8e).
Then we create a physical volume for LVM:

lvm> pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

After that we can extend the volume group with this new physical volume:

lvm> vgextend VolGroup00 /dev/sdb1
Volume group "VolGroup00" successfully extended

Then extend the existing logical volume with 100% of the free space from the new physical volume:

lvm> lvextend -l +100%FREE /dev/VolGroup00/os
Extending logical volume os to 27.84 GB
Logical volume os successfully resized

That’s all, the existing logical volume is now extended with the new harddisk.
If you have a ext3 filesystem on this logical volume you can extend this online using the command:

[root@dbdev01 ~]# resize2fs /dev/VolGroup00/os
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/os is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/os to 7299072 (4k) blocks.
The filesystem on /dev/VolGroup00/os is now 7299072 blocks long.

On a linux terminal you can simply run a process in the foreground like it normally does. But if you close your terminal session the process will stop running. If you run a large database import you don’t want to wait for it to finish, so you want to run it in the background.

To do this you can simply put a ‘&‘ behind the command you want to execute, for example:

mysql -u root -p < import.sql &

But it’s also possible to put a process to the background when it’s already running. You can do this with the keyboard shortcut ctrl + z. Then you ’stop’ the process. You should see a message like this:

[1]+  Stopped                 mysql

Now you can choose two things, one is to run it in the foreground, the other is to run it in the background.
Just type bg <enter> and the process will continue running in the background. With fg <enter> it will run in the foreground.

You can see what processes are running in the back- or foreground with the command jobs.

Normally when you execute a command in your shell you’ll get the output direct on your screen. But it’s also possible to redirect this output to a file, for example for logging purposes.


php myscript.php > mylog.log

Now all output from myscript.php will go in the mylog.log file. This is called the “standard output” (stdout). But when a PHP error occurs it will not be written to the mylog.log file. Instead it will be printed on your screen. This is the “error output” (stderr), and to write this to mylog.log you have to use this:

php myscript 2>&1 mylog.log

This will send all output to mylog.log including the errors. It’s also possible to only write the error ouput to a log file.

php myscript 2> mylog.log

Combine this with ‘running processes as background jobs ‘ and you can run your scripts/command in the background but still be able to watch the progress in the log file.

php myscript 2>&1 mylog.log &

And now watch your log with

tail -f mylog.log

You can use several options to streamline the viewing of large text files, such as /var/log/messages. Some of these options are described in the article below.

# head
The head command will print the first 10 lines of a file to the screen. This can be coupled with the options “-n ” to display a larger number of lines. So for instance,
# head -n 40
would display the top 40 lines of a text file.

# tail
Much like #head, the tail command will display the last 10 lines of a text file. This can also be coupled with the option “-n ” to display a larger number of lines.

# cat
Cat will print the entire contents of a file to the screen.

You can also add a ‘| grep’ to the end of any of these commands to search for a specific word. For instance,

# cat testing.txt | grep error

would only report the lines containing the word ‘error’. Note that this is case-sensitive.

How do I restrict access to a given command for instance /opt/apps/start, to authorized users only under Linux / UNIX / BSD operating system?

You need to use traditional Unix groups concept to enhance security including restricted access to a given command.

Step # 1: Create and Maintain a Group For All Authorized Users

Create a group named appsonly:
# groupadd appsonly
Add all authorized users to appsonly:
# usermod -aG {groupName} {userName}
# usermod -aG appsonly tom
# usermod -aG appsonly jerry
# id jerry


  1. -a : Add the user to the supplemental group(s) i.e. appends the user to the current supplementary group list.
  2. -G : A list of supplementary groups which the user is also a member of.

Step #2: Restrict Access

Now a group of user had been created. Next, use the chgrp command to change the group of /opt/apps/start to appsonly group:
# chgrp {groupName} {/path/to/command}
# chgrp appsonly /opt/apps/start

Disable the file permission for others

Finally, use the chmod command to change file permission as follows:
# chmod 750 /path/to/command
# chmod 750 /opt/apps/start

You can also apply permissions to directory (this will disable ls command access to others) :
# chgrp appsonly /opt/apps
# chmod 0640 /opt/apps

Step # 3: Test It

su to tom, enter:
# su - tom
$ id
$ /opt/apps/start
$ exit

su to vivek (not a member of appsonly group), enter:
# su - vivek
$ id
$ /opt/apps/start

Sample outputs:

bash: /opt/apps/start: Permission denied

A Note About ACL and SELinux

The access control policies which can be enforced by chmod, chgrp, and usermod commands are limited, and configuring SELinux and fille system ACLs (access control list) is a better and recommend option for large deployments.

Recommend readings:

  • man page chgrp, groupadd, useradd, usermod, passwd, and group file.

Q. How do I find out my SCSI hard disk RPM speed from a Linux shell prompt without opening my server case? How do I find out hard disk model and serial number from a shell prompt?

A. A typical desktop hard disk rotate at 7,200 revolutions per minute (RPM). A typical server hard disk spin at 10,000 or 15,000 rpm to achieve sequential media transfer speeds. You can use hard disk model number to obtain disk RPM. For example, a typical Seagat disk Model # ST373455SS can provide following information:

  • ST – Brand identity
  • 3 – Form Factor (3 = 3.5″)
  • 73 – Disk size / Capacity in GB i.e. 73GB
  • 4 – Reserved for future use
  • 5 – RPM ( 5 = 15k and 0 = 10K)
  • 5 – Generation
  • SS – Indicates interface i.e Serial Attached SCSI

How do I find out hard disk model and serial number?

Use any one of the following command from shell prompt to find out hard disk model number:
$ cat /proc/scsi/scsi
OR use scsi_id command to querys a SCSI device via the SCSI INQUIRY vital product data (VPD) page 0x80 or 0x83 and uses the resulting data to generate a value that is unique across all SCSI devices that properly support page 0x80 or page 0x83.
$ /sbin/scsi_id -g -p 0x80 -s /block/sdd
$ sudo grep -i sdd /var/log/boot.log
OR use sginfo / scsiinfo command from sg3_utiles package, enter:
# sginfo -a /dev/sdd | more

scsiinfo or sg3_utils package

sg3_utils is a collection of Linux utilities for devices that use the SCSI command set. You can install by typing following command:
# yum install sg3_utils
If you are using Debian / Ubuntu Linux, enter:
$ sudo apt-get install sg3-utils

WARNING! Some of these tools access the internals of your hard disk system and the incorrect usage of them may render your system inoperable or loss of data possible.

Now you can use command sginfo with the -g switch to obtain information about hard disk cylinders, heads and RPM:
# sginfo -g /dev/sdd
Sample output:

Rigid Disk Geometry mode page (0x4)
Number of cylinders                74340
Number of heads                    2
Starting cyl. write precomp        0
Starting cyl. reduced current      0
Device step rate                   0
Landing Zone Cylinder              0
RPL                                0
Rotational Offset                  0
Rotational Rate                    15015

Finding out your hard disk RPM speed using manufactures website / product page

Once obtained hard disk model number, directly go to manufactures website and search for model to get detailed information.