Showing posts with label Linux-howto. Show all posts
Showing posts with label Linux-howto. Show all posts

May 11, 2009

Solve no sound problem in Ubuntu

One after another 17 days have passed.. till today my laptop was completely silent when i booted into Ubuntu. But now, just 10 mins back, after a lot of hit and trial with driver model, I could make make my laptop speak. Here's what I did.
Though I specified this as ubuntu problem in title, it the problem of alsa; it's not recognizing your device.

I completely forgot what I did to mess up my laptop-sound-system, so i thought to start afresh.
I removed the alsa and pulseaudio completely. And One thing I would like to mention: I am completely unfamiliar about the interaction of alsa and pulseaudio with the sound system. This is my first deal with sound system of linux to this depth.
sudo apt-get --purge remove linux-sound-base alsa-base alsa-utils \
"pulseaudio-*"

Then I did a quick Reboot; just playing safe. (Jaunty boots on/off so fast, I am fan of it.)
Next I reinstalled the alsa with pulseaudio.
sudo apt-get install linux-sound-base alsa-base alsa-utils \
libasound2-plugins "pulseaudio-*" paman padevchooser \
paprefs pavucontrol pavumeter

Then, I appended following lines to the file /etc/modprobe.d/alsa-base.conf
alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel
options snd-hda-intel model=dell-m6
options snd-hda-intel enable_msi=1

The bold faced "model=dell-m6" was the main hack for the system to work.

Then after another quick boot, I got the sound.

During this I refered a lot of pages, But the most useful and the one that is well documented is: Comprehensive Sound Problem Solutions Guide
And this is the page where I got the model of the sound-card(dell-m6) from.

Mar 24, 2009

make scite, a default editor in gnome

Personally, I prefer scite over gedit (The one that is included by default in gnome). So soon after every system upgrade (fresh installation), I simply remove gedit and install scite:
sudo sh -c "apt-get -y remove gedit && apt-get -y install scite"

Now to make it a default text editor run:
sudo update-alternatives --install /usr/bin/gnome-text-editor \
gnome-text-editor /usr/share/scite 1

Dec 17, 2008

Schedule a job in cron

For the task that you have to run regularly in some period, scheduling it in the cron is the one and only way for it.
For this run this in terminal:
crontab -e

This will start the vi editor and load the current cron table file for this user, or a blank file if none exists. In a new line type the following

A B C D E < path to the script > [Arguments if any]


Where:

  • A = minute of the hour

  • B = hour of the day

  • C = day of the month

  • D = month of the year

  • E = day of the week



Example:
To schedule a Task daily at 9 in the moring that lies in /home/sata/script. I use the following.
0 9 * * * /home/sata/script

Nov 11, 2008

Run GUI application as another user.

I knew that if there is some flaw in irc-client it will leave a security loop in the system. And the attacker get the privilege of the user running the irc-client. And you know what it will lead to.
So specially to run the X-chat (a irc client), I created another user irc with very less privilege.

Then I tried running the xchat as follows:
suraj $ su irc
Password:
irc$ xchat
No protocol specified

(xchat:6966): Gtk-WARNING **: cannot open display: :0.0


Hum.. There occured a problem. The app couldn't get handle to the grapics display.

So here is the solution:
$ sudo apt-get install sux

and run
$ sux irc xchat
Password:


Provide the password of the user irc and see the application launching.

Oct 30, 2008

Disable root ssh login

Disabling ssh is one of the major security enhancement. It is just a simple task. What you need to do is edit a file ("removing a #") and restart the service. Here it goes,
First you need to find the following line and remove the comment from the file "/etc/ssh/sshd_config".
#PermitRootLogin no

ie. Just remove the preceding "#"

You can edit it in your favorite editor. But remember you need to be have root access to edit it.

Or simply you can run the following command from terminal
sudo sed -i "s/#PermitRootLogin/PermitRootLogin/g" /etc/ssh/sshd_config

Now, For this to take effect, you need to restart the service:
sudo /etc/init.d/sshd restart

Sep 29, 2008

reset mysql root password

Recently, one person left me in his system to solve one of his problem associated with webservice.
He left me and went somewhere and asked me to solve the problem before I left.

During this i requited the mysql root password, but he want there. So i googled to reset the mysql password. And here is what i did to reset the password.

$ sudo /etc/init.d/mysql stop

$ sudo mysqld_safe --skip-grant-tables --user=root

$ sudo mysql -u root


Run this query in mysql prompt:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;


Finally kill this mysql process and restart it safely:

$ sudo /etc/init.d/mysql start


