Tag Archive for 'linux'

Linux booting optimizations

This is a smal guide that I use myself in new or current Debian GNU/Linux installations, to reduce a bit (about some seconds), the overall booting time.

To start, we need a way to measure the time that our system needs to boot up.

  • Bootchart: It measures time required to boot the system, and displays it in a graphical way.
    • $sudo apt-get install bootchart
    • Edit /etc/grub/menu.lst, and add "init=/sbin/bootchartd" to the kopt line.
    • $sudo update-grub
    • Edit /etc/bootchartd.conf and set "AUTO_STOP_LOGGER" to "yes"

Now some basic "safe" optimizations. Optimizations that you can do without breaking the system.

  • ReadAhead: It preloads all files required to boot at the begining of the boot process. (Note: If you have preload installed it must be dissables when the first run is done.)
    • $sudo apt-get install readahead
    • If preload is installed, temporally dissable it by adding "exit 0" at the beggining to /etc/init.d/preload
    • Enable profile on first run: $sudo touch /etc/readahead/profile-once
    • reboot system (yes you need to reboot, sorry, is one of these exceptions when you need to reboot Linux.)
  • preload: It learns with system libraries are most used, and preloads them on demand.
    • $sudo apt-get install preload
  • dash: By default the OS ships with bash that is extremely slow, thus all init shell scripts run very slow. Dash is a faster shell implementation. I saw an increase of 6 seconds in my experiments.
    • $sudo apt-get install dash
    • Install dash as default sh interpreter: $sudo dpkg-reconfigure dash
  • You need an e-amail server?: By default the OS will ship with a full e-mail server, because some desktop applications an other stuff depend on it. Debian comes with Exim, the light version by default. This means that you will have an extra useless process consuming resources at boot time, and during execution. You can't remove it because it's needed, but you can replace it with a null mailer implementation. So there are two possible packages avaliable depending on your e-mail needs. Of course if you really need a full e-mail server in you computer, then you may continue with wathever you have.
    So, we have ssmtp and esmtp-run

    • ssmtp: This mailer will deliver all mail to a remote e-mail server, it does not do local mail delivery it's only usefull when you already have an e-mail server in your network.
      • $sudo apt-get install ssmtp
      • Configure your remote e-mail server. $sudo dpkg-reconfigure ssmtp
    • esmtp: Same as ssmtp, but does local mail delibery. If you don't have a remote mail server to use, just use localhost as a mail server, it will try to deliver mail to it, but since there is no service running it will fail, thus it will only do local delibery. This is perfect for a laptop where I'm only interesting on recieving locally system generated mails, I don't want my laptop to send e-mails outside. (In fact most Linux distros ship by default with an e-mail server that will do remote delivery by default, altough it's only listenning on localhost, I see that as a possible security threat that any user could exploit, altough nowadays most e-mail servers will reject those e-mails.).
      • $sudo apt-get install esmtp-run
  • quiet saves time also. The "quiet" kernel parameter it's usually enabled on most distros, but if it is not enabled in your distro, it's poosible to save some time. Just check that "quiet" is present in "defoptions" of your /boot/grub/menu.lst configuration file.
  • remove some useless garbage: Some completely useless services, that only waste ram, and time. (Always check when you remove something from your system, that you are not deinstalling your entire operating system due to dependencies. I at least know a case of someone that wanted to unistall mysql but unistalled the entire os, because the os had dependencies over mysql?? (This only happens on Ubuntu, Debian does not have this problem ;-P )
    • Who needs "inetd", I don't use anything that it provides. $sudo apt-get --purge remove openbsd-inetd
    • WTF is avahi? More useless garbage. I remove it as soon as I install a new system. $sudo apt-get --purge remove avahi-daemon avahi-autoipd
    • localepurge: Why do you need your os avaliable in 560 and more languages? Them waste disk space.
      • $sudo apt-get install localepurge
      • Configure it to the locales that you want to keep $sudo dpkg-reconfigure localepurge
      • And free about 1Gigabyte or more of space. $sudo localepurge
    • orphaner: Remove unused orphaned system libraries.
      • $sudo apt-get install deborphan
      • Remove all unused garbage: $sudo orphaner
    • autoremove unused stuff: Remove all those packages that were installed but are currently not used and we don't want them in our system.
      • $sudo apt-get --purge autoremove
    • remove unused config files: Unistalled packages will drop a lot of garbage in the /etc directory, so remove it.
      • $sudo dpkg --purge `dpkg --get-selections | grep deinstall | cut -f1`

Some dangerous optimizations. These optimizations may break your system into an unboatable status, and also require lot of user intervention to configure.

  • insserv: Reorders the init scripts. May break some thing that need to be manually fixed.
  • runit: Another init system, requires a lot of time to configure and get a boatable, system. NOT recomended for currently installed systems. Should be implemented on new systems, with lot of patience. I personally do not have enough patience and/or time to configure runit.

That's all for today.