jump to navigation

Make Documentation Easier to Read February 4, 2006

Posted by Carthik in administration, snippets, ubuntu.
12 comments

Today’s tip rules them all, for it puts you in the driver’s seat.

Debian (and ergo Ubuntu) has some of the best documentation in the world. The best thing about the documentation is that it is on your machine, not on the internet. However not many realize this, and many a problem that can be solved just by reading the documentation remains unsolved, and many a user resorts to forums, mailing lists etc when the answer is right there on their own computer. I am guilty too, having realized the power of RTFM-ing before.

You can browse most of the html documentation on your system by
Clicking the System -> Help menu item on the desktop taskbar. Besides Manual Pages, and other Documentation, you will find lots of docs for the different applications.

But what if the tool/library you installed does not come with a GUI, or a menu entry? The documentation for all packages is installed in /usr/share/doc. You could use the terminal to change to that directory and then look around to find the directory containing documentation for the package. Or you could use today’s tip 🙂

To make documentation easier to access, set CDPATH as follows:
$export CDPATH=.:/usr/local:/usr/share/doc

To make the change permanent (across terminal sessions/restarts), add the line to your ~/.bashrc file.

Now, to find documentation for package-name
Type:
$cd package-name
and then you can do an $ls to see what documentation is on offer. You can then use your favourite editor/pager to read the documentation.

Often, if you have problems with a package, it is good to read the README.Debian file to see if there are any special notes explaining workarounds or expected problems.
$ pager README.Debian

If there is a file called index.html, you can read the html documentation using
$firefox index.html

There, now you are all set to go exploring and find out more about the packages installed on your system. I was literally overjoyed to find the “CDPATH” variable for bash which makes things so much easier.

Keeping SSH Sessions Alive February 3, 2006

Posted by Carthik in administration, snippets, ubuntu.
68 comments

Scott Merrill writes in to say:

I noticed recently that ssh connections from my Ubuntu laptop to my
Debian server would time out and disconnect if I left the connection
idle for a long-ish period of time. This really annoyed me, because my
Debian desktop does not exhibit this behavior when connecting to the server.

I added the following line to /etc/ssh/ssh_config :
ServerAliveInterval 5

That seems to have fixed the problem, and my laptop can now remain
connected, though idle, to my server. Maybe this will help someone
else, too.

What this does, essentially is every 5 seconds, the client sends a small keep-alive packet to the server to make it look like the ssh connection is being actively used. The reason for Scott’s timeout could be a NAT firewall that seeks to minimize the nember of active connections to reduce its memory footprint, or to improve performance for other clients. Most firewalls and networks let you keep your connections alive for as long as you wish, but some may act up, and that’s when you can use Scott’s trick.

Tip: Change 5 to 240 or 300, so that instead of every 5 seconds, the keep-alive signal is sent only once in 4 or 5 minutes 🙂

Sorry it took me so long to post this useful tip, Scott.

Defining Keyboard Shortcuts for Commands January 30, 2006

Posted by Carthik in administration, guides, snippets, ubuntu.
32 comments

One of the insanely difficult things to do in Gnome/Ubuntu is to map a custom keyboard shortcut to launch an application. Someone out there knows why one has to muck about in the gconf-editor to do this!!! Usability experts, listen up and fix this! While you are at it, please make it easier to change the default application used to open different filetypes.

But I rant, needlessly 🙂

Faced with the difficult problem of creating a keyboard shortcut to have +E to open up Nautilus, I found this very useful guide to adding keyboard shortcuts for commands in Gnome.

Move /home to it’s own partition January 29, 2006

Posted by Carthik in administration, guides, ubuntu.
352 comments

Having the “/home” directory tree on it’s own partition has several advantages, the biggest perhaps being that you can reinstall the OS (or even a different distro of Linux) without losing all your data. You can do this by keeping the /home partition unchanged and reinstalling the OS which goes in the “/” (root) directory, which can be on a seperate partition.

But you, like me, did not know this when you first installed Ubuntu, and have not created a new partition for “/home” when you first installed Ubuntu. Despair not, it is really simple to move “/home” to its own partition.

First, create a partition of sufficient size for your “/home” directory. You may have to use that new hard drive, or adjust/resize the existing partition on your current hard-drive to do this. Let me skip those details.

Next, mount the new partition:
$mkdir /mnt/newhome
$sudo mount -t ext3 /dev/hda5 /mnt/newhome