ref: http://www.linuxweblog.com/blogs/sandip/20060330/reset-mysql-root-password

Aug 8, 2008

Change your terminal prompt (bash)

I always get messed up with the output and the prompt. I wanted to so sth that would make the prompt distinguishable. I also hate the (increasing) length of prompt ie showing the full current path.

Ok here's what and how I did. It easy and a bit tricky.

You must have known that while starting a (bash) terminal, the terminal itself runs the script in the "~/.bashrc" file. If you didnt know, know it now.

Ok. Its straight forward, what we do now is add few lines to the end of the file. So open the file in any editer you like and add the following line at the end of the file

BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
PS1="\[$BLUE\][\u@\h]\[$RESET\] "


Here the env variable PS1 is the normal terminal prompt. FYI PS2 contains the continuation prompt in bash.
So what this says is "DISPLAY A PROMPT IN BLUE COLOR SHOWING [USERNAME@HOSTNAME] AS PROMPT".

Here is the screenshot of my (gnome-)terminal:
gnome-terminal

Zoomed
Zoomed gnome-termial

EDIT:
Here is a list of Escape Sequence that yuu can use:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html

Jul 22, 2008

NETDEV WATCHDOG: eth0: transmit timed out

NETDEV WATCHDOG: eth0: transmit timed out
eth0: Transmit timeout, status 00000004 00000249

This was the error that i got in my kernel log message.

I was unable to use internet in my laptop "MS 1006". I tried setting up the network in either way (dhcp and static) but non of these solved the problem. I got terribly wired, as i could see no other message beside "destination host unreachable" and waiting for never offering, DHCP.

I even wasted 2 days and even googled for many keywords. But i couldnt get the solution. But finally the end of the second day was fruitful. I solved it.

This was due to the interrupt conflict that occured between the acpi and network modules.
I turned off acpi while booting by adding following words at the end of the boot option.

Before:

title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,1)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=e89b77d0-3183-4036-b508-15d9a23dc86c ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet


After:

title Ubuntu 8.04, kernel 2.6.24-16-generic
root (hd0,1)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=e89b77d0-3183-4036-b508-15d9a23dc86c acpi=off ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic
quiet


Enjoy the net.

ref:

  1. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/183588

  2. http://bugzilla.kernel.org/show_bug.cgi?id=7595

Jul 17, 2008

Solve [mount_point cannot contain the following characters: newline, G_DIR_SEPARATOR (usually /)]

I recently suffered from this problem. I googled it and finally solved it.
This is a bug filed here.

I specified the mount point like "sata/160GB", expecting it to mount the device in "/media/sata/160GB". But the problem started here. The system expects only a word here with no slashes(/) in it. While mounting it just creates a folder which you provided, in /media and mounts the volume there.

And this is what I did:

Open gconf-editor in terminal:
$ gconf-editor
In the left panel:
Goto:
System -> Storage -> volumes

Here you will see the mount point you specified for the device.
Change it to just a single word (OR just remove it :) )
Thats it. Replug your device.

Enjoy!!!

EDIT:
1. Do not use sudo for this purpose.
See this comment by Anonym... (Thanx to Anonym) for detail.

2. Sometimes instead of System -> Storage -> volumes you may also get System -> Storage -> drives , depending upon what you messed up. The rest process is same.

Jul 13, 2008

writing-udev-rules, the other way

Here's my earlier post on about writing the udev rules:
writing-udev-rules, the easier way
This will give you a bit of understanding about what a udev-rule is and how can you write a udev rule on the basis of vender-id and product-id.

Here is the other way (Its easier but a bit time consuming):
So here you go..
Insert your usb-device, and watch the log:
# tail -f /var/log/messages
Jul 13 16:47:20 workbench kernel: [ 5418.740803] sd 7:0:0:0: [sdb] 312581808 512-byte hardware sectors (160042 MB)
Jul 13 16:47:20 workbench kernel: [ 5418.743055] sd 7:0:0:0: [sdb] Write Protect is off
Jul 13 16:47:21 workbench kernel: [ 5418.743072] sdb: sdb1
Jul 13 16:47:21 workbench kernel: [ 5419.323103] sd 7:0:0:0: [sdb] Attached SCSI disk
Jul 13 16:47:21 workbench kernel: [ 5419.323163] sd 7:0:0:0: Attached scsi generic sg2 type 0

Notice the third-last line. It shows that the device is mounted as sdb1.
Now lets dig into it.
# udevinfo -q path -n /dev/sdb1
/block/sdb/sdb1


This shows the devpath of the device.
From this devpath you can see a lot of information.

