`
love~ruby+rails
  • 浏览: 829576 次
  • 性别: Icon_minigender_1
  • 来自: lanzhou
社区版块
存档分类
最新评论

How to make Ubuntu extremely fast

阅读更多

Old hardware? Want a faster boot up? Need to free some system resources? Want snappier applications? This is for you.  Note, I wouldn’t suggest doing anything within this if it doesn’t make sense to you.

 

Boot Process

1. Remove Network Manager if you do not need it “sudo apt-get remove network-manager”. If possible give yourself a static IP in /etc/network/interfaces like so:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
network 192.168.1.100
broadcast 192.168.0.255
gateway 192.168.1.1

Having a static IP helps with boot time as your machine doesn’t have to communicate with the router/dhcp server as much to obtain an address.

2. Also remove firestarter or whatever graphical firewall frontend you’re using. Learn to control iptables at boot up and shutdown . It’ll be much snappier.  Some have been critical of this step, but firestarter is used quite frequently in ubuntu and it runs an additional startup process before the desktop environment is loaded.  Doing straight iptables is much faster, plus you’ll learn something anyways.

3 . Install bum, “sudo apt-get install bum” and run it with root access. Shut off all unnecessary services. If you’re not sure about a service research it before shutting it off. Also, install sysv-rc-conf. Run the application as root. This will allow you to control, in an easy way, what services start at which run level. It’s like bum, but more detailed. Be very careful with which services you are removing from which run-level. If you don’t know what you’re doing here, research it or don’t touch it. After you do this you may want to reboot to make sure you didn’t break anything.

4. Turn off usplash in grub. (Mind you, you’re bootup won’t be as pretty as the splash will go away).

  • vim /boot/grub/menu.lst
  • on the kernel line delete the words “splash” and “quiet”
  • Reboot to see the changes.

I remove “quiet” simply to show what’s going on.  It does not have to be removed.

5. If you have a dual core processor, you can decrease your boot time with concurrency.

  • sudo vim /etc/init.d/rc
  • and find the line CONCURRENCY=none and change it to: CONCURRENCY=shell
  • Reboot to see the changes. (tired of rebooting yet?)
  • automounting encrypted drives done with dm-crypt/luks will not work with concurrency.

6 . Remove some TTYs

I could easily do this by editing /etc/inittab and then commenting the extra TTYs there. With the new upstart mechanism in place, things are a little different.

You have to edit /etc/default/console-setup file. This file defines how many ttys should you get.

Change ACTIVE_CONSOLES=”/dev/tty[1-6]” to the number of consoles you want. Lets say, 3 ttys, then change it to “/dev/tty[1-3]“.

And then goto /etc/event.d/ and change the ttyx files that you DONOT want. Edit them and comment lines starting with “start on runlevel”. So, in this case, you’ll comment the start line in tty4..tty6 files.

Rebooting shoud minimize the number of consoles for you. Worked for me!! Good luck, NOTE: Even though you’ve reduced the tty number, X is still on Alt-F7. Again, go ahead and reboot to make sure you didn’t break anything.

Tune Your Hard drive

Speed up your ext3 file system

The following tweaks assume that you are using an ext3 filesystem for your Ubuntu OS and they will offer a noticeable performance boost! However, there is also a bad side of them… if you don’t have an UPS and your system will power off accidentally or because of a power loss, YOU WILL LOSE IMPORTANT DATA! (don’t say you haven’t been warned)


Open a terminal (Applications -> Accessories -> Terminal ) and type:

CODE
sudo vim /etc/fstab


WARNING: The following is just an example! Do NOT copy the lines into your /etc/fstab file! Just REPLACE the options marked with underline with the ones marked with bold !

From this:

# /dev/sda1
UUID=19f70288-7340-40c0-82d1-ee4b218fee1d / ext3 relatime,errors=remount-ro 0 1

To this:

# /dev/sda1
UUID=19f70288-7340-40c0-82d1-ee4b218fee1d / ext3 noatime,nodiratime,errors=remount-ro,data=writeback 0 1

<script type="text/javascript">&lt;!-- google_ad_client = &quot;pub-2941637122112958&quot;; google_alternate_color = &quot;FFFFFF&quot;; google_ad_width = 234; google_ad_height = 60; google_ad_format = &quot;234x60_as&quot;; google_ad_type = &quot;text&quot;; google_ad_channel =&quot;1838017730&quot;; google_color_border = &quot;000000&quot;; google_color_link = &quot;FFFFFF&quot;; google_color_bg = &quot;FFFFFF&quot;; google_color_text = &quot;000000&quot;; google_color_url = &quot;0000cc&quot;; google_ui_features = &quot;rc:10&quot;; //--&gt;</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script><script src="http://pagead2.googlesyndication.com/pagead/expansion_embed.js"></script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></script><script>google_protectAndRun(&quot;ads_core.google_render_ad&quot;, google_handleError, google_render_ad);</script>

Save and close. Now type the following command in the terminal:

CODE
sudo vim /boot/grub/menu.lst


And add the following option…

rootflags=data=writeback

…to the end of the following lines:

# defoptions=quiet splash vga=795 (by default, Ubuntu doesn’t have the “vga=795? option on this line. It appears if you did the second tweak from the first step (see above)).

# altoptions=(recovery mode) single

Save and close, and paste the following command in the terminal:

CODE
sudo update-grub


Type now the following command in order to manually change your filesystem “on-the-fly” into writeback.

CODE
sudo tune2fs -o journal_data_writeback /dev/sdb2


ATTENTION: Please note that /dev/sdb2 is MY root (/) partition. If you have the root (/) partition in another place (for example /dev/sda1 or /dev/sda2) change it accordingly. Please look in /etc/fstab for this!

That’s all, now reboot your system and when you get back, you should feel an increased speed in video, image or audio usage.

Tune your swappiness

If you have been running Linux systems for some time and you have used applications like ‘top’ to see what’s going on in your machine, then you’ve probably wondered: Where has all my memory gone? You should know that the largest place it is being used in is the disk cache, as the cached memory is free and it can be replaced anytime if a newly started application needs that memory. Linux systems are made like this to use so much memory for disk cache because the RAM is wasted if it is not used and if something needs the same data again, then there is a very good chance to be in the cache memory.

Open a terminal (Applications -> Accessories -> Terminal ) and paste the following code:

CODE
sudo vim /etc/sysctl.conf


Now add the following line at the end of this file:

CODE
vm.swappiness=10


The number at the end of this line can be between 0 and 100. At 100 the Linux kernel will prefer to find inactive pages and swap them out, while value 0 gives something close to the old behavior where applications that wanted memory could shrink the cache to a tiny fraction of RAM. Save, close and reboot.

Preload and Prelink

prelink

Any executable that makes heavy use of shared libraries can benefit from prelinking. Prelinking resolves addresses of shared libraries in advance this reduces number of relocations.

Prelink is also useful in the context of security since we can tell prelink to make libraries load at random addresses until next run of prelink. This is useful since libraries won’t load at fixed addresses on every system.

You can install prelink by issuing following command.

sudo apt-get -y install prelink

Change a line inside the configuration file /etc/default/prelink from

PRELINKING=unknown

to

PRELINKING=yes

We will do our first prelinking by executing following command

sudo /etc/cron.daily/prelink

Thats it you don’t have to do anything else. Prelink daemon will run periodically to optimize your newly installed executables.

preload

Preload is a little application that monitors files of frequently used applications and and loads them in to the memory when system is idle. This usually results in lesser startup times for those applications. Install preload by executing following command.

sudo apt-get -y install preload

New Applications

Ok time to install a faster window manager and set of applications:

Add this repo in /etc/apt/sources.list:

#openbox https://launchpad.net/~k-belding/+archive
deb http://ppa.launchpad.net/k-belding/ubuntu hardy main
deb-src http://ppa.launchpad.net/k-belding/ubuntu hardy main

and then:

sudo aptitude update && sudo aptitude install openbox pypanel gmrun obmenu obconf nitrogen gtk-chtheme sakura scrot kazehakase sylpheed rtorrent irssi finch decibel-audio-player xfburn mirage abiword gnumeric leafpad epdfview xarchiver pcmanfm ivman

For an explination of each:

  • openbox is an alternative window manager that we’ll be using as our desktop environment. It’s snappier than Fluxbox since it was rewritten to no longer be based off blackbox code.
  • pypanel – since open box comes with no panel, this is an extremely light weight one, it can be configured in ~/.pypanelrc. You’ll need to add this to .config/openbox/autostart.sh with the line: pypanel &
  • gmrun – will give you a small run dialog upon running
  • obmenu – graphical openbox menu editting app
  • obconf – graphical openbox theme changer, among other options
  • nitrogen – lightweight application to change wallpapers
  • gtk-chtheme – will allow you to change gtk themes. Icon themes and fonts can be specified in .gtkrc-2.0
  • sakura – a light weight tabbed terminal. Easier to configure than aterm, xterm and the like.
  • scrot – a command line screenshot tool
  • kazehakase – a lightweight browser based on the gecko engine (A heads up about the hardy package: you can’t view the preference menu, it’ll crash. You can control most things through it’s config files and about:config)
  • sylpheed – a light weight email application
  • rtorrent – a command line torrent app
  • irssi – command line irc
  • finch – the command line version of finch
  • decibel-audio-player – a light weight gtk based audio app
  • xfburn – a burning application from the xfce suite
  • mirage – an extremely light weight image viewer
  • abiword and gnumeric – lighter office apps when compared to open office.
  • leafpad – extremely lightweight notepad app
  • epdfview – lightweight pdf viewer
  • xarchiver – lightweight archiving and compression tool to replace file-roller with.
  • pcmanfm – tabbed, lightweight file manager.
  • ivman – a behind the scenes auto-mounter. You’ll need to add this to .config/openbox/autostart.sh with the line: ivman &

Here are some great reads on how to configure openbox:

  1. http://icculus.org/openbox/index.php/Main_Page
  2. http://wiki.archlinux.org/index.php/Openbox
  3. http://gentoo-wiki.com/HOWTO_Openbox

And that’s it. Log into openbox and get to configuring things the way you want it.

Use Readahead

This guide asks you to use the command-line to issue some commands, and uses the readahead-list and readahead-watch applications to profile a bootup. Changes to the system are easily reversible and the worst negative impact would be a reduction in login speed (the irony!). Of course, since you will be doing some things with root access, failure to correctly type in some commands may lead to permanent damage to your software or data. These changes are unsupported by Ubuntu developers. You probably shouldn’t try this unless you have more than 512MB RAM.

PART 1: Profile Login Sequence

First, we need to ask readahead to monitor a login sequence and make note of all the files read during this period. Advanced users may point out that during bootup, there is a GRUB argument “profile” that causes Ubuntu to optimize bootup. We will need to essentially manually replicate what this boot option does, but save the output to a different file.

First, let’s store our readahead list into a ~/.readahead directory.

Code:
mkdir ~/.readahead

Now, log out, and press CTRL+ALT+F1 to log into a terminal. Start the profiler:

Code:
sudo readahead-watch -o ~/.readahead/gnome.root /

This will grind the disk for a while (up to a few minutes) then it will return you to a command prompt. The profiler is now in the background watching all actions. Now, without logging out, go to your GDM prompt (ALT+F8 ) and log in normally.

after you are fully logged in, press CTRL+ALT+F1 to go back to your terminal, then run:

Code:
sudo killall readahead-watchsudo chown jdong:jdong ~/.readahead -R

Replace jdong:jdong with your user and group name. Now, we need to go prune this list a bit. Especially if you have large files on your desktop (like a 1GB AVI), the login sequence may touch it, causing readahead to think it should load the whole thing into memory! In a terminal, run:

Code:
cat ~/.readahead/gnome.root | xargs -i ls -lk {} | sort -rn -k +5 | less

This will display all the files readahead wants to cache, sorted by largest file first. The 5th column (before date) is the size of the file in KB. Make sure there’s nothing glaringly large. If it’s bigger than 10,000KB or so, it’s probably not worth preloading. You can remove unwanted files from the preload list by opening ~/.readahead/gnome.root in your favorite editor, and deleting its line.

If you have home on a different partition as root, you should repeat Part 1 for each partition, replacing gnome.root with a different name, and replacing the mountpoint / with each interested mountpoint.

PART 2: Hooking this into the login sequence.

Next, we need to tell Ubuntu to do this readahead on every login. I am going to use /etc/X11/Xsession.d for this, but if you have another preferred way to execute things before everything loads, be my guest!

Create a file called /etc/X11/Xsession.d/00readahead and put this in it:

Code:
for list in ~/.readahead/*; do  readahead-list $list &done

wait

Save the file. Now, you can reboot to try it out. You will notice the login
“hang” at the orange screen while the disk works without much grinding, then once that is done the bootup should soar as if it were a fully cached login. This brings my login session to around 30 seconds, a notable improvement.

PART 3: Hook into bootup sequence

Often times, we don’t log in immediately when the prompt comes up. We might be getting a cup of coffee, or an entire lab might be turned on before students arrive. It makes sense to cache a login as a part of bootup. Open up /etc/rc.local in your favorite text editor, and before the exit 0 statement, add:

Code:
for list in /home/jdong/.readahead/*; do  readahead-list $listdone

Note you need to hard-code a particular user in there, and this time we don’t background it. (We could, but there is not much motivation to)

Now, reboot, and wait for all disk activity to stop before logging in. This
time, I get a login speed of 19 seconds.

You might have two common questions at this point:

1. How much time does it take to call readahead again on files that have been cached once already? About 0.05 seconds to call readahead on the same list a second time

2. How much overhead does it add to bootup if the background readahead was still going, and you tried to log in? About 2 seconds on my setup

Conclusion

In my case, applying this readahead hack lead to a 10-second improvement in login speed in the worst-case scenario, and a remarkable doubling in login speed when the system idles at the login prompt for a few seconds.

This is a pretty appreciable improvement and it would be nice if a nicer version of this hack can be added to Ubuntu. The basic idea should be fairly simple to adapt to an /etc/readahead/readahead.gnome file representative of the default system and hooked by an Xsession.d script.

Many more applications come to mind as taking a long time to load while the disk grinds (Firefox? Openoffice? Eclipse?). You can use a procedure very similar to this to write a “wrapper script” that first performs a readahead-list call on a list, then call the application with the original arguments. I’d be interested to hear of any improvements gained by that method.

Undoing readahead

Remove, remove, remove! Delete the ~/.readahead directory, delete /etc/X11/Xsession.d/00readahead, and delete the line you added to /etc/rc.local

All Done

Your system should be a 100 times more snappier.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics