2003-03-06 00:08:39

by Brad Parker

[permalink] [raw]
Subject: Kernel Boot Speedup

What are some things I can change/disable/etc. to cut down the boot time
of the kernel (i386) ? I would like to get one to boot in a couple
seconds, tops. Is this possible, and how?




2003-03-06 00:33:49

by Andy Pfiffer

[permalink] [raw]
Subject: Re: Kernel Boot Speedup

On Wed, 2003-03-05 at 16:19, Ro0tSiEgE LKML wrote:
> What are some things I can change/disable/etc. to cut down the boot time
> of the kernel (i386) ? I would like to get one to boot in a couple
> seconds, tops. Is this possible, and how?

To get to that kind of boot-up speed, the best way is to never shutdown.

On a StrongArm platform I worked on, we managed to put the CPU to sleep
and the DRAM controller into self-refresh mode and a few other
housekeeping chores (like checksumming our saved CPU state to be able to
verify it on resumption), and could spring back to life with the press
of a power button in about the same amount of time it took for the
cold-cathode back-light to warm up enough to see the built-in screen.

On a modern laptop, it may be possible, in theory, to accomplish the
same kind of thing. The key is to be able to not lose the contents of
memory. I'm not well versed on current state-of-the-art
power-management on commodity x86 platforms, so your mileage may vary.

If you want cold-start boot on a PC, you'll probably need to completely
skip the BIOS (have a look at LinuxBIOS and/or kexec), skip the probing
of devices on reboot, and drastically shorten (or run later) any
user-mode scripts that are invoked.

On the machines that I have measured (p3-800 and p4-1.7Xeon, a
well-configured kernel, after subtracting out BIOS time and stupid scsi
reprobing, is up and open for business in about 10 seconds after the
LILO handoff. The *system* however, isn't often available for another
30 or 40 seconds, perhaps longer.

Andy


2003-03-06 01:02:30

by Adam Sulmicki

[permalink] [raw]
Subject: Re: Kernel Boot Speedup

> If you want cold-start boot on a PC, you'll probably need to completely
> skip the BIOS (have a look at LinuxBIOS and/or kexec), skip the probing
> of devices on reboot, and drastically shorten (or run later) any
> user-mode scripts that are invoked.
>
> On the machines that I have measured (p3-800 and p4-1.7Xeon, a
> well-configured kernel, after subtracting out BIOS time and stupid scsi
> reprobing, is up and open for business in about 10 seconds after the
> LILO handoff. The *system* however, isn't often available for another
> 30 or 40 seconds, perhaps longer.

Also, when you are using LinuxBIOS then time for the hard disk to spin up
actually becomes significant. And it is of order of several seconds (and
up to 30 seconds according to specs for ATA). To counter this problem you
may want to put kernel and root stuff on Compact Flash and then use
CF<->IDE adapter to use CF as primary boot device. (As side benefit it
allows you to easily get around 256KiB limitation of most eerpom (bios)
sockets on your typical motherboard)

--
Adam Sulmicki
http://www.eax.com The Supreme Headquarters of the 32 bit registers

2003-03-06 09:49:25

by Helge Hafting

[permalink] [raw]
Subject: Re: Kernel Boot Speedup

Ro0tSiEgE LKML wrote:
> What are some things I can change/disable/etc. to cut down the boot time
> of the kernel (i386) ? I would like to get one to boot in a couple
> seconds, tops. Is this possible, and how?

As a first step, compile the kernel yourself.
Include only drivers for stuff you actually have and use, drop
everything else. That should give you a kernel that boots in a
few seconds, unless you have some really slow piece of hardware.

Of course the kernel boot time is only part of what we perceive
as "boot time", i.e. time from power-on till you can use the machine.

A normal pc boot goes like this:
1. The bios does its stuff. No amount of kernel tweaking can help
you with this, because this happens before the kernel is loaded.
You can tweak bios options or get a better bios or motherboard though.
Many bioses are really slow - I'm lucky and have one that gets to the
kernel loading stage so fast that the flat panel screen don't
have time to keep up. (The bios starts briefly with some graphichs
mode, then turns to 80x25 text for compatibility reasons. I don't
get to see that transition unless I pause it at the lilo stage)

2. The bios loads a linux loader, typically lilo. Lilo then loads the
kernel of choice. Lilo may be configured with a keypress timeout of
several seconds - I have shortened that to 0.2 seconds, you may remove
it entirely. You may also want to configure lilo with the compact
option, it loads a little faster that way.

3. The kernel boots. This is what you may shorten by being clever.
Leave out everything you don't need, compile into the kernel
anything needed during boot. (I.e. don't use modules unnecessarily,
they cause extra disk accesses)
You know the kernel boot has started when it print something like
"Linux hh 2.5.63-mm2" or similiar.
The kernel boot has ended when it prints

VFS: Mounted root (ext2 filesystem) readonly.
Freeing unused kernel memory: 320k freed

or something like that. This is usually pretty quick. The machine
isn't ready for use yet though.

4. Various init scripts run - depending a lot on your distribution.
This typically involves lots of disk access and may be slow. You can
trim down the init scripts a lot if you know what you're doing - they're
general-purpose but you may have something more specific in mind.

The easy tip is to uninstall anything that have a boot script but
you don't use. Such as unnecessary servers. This also makes the
machine safer on a network - less stuff to break into.

You may be able to speed the boot scripts up by creating
some _huge_ initrd containing as much of the boot scripts
and related executables as possible. This works because an initrd
is loaded by sequential disk accesses while the boot process use
time-consuming seeking.

If all you care about is to login fast, move the script that
enables login earlier in the boot process. Similiarly, if you
use X, move xdm (or whatever starts X) earlier.
There's no reason to wait for webservers and similar to start
before running X, but thats what distributors usually do,

And if you want to get into X fast - use a lightweight
window manager! Something like icewm, twm or similiar.
You will particularly want to throw away KDE and gnome. (This is
is not as drastic as it sounds, because you can run your
kde/gnome apps under plain icewm just fine.)
KDE alone adds 40 seconds or so to my startup time, more
than everything else taken together. So of course I don't use it.

Unless you have a special machine, most of your startup waiting
will be waiting for the bios, or for disk seeks.
Having 256-512M of RAM helps, because the cache _won't_ run
out during boot. 10000RPM disks helps too. And you definitely
want more than one drive. Having /usr and /var on separate
spindles speeds up the boot because the programs loads
from /usr and tends to use data on /var. Having the root
with /etc on some third spindle is even better, because /etc
is where the programs reads their configuration.
This division will avoid a lot of seeking around as
all your software starts up.

Helge Hafting







2003-03-06 10:28:26

by John Bradford

[permalink] [raw]
Subject: Re: Kernel Boot Speedup

>
> Ro0tSiEgE LKML wrote:
> > What are some things I can change/disable/etc. to cut down the boot time
> > of the kernel (i386) ? I would like to get one to boot in a couple
> > seconds, tops. Is this possible, and how?
>
> As a first step, compile the kernel yourself.
> Include only drivers for stuff you actually have and use, drop
> everything else. That should give you a kernel that boots in a
> few seconds, unless you have some really slow piece of hardware.
>
> Of course the kernel boot time is only part of what we perceive
> as "boot time", i.e. time from power-on till you can use the machine.
>
> A normal pc boot goes like this:
> 1. The bios does its stuff. No amount of kernel tweaking can help
> you with this, because this happens before the kernel is loaded.
> You can tweak bios options or get a better bios or motherboard though.
> Many bioses are really slow - I'm lucky and have one that gets to the
> kernel loading stage so fast that the flat panel screen don't
> have time to keep up. (The bios starts briefly with some graphichs
> mode, then turns to 80x25 text for compatibility reasons. I don't
> get to see that transition unless I pause it at the lilo stage)
>
> 2. The bios loads a linux loader, typically lilo. Lilo then loads the
> kernel of choice. Lilo may be configured with a keypress timeout of
> several seconds - I have shortened that to 0.2 seconds, you may remove
> it entirely. You may also want to configure lilo with the compact
> option, it loads a little faster that way.
>
> 3. The kernel boots. This is what you may shorten by being clever.
> Leave out everything you don't need, compile into the kernel
> anything needed during boot. (I.e. don't use modules unnecessarily,
> they cause extra disk accesses)
> You know the kernel boot has started when it print something like
> "Linux hh 2.5.63-mm2" or similiar.
> The kernel boot has ended when it prints
>
> VFS: Mounted root (ext2 filesystem) readonly.
> Freeing unused kernel memory: 320k freed
>
> or something like that. This is usually pretty quick. The machine
> isn't ready for use yet though.
>
> 4. Various init scripts run - depending a lot on your distribution.
> This typically involves lots of disk access and may be slow. You can
> trim down the init scripts a lot if you know what you're doing - they're
> general-purpose but you may have something more specific in mind.

Agreed - you can save a *lot* of boot time like this - my main box
runs just three init scripts, (I use a BSD-style init script layout,
and the main script calls two others). The main script is 2095 bytes,
and the others are 5144 and 2713 bytes. Most of that is taken up with
comments.

I've booted a 486, 4Mb laptop in to 2.2.13 in around 30 seconds, (from
power on), by cutting the init scripts down to almost nothing.

> And if you want to get into X fast - use a lightweight
> window manager! Something like icewm, twm or similiar.

FVWM2 is good, too.

John.

2003-03-26 09:09:00

by Daniel Phillips

[permalink] [raw]
Subject: Re: Kernel Boot Speedup

On Thu 06 Mar 03 01:19, Ro0tSiEgE LKML wrote:
> What are some things I can change/disable/etc. to cut down the boot time
> of the kernel (i386) ? I would like to get one to boot in a couple
> seconds, tops. Is this possible, and how?

I just noticed this post in an oldish Kernel Traffic. I got the following
timing for booting a uml kernel to an IDE root disk:

time ./linux ubd0=/dev/hda6 init=/sbin/halt >/dev/null
real 0m3.146s
user 0m0.310s
sys 0m0.040s

This includes shutdown, and the IDE disk is only 5400 RPM (1 GHz PIII). UML
isn't initializing any physical devices, which would account for most of the
delay on a native kernel. It doesn't do any decompression either. On the
other hand, there are ways to trim the boot time further, e.g., with run-time
precedence relations to control task start order. As others have mentioned,
the limiting factor is likely to be hard disk spin-up time.

To cut down the bios initialization time, use Linux Bios:

http://www.linuxbios.org/index.html

Claimed fastest boot time is 3 seconds, which sounds like they are talking
about a full kernel boot as opposed to just bios start.

I suppose a cold start time in the one second range is achievable without
major hacking of the kernel, using a flash disk, Linux Bios, and minimal
startup scripts.

Regards,

Daniel