Sunday, July 15, 2012

Modify Ubuntu

Today I bumped onto this website: http://modifyubuntu.com

It is really well structured and it includes really good solutions that work! Enjoy!

p.s. I am expected to be exploiting all those options one by one! ;)

Ubuntu swappiness. Improve ubuntu performance


Ubuntu swappiness. Improve ubuntu performance. vm.swappiness=10. sysctl.conf
If you are looking to squeeze every last bit of performance out of Ubuntu, you can change swappiness value. Swappiness can have a value between 0 and 100. A recommended setting for swappiness is 10.

By adding swappiness=10 to the sysctl.conf file, you will see quite an improvement in Ubuntus performance. To add this please follow the instructions.

Open your terminal and enter the following command:

sudo gedit /etc/sysctl.conf
If you are using Kubuntu swap gedit for kate.
sudo kate /etc/sysctl.conf
You will be prompted to enter your root password. After entering your password the sysctl.conf file will appear. Scroll to the bottom of the file and add the following code.
vm.swappiness=10
Save the file. Next time you reboot you should see an improvement in Ubuntu's performance. Here is a screenshot of the sysctl.conf file

 



http://www.techheadz.co.uk/219.html

Ubuntu : update-apt-xapi takes lot of cpu usage


Ubuntu : update-apt-xapi takes lot of cpu usage
Problem : The process "update-apt-xapi" causes increase in CPU utilization to 100%

There are 2 ways to check this problem :

1.  One is to go to the System Monitor and click on the Processes tab. Sort by %CPU Used and the offending process should pop to the top.

2. The other way is to executed a terminal and type “top” w/o the quotes. Top is a great little application that lists the top users of CPU time, plus gives a bunch of great info at the top of the terminal screen like total uptime, CPU info, process statistic

What is update-apt-xapi?
The actual name of the package is "update-apt-xapian-index". It helps in maintaing an index of packages, and this helps speed up searching for packages in Synaptic, and possibly in other package managers as well.

Solutions :

There are 3 possible solution to solve this problem :

Note: Use method 2 and 3 only if 1 does not works.


1. Edit /etc/cron.weekly/apt-xapian-index

This method will do following things :
a) Run process with the lowest system priority.
b) Update the index and not built it again (faster)

i) sudo gedit /etc/cron.weekly/apt-xapian-index

ii) replace the line
nice $IONICE -c 3 $CMD --quiet
by
nice -n 19 $IONICE -c 3 $CMD --update --quiet

iii) Save And exit And you are done.

In depth detail of changing  cron file can be found here:(Not important)
----------------------------------------------------------------------------------------------------------------------------------
Cron is a utility for scheduling tasks to run at certain times. System tasks run weekly are, unsurprisingly, stored in the /etc/cron.weekly directory. You can also set up personal tasks to run pretty much whenever you want. For that, have a look at man crontab.

Looking at the internals of the code we're using here, the first line, the "crunchbang" line (#!), tells the system what executable to use to run the contents -- in this case, /bin/sh, or your basic shell.

The next two lines establish two shorthand variables. Variables in shell scripts are generally defined in ALL CAPS for easy readability. This is more of a best practice than any hard-and-fast requirement. When referenced later in the script, the variable names are prefixed with a $. Here, CMD is simply shorthand for the path to the update-apt-xapian-index binary, and IONICE is shorthand for the path to the ionice utility for getting or setting a process's I/O scheduling class and priority.

In the if statements, the -x checks to see if the next argument exists, so if [ -x $CMD ] will check to see if /usr/sbin/update-apt-xapian-index exists in the filesystem.

nice -n is basically how you assign a priority to a process. An important caveat, however, is that nice is just that -- a high nice value (up to a maximum of -n 19) means the process is nice and gets out of the way, and a low nice value (down to a minimum of -n -20) means the process is *not* nice and barges to the front of the line to be the first to use system resources. Niceness defaults to 10 if not otherwise specified, and apparently the default update-apt-xapian-index setup does not specify any value.

ionice is new in this fix. It works along similar lines, affecting a process's input/output niceness, only using the flag -c for "class". The ionice man page describes -c:

Quote:
-c class
The scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle.
Finally, we have the two options passed to update-apt-xapian-index itself, --update and --quiet. --quiet just tells it to not generate much text, only outputting for fatal errors, which makes sense for a background process. --update is new here in this fix together with the nice value and the ionice prioritization, and is a real kicker: it tellsupdate-apt-xapian-index to only update those items in the index that have actually changed. This seems like a no-brainer, since the index includes *every* package installed in the system, but unfortunately the default update-apt-xapian-index setup in a fresh install of Jaunty, Karmic, or Lucid all leave this option out, meaning thatupdate-apt-xapian-index will rebuild the ENTIRE package index every time it runs. No wonder it eats up so much memory and CPU time! With --update, it should take much less resources and much less time.
----------------------------------------------------------------------------------------------------------------------------------

2.  Making the weekly update script non-executable

It turns out that it installs itself to run weekly by adding a script to /etc/cron.weekly/. That’s easy to fix simply by making the script non-executable through file permission change:

sudo chmod 644 /etc/cron.weekly/apt-xapian-index

3.  Remove update-apt-xapi package
sudo apt-get autoremove --purge apt-xapian-index
sudo apt-get autoremove --purge