(You have to change the “hda5” in the above to the correct partition label for the new partition. Also, the above assumes that the new partition you created is formatted as an ext3 partition. Change the “ext3” to whatever filesystem the drive is formatted to.)

Now, Copy files over:
Since the “/home” directory will have hardlinks, softlinks, files and nested directories, a regular copy (cp) may not do the job completely. Therefore, we use something we learn from the Debian archiving guide:
$cd /home/
$find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/

Make sure everything copied over correctly. You might have to do some tweaking and honing to make sure you get it all right, just in case.

Next, unmount the new partition:
$sudo umount /mnt/newhome

Make way for the new “home”
$sudo mv /home /old_home

Since we moved /home to /old_home, there is no longer a /home directory. So first we should recreate a new /home by:
sudo mkdir /home

Mount the new home:
$sudo mount /dev/hda5 /home
(Again, you have to change “hda5” to whatever the new partition’s label is.)

Cursorily verify that everything works right.

Now, you have to tell Ubuntu to mount your new home when you boot. Add a line to the “/etc/fstab” file that looks like the following:

/dev/hda5 /home ext3 nodev,nosuid 0 2
(Here, change the partition label “hda5” to the label of the new partition, and you may have to change “ext3” to whatever filesystem you chose for your new “home”)

Once all this is done, and everything works fine, you can delete the “/old_home” directory by using:
$sudo rm -r /old_home

Michael, Russ and Magnus posted this solution on the ubuntu-users mailing list a few months ago.

Digg this articleDigg This!

Turn on Bash Smart Completion January 28, 2006

Posted by Carthik in administration, commands, snippets, ubuntu.
63 comments

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents

If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now 🙂

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.

Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!

To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:

#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi

Now you can use tab completion to power your way through commands.

You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

Make sudo/gksudo remember passwords January 25, 2006

Posted by Carthik in administration, snippets, ubuntu.
15 comments

I use sudo and gksudo quite often. Now, if you use sudo in a terminal window, then you only have to enter the password the first time. But what if you have more than one terminal window, and try to use a sudo command in all of them? You will be prompted for your password the first time you use sudo in each terminal window. The same applies for gksudo.

This makes sense for a computer that is acting as a server. If you are logged in from multiple locations, and you enter the password for sudo in your current location, all the other locations are still “safe” since the person using the other terminals will still have to enter the password to use sudo. But when it comes to desktop use, this behaviour can be an annoyance.

I hate being prompted again and again for the sudo password (and the graphical gksudo password). For me, on my laptop, I want the sudo password to be “shared” between the different terminal windows, and with gksudo. It would be nice if the timestamp on the password was “global” to all terminals, and all the “gksudo” menu entries.

I ensure this by changing the following line in /etc/sudoers:
Defaults !lecture,tty_tickets,!fqdn

to
Defaults !lecture,!tty_tickets,!fqdn

Here, tty_tickets refers to “terminal tickets”, and I just changed it from using one ticket per terminal, to a common ticket, globally.

Again, this is not recommended for server installs, but may make life a little easier for average Joe Desktop Users.

Rescue Data from Failing Partition January 21, 2006

Posted by Carthik in administration, applications, commands, guides, ubuntu.
19 comments

If you have a hard disk drive, or a drive partition that is failing, or if you want to copy data from one partition to another (don’t we all, at some time or the other?), then ddrescue comes to the rescue!
In case parts of the partition you are trying to rescue data from are corrupt, then ddrescue (unlike dd) skips over it and gets out all the data that is uncorrupted!

Install ddrescue using
$sudo apt-get install ddrescue

Make sure you have a partition with more disk space that the entire partition you are trying to retrieve data from. Yes, that includes occupied AND free space on the partition you are trying to retrieve data from.

Rescue data using:
$dd_rescue /dev/hda1 /some/dir/drive-backup.img
Where you might have to replace /dev/hda1 with the partition you are trying to rescue data from, and /some/dir/ should have more free space than the entire /dev/hda1 partition.

This creates a drive image. You can mount it as a loop device. Do the following to do just that:

sudo touch /dev/loop1
sudo losetup /dev/loop1 /some/dir/drive-backup.img
–If you get an ioctl error, run “$sudo modprobe loop”, and run the prior command again
sudo mount -t ext3 /dev/loop1 /media/drive-backup
(replace ext3 with the filesystem type of your old partition)

Now you can browse /dev/loop1 and copy out all your data. If you use an external USB drive to backup the image to, you can take the image with you 🙂