# udevinfo -a -p /block/sdb/sdb1

At the very first line of the output you will see:


"Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device."

This pretty much explains itself.

And the (trimmed-)output is:

looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"

looking at parent device '/block/sdb':
KERNELS=="sdb"
SUBSYSTEMS=="block"
DRIVERS==""
ATTRS{dev}=="8:16"
ATTRS{range}=="16"
ATTRS{removable}=="0"
ATTRS{size}=="312581808"
ATTRS{stat}==" 206 10881 12228 1688 0 0 0 0 0 1272 1688"
ATTRS{capability}=="12"

...

looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x24dd"
ATTRS{subsystem_vendor}=="0x8086"
ATTRS{subsystem_device}=="0x4246"
ATTRS{class}=="0x0c0320"
ATTRS{irq}=="19"
ATTRS{local_cpus}=="ff"
ATTRS{modalias}=="pci:v00008086d000024DDsv00008086sd00004246bc0Csc03i20"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""

looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""



So you can choose any block and write the rule for that.
Let me zoom into a block

looking at device '/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{dev}=="8:17"
ATTR{start}=="63"
ATTR{size}=="312576642"
ATTR{stat}==" 11011 11620 0 0"

So here's the rule for this :
KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{dev}=="8:17", ATTR{start}=="63", ATTR{size}=="312576642", SYMLINK+="myDisk"

Now, this is also not the only rule. Go on! Generate your own rule. Mind with the spaces like in case of ATTR{stat}==" 11011 11620 0 0".

Finally place the rule in /etc/udev/rules.d/60-persistent-storage.rules. Then Plug out the device and again plug-in to see the change.


# ls /dev/ | grep my
myDisk


That's it.
If you want to learn more about it:
http://reactivated.net/writing_udev_rules.html
http://ubuntuforums.org/showthread.php?t=168221

Writing udev-rules, the easier way

What is udev-rules?
udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.

Okay, here i will show you howto write udev-rule for a USB hardisk.


# lsusb

Bus 005 Device 003: ID 04fc:0c25 Sunplus Technology Co., Ltd
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 004: ID 062a:0000 Creative Labs Optical Mouse
Bus 001 Device 001: ID 0000:0000


This gives us two information, one of them is what we want.
Very first line shows that I have a Device with vernder id: 04fc and product id:0c25 named "Sunplus Technology Co., Ltd "

The second-last line points my USB-mouse, which is not of much interest now.

Now move to the /etc/udev/rules.d directory

# cd /etc/udev/rules.d


As the device is a storage device we will be writing the rule in "60-persistent-storage.rules"
So open this file with your prefered editor (I recommend scite in gui and vim in console) and add the following line:
KERNEL=="sd*[0-9]",SYSFS{idVendor}=="04fc",SYSFS{idProduct}=="0c25", SYMLINK+="sata"

This informs udev-manager, that if any storage device with vendour-id, 04fc and product-id 0c25 is plugged into the system add a symlink in /dev with name, sata.

Note: This rule is specific to the device only. And also this is not the only rule that you can write.

This is the easiest way. And there is another way round to work on this: >Here<

Jul 11, 2008

Generate your gpg-key


GNU Privacy Guard (GnuPG or GPG) is a replacement for the PGP suite of cryptographic software. It is freely available and is a part of Free Software Foundation's GNU software project.

Generating your gpg-key in linux
Terminal,:) the following:

~$ gpg --gen-key

You will be asked with the following options:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)

*nux-platform developers are crazy... there is no any reason for sth like this 1, 2 and then suddenly 5 ;)

Choose the option according to your choice if you dont know what DSA and RSA are. Just gooooogle them. I recommend choosing (2) as it gives better security. Remember it's just for signing purpose.

DSA keypair will have 1024 bits.
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years

Choose 0 if you dont want it to expire.
Provide your Real name ( at least 5 chars ), Email address and Comment.

Conform (enter alpha-O) it and wait few secs and your key is ready.

Ps: You may be asked to move your mouse or do any thing on your desktop to refill the pool of random numbers.

Mar 18, 2008

Change ssh Welcome Banner

/etc/motd

Everything you write in this file is shown as welcome banner when someone enters your into your box via ssh.

So sudo gedit /etc/motd :) enjoy!!!

Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

Here's the quick and easy way to re-enable Grub.

1) Boot off the LiveCD

2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub "prompt", and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.

$ sudo grub
> find /boot/grub/stage1
> root <the output of above command>
> setup (hd0)
> quit


Reboot (removing the livecd), and your boot menu should be back.

