Make Debian boot faster

Posted by peterhoeg on Wed 27 Jul 2005 at 20:42

Several people have written guides on booting Debian systems faster. Most of these involve reordering initscripts, and other significant changes. There is a much simpler alternative to speeding up boot times though, whilst it might not work for all it's an interesting hack.

A simple one-line hack is to run scripts in parallel, merely by changing the startup script /etc/init.d/rc.

Changing the line:

startup $i start

to the following:

startup $i start &

This idea originated here.

 

 


Posted by davrieb (129.27.xx.xx) on Sun 31 Jul 2005 at 22:24
[ View davrieb's Scratchpad ]
It is ok to do this on your own machine, but you should always keep in mind that this can lead to problems.

Some services assume that some other services are already up and running. With your proposal this can no longer be guaranteered. This services may now fail or not fail depending if everything starts in the right order.

I am not saying, that this is really a bad idea, but it can break things in non-obvious ways and you should know about that before doing that

[ Parent | Reply to this comment ]

Posted by peterhoeg (62.242.xx.xx) on Mon 1 Aug 2005 at 07:22
This is true - there are potential issues from dependancies.

However, Debian seems to start all critical services in single user mode, so I have not yet seen any problems.

[ Parent | Reply to this comment ]

Posted by fsateler (200.104.xx.xx) on Mon 1 Aug 2005 at 00:59
[ View Weblogs ]
I don't know about other computers, but in my PC most of the time isn't spent services starting up, but rather in system initialization. For example, hotplug takes a lot of time, loading lots of modules that either I don't need, or that are already loaded. I've tried compiling my own kernel, and leaving out stuff I don't need, but I can't seem to get the same performance I get from stock kernels.

--------
Felipe Sateler

[ Parent | Reply to this comment ]

Posted by Anonymous (213.150.xx.xx) on Mon 1 Aug 2005 at 08:37
What about initng ? I have not try it because it is to young for me, I don't want to take the risk but it seems quite powerfull.

http://initng.thinktux.net/index.php/Main_Page

[ Parent | Reply to this comment ]

Posted by peterhoeg (62.242.xx.xx) on Mon 1 Aug 2005 at 08:43
Yes, there are various replacements. But my idea behind this hack is that it is so dead simple, that anybody can do it.

The post found at the end of the link in the article also has some more references to how other people did various things to speed up the boot process, but none of them are as simple as mine.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.51.xx.xx) on Tue 2 Aug 2005 at 15:54
If you really want to replace init runit is the best choice (IMHO).

It's a daemontools like thing with BSD license and cleanup (additional features too!)

Take a look: http://smarden.org/runit

It is a part of debian so: apt-get install runit
(installing runit-run replaces init)

But this requires a lot of work (as seen in the other comment above).
-- cstamas

[ Parent | Reply to this comment ]

Posted by hardik (61.95.xx.xx) on Sat 3 Sep 2005 at 07:28
I am totaly agree with you, If you want to make your debian
box faster, replace init with runit. which is only three stage booting process. Check more on..... http://smarden.org/runit


With Cheers,
Hardik Dalwadi.

[ Parent | Reply to this comment ]

Posted by hildeb (193.175.xx.xx) on Mon 1 Aug 2005 at 09:10
Another idea is to use kexec to reboot, which exists in 2.6.13 release candidates and upwards. This bypasses the BIOS which (on many of my machines) takes ages to do whatever it does :) For kexec, you need a kexec enabled kernel (2.6.13-rcX) and the kexec-tools http://www.xmission.com/~ebiederm/files/kexec/ I load the kernel in /etc/init.d/umounfs:
...
echo "Loading kernel for kexec()"
/usr/local/sbin/kexec \
   --load /vmlinuz \
   --command-line="root=301" \
   --append="root=301 panic=5"

echo -n "Deactivating swap..."
...
and kexec the kernel in /etc/init.d/reboot:
PATH=/sbin:/bin:/usr/sbin:/usr/bin

echo -n "Rebooting... "
/usr/local/sbin/kexec -e
reboot -d -f -i

[ Parent | Reply to this comment ]

Posted by shufla (83.30.xx.xx) on Mon 1 Aug 2005 at 10:37
Huh. That's nice, but AFAIR there are disk read/write bottlenecks, which are able to slow down paraller loading process. Right now I've set it up on my ubuntu box (which is Hoary, and in Hoary gdm starts ASAP - before apache, pg, etc).

My conclusion: it's little bit faster, on Workstation box it should not fail on anything, but boot time from grub-init2 is longer than init2-gdm screen. Pure kernel initialization and hotplug from rcS are the slowest ones.

[ Parent | Reply to this comment ]

Posted by Anonymous (195.202.xx.xx) on Tue 2 Aug 2005 at 15:37
I found that I could shave about 8 seconds off of my 58-second startup time (on a 800MHz Sony Vaio running sarge) by simply pointing the symbolic link /bin/sh to dash rather than bash.

[ Parent | Reply to this comment ]

Posted by Anonymous (151.37.xx.xx) on Tue 13 Sep 2005 at 19:12
Really impressive...
Five seconds of difference on my laptop using this simple tweak! (bootchart shows an improvement from ~45s to ~40s)

Debian Sid on a 1,73GHz centrino laptop

[ Parent | Reply to this comment ]

Posted by Anonymous (81.178.xx.xx) on Mon 8 Aug 2005 at 17:21
I hacked /etc/init.d/rc so that only items of the same S number would execute simultaneously.

[ Parent | Reply to this comment ]

Posted by Anonymous (24.58.xx.xx) on Sat 24 Sep 2005 at 06:46
This hack doesn't seem applicable to the latest init release in Sarge.