Thanks are due to Dan Martin who posted this at the ubuntu-users mailing list a few weeks ago.

Enabling CPU Frequency Scaling November 4, 2005

Posted by Carthik in administration, applications, guides, ubuntu.
142 comments

I use the CPU Frequency Scaling Monitor on my panel to see the speed of my CPU. I have a centrino laptop. Ubuntu automatically increases the speed (frequency) of my laptop when the demand is more, and manages things very well.

However, when I am plugged in, I want to run my laptop at the maximum possible frequency at certain times. It turns out that the CPU Frequency Scaling Monitor can also have the functionality to change the Frequency, by “Governing” the CPU frequency. However, by default, on my laptop, left-clicking on the Monitor in the Panel did not give me the option to change the frequency.

In order to be able to change the operating frequency, your processor should support changing it. You can find out if your processor has scaling support by seeing the contents of files in the /sys/devices/system/cpu/cpu0/cpufreq/

For example, on my system:

$cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
gives:

1300000 1200000 1000000 800000 600000

Which means that the above frequencies (in Hz) are supported by my CPU.
and…
$cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
gives:

userspace powersave ondemand conservative performance

All those are the different “modes” I can operate the CPU at. Userspace, for example, regulates the frequency according to demand. Performance runs the CPU at max-frequency, etc…

On the Ubuntu Forums, I read that one can manually change the frequency by executing commands like:
$ cpufreq-selector -f 1300000
which will set the frequency to 1.3 GHz.

Now, I was interested in being able to change the power mode (between the different values listed in the “governors” above, manually by using the Cpu Frequency Panel Monitor.

I found out from the Forums, again, that changing the permissions of the cpufreq-selector binary by doing a:
$sudo chmod +s /usr/bin/cpufreq-selector

will allow me to acheive this. However, I was curious as to why Ubuntu does not, by default, allow me to choose the frequency using the CPU Frequency Panel Monitor, and what the “right” or “correct” way of enabling this is.

With a little bit of detective work, I found the reason why things are the way they are in Bug #17604 :

Oh, please, not another setuid root application if we can avoid it. Which file does cpufreq-selector need access to to change the CPU speed? And why should a normal user be able to change the CPU speed in the first place? The automatic CPU speed works well enough for the majority of users, and control freaks can always use sudo to manually set the speed, or deliberately shoot themselves in the foot by making the binary suid root (as explained in README.Debian).

Anyways, since I really want to “shoot my self in the foot” using my CPU ;), so I read the readme:
$cat /usr/share/doc/gnome-applets-data/README.Debian

and as suggested in it, I did a
$ sudo dpkg-reconfigure gnome-applets
and answered “Yes” to the question regarding setting the suid of the cpufreq-selector executable. Now, by left-clicking on the CPU Frequency Monitor Applet, I can choose the frequency for my processor, and things couldn’t be better!!

P.S.: A lot of my detective work could have been avoided had I read the README in the first place. Stupid me.

22x Faster Upgrade October 14, 2005

Posted by Carthik in administration, ubuntu.
38 comments

Use a mirror in your /etc/apt/sources.list file for faster upgrades. I went from 28 kbps downloads to 600+kbps downloads by editing my /etc/apt/sources.list to use a mirror instead of the usual ubuntu.com repository. Why wait when you can upgrade faster, eh? Instead of taking hours to download the updated packages, it took me less than half an hour. It is better if the mirror is geographically close to you.

Choose from the list of mirrors (look under the mirror-mirrors section) and update your sources.list now!

Enabling cupsys Web Admin Interface October 13, 2005

Posted by Carthik in administration, ubuntu.
34 comments

If you are trying to get your printing system going, and search for tips and docs on the web, you will find most of the documentation referring to http://localhost:631 as your cupsys administration interface. However, on Ubuntu, this browser-based administrative interface for cupsys is disabled by default. Here’s how to enable it:

Select “System”->”Administration”->”Users and Groups” from the main menu on your desktop.
Select “Show all users” and/or “Show all groups”.
Add the user “cupsys” to the group “shadow” in the “groups” tab.

Restart cupsys by issuing the command:
$sudo /etc/init.d/cupsys restart

IMPORTANT: I don’t know why the web admin interface was disabled in the first place – so please know that it is best to reverse all that you did once by removing the user cupsys from the shadow group,a nd restarting cupsys, once your work with the interface is done. If anyone knows why the web-browser interface was disabled in Ubuntu, please let me know – a lot searching and reading changelogs led me nowhere 🙂