Dec 29, 2007

Multiple X-clients in Linux

Before starting note that this is tested in ubuntu (a debian-based distro).

Here i will be assuming that you are familiar with X-system in linux.

Perhaps you know, what you will get when you press F1 to F8 with control and alt key. Well, if you don't know let me just brief it for you. By default, there are six virtual terminals in linux, F1 through F6.By pressing <ctrl> + <shift> + Fx you can switch to corresponding terminal. Next in F7 there is you your desktop manager. If you are reading this from linux, I must say this is where you currently are. In F8 you will see system logs. From F9 - F12 ...? Yes, this is where we will run other instance of desktop manager.

A brief intro about X-system:
In x-system there are two main parts X-server and X-clients. X-server simply communicates your hardware with the x-clients and a desktop manager gives a gui-environment to make the communication between the user and the x-client easier.
For detail goto wiki-page

Okay, Lets kick off:
It's just a single command. Open a terminal and login using any user-account and just enter the following command:

~$ startx -- :1 &

This command starts a new desktop-manager in screen:1 and the '&' symbol simply backgrounds the process.

The desktop manager on which you currently are, is Screen:0 ==> F7 and by issuing :1 as argument you are requesting to start it on Screen:1 ==> F9 (as you know in F8 there is system log)
Note: You might get it in F8 too or even other in other ditros.

Similarly you can start other three x-client from F10-F12 simply by choosing a from screen 2-4. By starting the x-client as user 'xyz' you will be logged in as same user. And remember you cannot start multiple x-clients in same screen.
In some distro you may also get some error or warning if you try to run it as root.


Note: I have tested it in Ubuntu. If you have tested it successfully in other distro then please post it as a comment.

Nov 29, 2007

Limiting the power of Sudoers

Basically in linux, a default user "root" have full access to any kind of file (every thing is file in linux, yes! even device!!!). Sometimes it is necessary for other users in the same system to access some file which are inaccessible for him by default. Command "sudo" helps to solve this problem. It is used as follows:

$sudo <command-inacessable_by_default arguments_if_any>

This Sudo command limits the user's power on the basis of the configuration made on the file "/etc/sudoers".
Generally in default case you might see something like this:
root ALL=(ALL) ALL
Above, you can see ALL 3 times. But what does it mean?
The first ALL: Run from any(all) host
The Second ALL: From any Terminal
The third ALL: Can Run any command

So, the line means the "root" run any command from any terminal from any host.
Now, how to change this? Dont ever attempt to change the power of root :) any thing may happen to your system. I cannot predict what will happen, but it is not obviously going to be good.

Yes, but you can add another user to sudoers list and limit his authority(power).Lets kick off:

Let me add another user "foo" which can have full acess to "ifconfig" command from current host.

foo HOST=(ALL) COMMAND

what do you think? will it work. Obviously not.

What does HOST and COMMAND mean?
HOST is just an alias to host(s), which i defined here.
Similarly COMMAND is a alias to command(s)

We should also define these aliases in the same file (etc/sudoers)

Host_Alias HOST = 127.0.0.1
Cmnd_Alias COMMAND =/sbin/ifconfig


If you want to give "foo" to access other commands too. you can simply append the line line with a seperator comma(,). ie:
Cmnd_Alias COMMAND =/sbin/ifconfig, <path to other command(1)>,<path to other command(2)>...

In similar fashion you can also add add other hosts too.
Further there are other 2 more types of aliases you can define:
User_Alias
Runas_Alias


I hope you got it...

you can find a detailed info by running the following line in console:
man sudoers

A visual defination of sudo:
http://howtoxyz.blogspot.com/2007/11/this-is-what-sudo-is.html :)

ref: http://www.go2linux.org/sudoers-how-to

Oct 28, 2007

batch resizing images in linux

we often need to decrease the image size before uploading. You must be using some graphical software to resize them. Its not that tedious if its one or two but what if you have to resize a large numbers of images!!!. This is what i do.

Basically two commands are used here.
1. djpeg - decompress a JPEG file to an image file
2. cjpeg - compress an image file to a JPEG file

So to resize, i run this script on a folder containing the image files.

#!/bin/sh

mkdir resized
for i in *.JPG
do
echo 'Resizing image..' $i
djpeg -scale 1/2 $i | cjpeg > resized/$i
done


After script is done, a folder named 'resized' is created containing the resized images.

Note:
Both djpeg and cjpeg aren't installed by default, they're part of libjpeg-progs package. Under Ubuntu you can get it by

sudo apt-get install libjpeg-progs


(source: jwalanta.blogspot.com)