[ Parent | Reply to this comment ]

Posted by Anonymous (204.96.xx.xx) on Mon 31 Oct 2005 at 04:05
hello, i was trying this and i did something stupid...to leave what that was aside could someone please e-mail me the original /etc/init.d/rc file
thank you in advance my e-mail is Justin_Kubicek@hotmail.com

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Mon 31 Oct 2005 at 04:06
[ View Steve's Scratchpad | View Weblogs ]

No need - just reinstall it:

apt-get install --reinstall sysv-rc

Steve
--

[ Parent | Reply to this comment ]

Posted by Anonymous (128.97.xx.xx) on Thu 15 Jun 2006 at 03:41
So for the /etc/init.d/rc script in Debian Etch, would you replace:
startup $ACTION $SCRIPTS
with:
startup $ACTION $SCRIPTS &
?

[ Parent | Reply to this comment ]

Posted by peterhoeg (193.163.xx.xx) on Mon 19 Jun 2006 at 07:02

I am not using etch myself, but give it a go. It seems like shutdown sequences also will be done in parallel this way which may or may not be a good thing.

You can modify your script to look like this:

if [ "$ACTION" == "start" ] ; then
  startup start $SCRIPTS &
else
  startup $ACTION $SCRIPTS
fi

Untested but it should work.

[ Parent | Reply to this comment ]

Posted by Anonymous (87.28.xx.xx) on Tue 20 Jun 2006 at 11:01
Using initng instead of init makes my laptop boot in 13/14seconds, most of which spent checking ReiserFS.

[ Parent | Reply to this comment ]

Posted by peterhoeg (193.163.xx.xx) on Tue 20 Jun 2006 at 11:40
There are different ways, yes, but they all require extensive reworking on initscripts. You hack the line I mention in 2 secs and you gain a dramatic increase.

[ Parent | Reply to this comment ]

Posted by kev (200.77.xx.xx) on Fri 14 Jul 2006 at 18:43
i replaced "startup $ACTION $SCRIPTS" with this code in sid:

if [ "$ACTION" == "start" ] ; then
startup start $SCRIPTS &
else
startup $ACTION $SCRIPTS
fi


didn't work. it boots. and really quickly. but what from what i can see most of the boot processes aren't allowed to finsh. for example, routine reiserfs check fail, and X doesn't start up, unable to load the mouse module.

is there similar code that would work for /etc/init.d/rc in sid?

[ Parent | Reply to this comment ]

Posted by peterhoeg (193.163.xx.xx) on Mon 17 Jul 2006 at 08:45
I am not running neither etch nor sid, but I imagine that what is happening is that the single user tasks are run in parallel which would cause the problems you mention as everything is now out of sync.

For sarge, the hack would only parallelize the tasks/services that are run after single user mode (normally runlevel 2).

Send me a mail with your rc file and I will take a look. My address is peter at hoeg dot com.

[ Parent | Reply to this comment ]

Posted by kev (200.77.xx.xx) on Sun 23 Jul 2006 at 16:57
in sid, it seems that its even easier. from /etc/init.d/rc:
# Specify method used to enable concurrent init.d scripts.
# Valid options are 'none', 'shell' and 'startpar'
so in your /etc/init.d/rc just replace:
CONCURRENCY=none
with:
CONCURRENCY=shell
this change reduced boot time on a debian/sid, Pentium III, 600MHz, runninig kernel 2.6.16-2-686 from 245 seconds to 205 seconds. i should note, not sure why, but kernel 2.6.16 boots extremly slow on this machine: 205 seconds isn't exactly fast. but other kernels boot much faster.
thanks for the help peter!

[ Parent | Reply to this comment ]

Posted by pippola (82.54.xx.xx) on Sun 26 Nov 2006 at 14:12
As suggested, I did replace
CONCURRENCY=none
with:
CONCURRENCY=shell
in /etc/init.d/rc : found a dramatic boot time improvement from 1'50" to 1'04" from pressing the power button (thus including bios & grub wait) to the gdm beeping ready, on my laptop dell D800 Pentium 1.60GHz, debian 4.0.
Some of the spared time comes from the system not standing still and waiting for DHCP to provide an address...
Thanks to all for the precious advice! I think this hack should be either included in the standard distribution or advertised more extensively, especially for laptop users.

All the best,
Nick
http://www.mi.infm.it/manini/

[ Parent | Reply to this comment ]

Posted by Anonymous (195.137.xx.xx) on Thu 13 Jul 2006 at 17:56
I'm running etch and my /etc/init.d/rc file does not have a corresponding line . is there a way of doing the same hack with etch/testing?

[ Parent | Reply to this comment ]

Posted by Anonymous (195.137.xx.xx) on Thu 13 Jul 2006 at 18:02
sorry, didn't see the comments above, however these are still unclear to me and apparently untested. Can anyone confirm that they work and tell me which line to edit? thanks

[ Parent | Reply to this comment ]

Posted by Anonymous (80.139.xx.xx) on Wed 27 May 2009 at 21:49
Hi!

Edit /etc/sysctl.conf and add following lines optimizing swappiness and reducing boot a bit more:
vm.swappiness=1
vm.vfs_cache_pressure=50
vm.dirty_ratio=10
vm.dirty_background_ratio=5

Beware, you should have for minimum 512 MB RAM otherwise you should set swappiness to higher values (60 is default with Debian/Mint/PCLinuxOS and simillar distros)!

For those running linux in virtual box the "CONCURRENCY=shell" in /etc/init.d/rc does not work!

Best Regards

Philippe

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 494 votes ~ 5 comments )