Note : Purging apt-xapian-index causes the quick search feature in Synaptic to become inoperative.

Tuesday, July 10, 2012

Reset the network adapter from the command line

If you really want to reset the network adapter you usually need to unload and reload the kernel module that it uses.
If you just want to reconfigure it you can usually do:
sudo /etc/init.d/network-manager restart
But if you just want a new dhcp lease (that's the technical name for obtain a new IP from the router), you just need to use:
sudo dhclient -v eth1

https://help.ubuntu.com/10.04/internet/C/troubleshooting-wireless.html

Monday, July 9, 2012

Make Thunar the default file management to make utility run even faster


Introduction

The default file manager in Ubuntu is Nautilus. Some people prefer other file managers. Unfortunately, it's difficult to make other file managers the default, especially since Nautilus manages the desktop icons in Gnome (Ubuntu's desktop environment).

Disclaimer

The first version of this script has been written by a non-programmer. It has been tested and works but, as you can see from the comments in the script, it could still be tweaked to be "better".

Script to change Thunar to be the default file manager

To run this script, paste this block of code into a text file and save it as a file nameddefaultthunar in your home folder.
Toggle line numbers
#!/bin/bash

## Originally written by aysiu from the Ubuntu Forums
## This is GPL'ed code
## So improve it and re-release it

## Define portion to make Thunar the default if that appears to be the appropriate action
makethunardefault()
{
## I went with --no-install-recommends because 
## I didn't want to bring in a whole lot of junk,
## and Jaunty installs recommended packages by default.
echo -e "\nMaking sure Thunar is installed\n"
sudo apt-get update && sudo apt-get install thunar --no-install-recommends

## Does it make sense to change to the directory?
## Or should all the individual commands just reference the full path?
echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nMaking backup directory\n"

## Does it make sense to create an entire backup directory?
## Should each file just be backed up in place?
sudo mkdir nonautilusplease
echo -e "\nModifying folder handler launcher\n"
sudo cp nautilus-folder-handler.desktop nonautilusplease/

## Here I'm using two separate sed commands
## Is there a way to string them together to have one
## sed command make two replacements in a single file?
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-folder-handler.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-folder-handler.desktop
echo -e "\nModifying browser launcher\n"
sudo cp nautilus-browser.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop --browser/thunar/g' nautilus-browser.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-browser.desktop
echo -e "\nModifying computer icon launcher\n"
sudo cp nautilus-computer.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-computer.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-computer.desktop
echo -e "\nModifying home icon launcher\n"
sudo cp nautilus-home.desktop nonautilusplease/
sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-home.desktop
sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-home.desktop
echo -e "\nModifying general Nautilus launcher\n"
sudo cp nautilus.desktop nonautilusplease/
sudo sed -i -n 's/Exec=nautilus/Exec=thunar/g' nautilus.desktop

## This last bit I'm not sure should be included
## See, the only thing that doesn't change to the
## new Thunar default is clicking the files on the desktop,
## because Nautilus is managing the desktop (so technically
## it's not launching a new process when you double-click
## an icon there).
## So this kills the desktop management of icons completely
## Making the desktop pretty useless... would it be better
## to keep Nautilus there instead of nothing? Or go so far
## as to have Xfce manage the desktop in Gnome?
echo -e "\nChanging base Nautilus launcher\n"
sudo dpkg-divert --divert /usr/bin/nautilus.old --rename /usr/bin/nautilus && sudo ln -s /usr/bin/thunar /usr/bin/nautilus 
echo -e "\nRemoving Nautilus as desktop manager\n"
killall nautilus
echo -e "\nThunar is now the default file manager. To return Nautilus to the default, run this script again.\n"
}

restorenautilusdefault()
{
echo -e "\nChanging to application launcher directory\n"
cd /usr/share/applications
echo -e "\nRestoring backup files\n"
sudo cp nonautilusplease/nautilus-folder-handler.desktop .
sudo cp nonautilusplease/nautilus-browser.desktop .
sudo cp nonautilusplease/nautilus-computer.desktop .
sudo cp nonautilusplease/nautilus-home.desktop .
sudo cp nonautilusplease/nautilus.desktop .
echo -e "\nRemoving backup folder\n"
sudo rm -r nonautilusplease
echo -e "\nRestoring Nautilus launcher\n"
sudo rm /usr/bin/nautilus && sudo dpkg-divert --rename --remove /usr/bin/nautilus
echo -e "\nMaking Nautilus manage the desktop again\n"
nautilus --no-default-window &

## The only change that isn't undone is the installation of Thunar
## Should Thunar be removed? Or just kept in?
## Don't want to load the script with too many questions?
}



## Make sure that we exit if any commands do not complete successfully.
## Thanks to nanotube for this little snippet of code from the early
## versions of UbuntuZilla
set -o errexit
trap 'echo "Previous command did not complete successfully. Exiting."' ERR


## This is the main code
## Is it necessary to put an elseif in here? Or is
## redundant, since the directory pretty much
## either exists or it doesn't?
## Is there a better way to keep track of whether
## the script has been run before?
if [[ -e /usr/share/applications/nonautilusplease ]]; then 

restorenautilusdefault 

else

makethunardefault

fi;

Then paste these commands into the terminal
chmod +x defaultthunar
./defaultthunar


from: