You are not logged in.
2 days of tweaking for a faster boot time
Why: just because I can, for other people to see what is possible with (Arch)linux.
Grub to agetty in 13s (coming from 24s)
Before: (after fresh install)
>Bootchart taken offline! 24s boot
After: (2 days of tweaking)
>Bootchart taken offline! 13s boot
Commenting stuff in /etc/inittab
wait -> once
lesser agetty's
no login manager
# /etc/inittab
id:3:initdefault:
rc::sysinit:/etc/rc.sysinit
rs:S1:once:/etc/rc.single
rm:2345:once:/etc/rc.multi
rh:06:once:/etc/rc.shutdown
su:S:once:/sbin/sulogin -p
c1:2345:respawn:/sbin/agetty -8 38400 vc/1 linux
c2:2345:respawn:/sbin/agetty -8 38400 vc/2 linux
#c3:2345:respawn:/sbin/agetty -8 38400 vc/3 linux
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
# End of file
Rough cleaning of /etc/rc.sysinit
Stripping out LVM, RAID, Encrypted
Defaulting hwclock behavior
Fine tuning /etc/rc.sysinit
Adding a lot of ampersands to send stuff to the background
Activate '/sbin/udevadm trigger' earlier
Commenting Module depencies
Including default behavior (LOCALE, KEYMAP, HOSTNAME)
#!/bin/bash
# /etc/rc.sysinit
. /etc/rc.conf
. /etc/rc.d/functions
echo " "
printhl "Arch Linux\n"
printhl "${C_H2}http://www.archlinux.org"
printhl "Copyright 2002-2007 Judd Vinet"
printhl "Copyright 2007-2008 Aaron Griffin"
printhl "Distributed under the GNU General Public License (GPL)"
printsep
# mount /proc, /sys and our RAM /dev
/bin/mount -n -t ramfs none /dev
/bin/mount -n -t proc none /proc
/bin/mount -n -t sysfs none /sys
# Create our default nodes that minilogd may need
/bin/mknod /dev/null c 1 3
/bin/mknod /dev/zero c 1 5
/bin/mknod /dev/console c 5 1
# More initial /dev setup that udev doesn't do
/bin/ln -snf /proc/self/fd /dev/fd
/bin/ln -snf /proc/self/fd/0 /dev/stdin
/bin/ln -snf /proc/self/fd/1 /dev/stdout
/bin/ln -snf /proc/self/fd/2 /dev/stderr
/bin/ln -snf /proc/kcore /dev/core
/bin/mkdir /dev/pts
/bin/mkdir /dev/shm
# start up our mini logger until syslog takes over
/sbin/minilogd
# anything more serious than KERN_WARNING goes to the console
# 'verbose' cmdline parameter enables more messages
if /bin/grep -q " verbose" /proc/cmdline; then
/bin/dmesg -n 8
else
/bin/dmesg -n 3
fi
# enable rtc access
/sbin/modprobe rtc-cmos >/dev/null 2>&1
RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null); RTC_MAJOR="${RTC_MAJOR%% *}"
if [ -n "$RTC_MAJOR" ]; then
/bin/mkdir /dev/misc/
/bin/mknod /dev/misc/rtc0 c $RTC_MAJOR 0
/bin/ln -s /dev/misc/rtc0 /dev/rtc
fi
# Set clock early to fix some bugs with filesystem checks
# Clock is set again later to match rc.conf
if [ -f /etc/localtime ]; then
/sbin/hwclock --hctosys --localtime --directisa --noadjfile
fi
echo > /proc/sys/kernel/hotplug
if [ -x /sbin/udevadm -a -d /sys/block ]; then
# We have udev and /sys appears to be mounted, use UDev
stat_busy "Starting UDev Daemon"
/sbin/udevd --daemon
/sbin/udevadm trigger &
udevstart="$(/bin/date +%s%0N)"
stat_done
else
# Static /dev, our last resort
status "Using static /dev filesystem" true
fi
# Load modules from the MODULES array defined in rc.conf
if ! [ "$load_modules" = "off" ]; then
if [ -f /proc/modules ]; then
stat_busy "Loading Modules"
for mod in "${MODULES[@]}"; do
if [ "$mod" = "${mod#!}" ]; then
/sbin/modprobe $mod &
fi
done
stat_done
fi
if [ -d /proc/acpi ]; then
stat_busy "Loading standard ACPI modules"
ACPI_MODULES="ac battery button fan processor thermal"
k="$(echo $BLACKLIST ${MOD_BLACKLIST[@]} | /bin/sed 's|-|_|g')"
j="$(echo ${MODULES[@]} | /bin/sed 's|-|_|g')"
#add disabled MODULES (!) to blacklist - much requested feature
for m in ${j}; do
[ "$m" != "${m#!}" ] && k="${k} ${m#!}"
done
# add disablemodules= from commandline to blacklist
k="${k} $(echo ${disablemodules} | /bin/sed 's|-|_|g' | /bin/sed 's|,| |g')"
for n in ${ACPI_MODULES}; do
if ! echo ${k} | /bin/grep "\<$n\>" 2>&1 >/dev/null; then
/sbin/modprobe $n > /dev/null 2>&1 &
fi
done
stat_done
fi
fi
# run udev uevents
if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
stat_busy "Loading UDev uevents"
/sbin/udevadm settle &
stat_done
udevend="$(/bin/date +%s%0N)"
printhl " UDev uevent processing time: $((($udevend-$udevstart)/1000000))ms"
fi
# bring up the loopback interface
if [ -d /sys/class/net/lo ]; then
stat_busy "Bringing up loopback interface"
/sbin/ifconfig lo 127.0.0.1 up &
if [ $? -ne 0 ]; then
stat_fail
else
stat_done
fi
fi
status "Mounting Root Read-only" /bin/mount -n -o remount,ro /
FORCEFSCK=
[ -f /forcefsck ] && FORCEFSCK="-- -f"
NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk"
if [ -x /sbin/fsck ]; then
stat_busy "Checking Filesystems"
if /bin/grep -qw quiet /proc/cmdline; then
/sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK >/dev/null 2>&1
else
/sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK 2>/dev/null
fi
fsckret=$?
if [ ${fsckret} -gt 1 ]; then
stat_fail
if [ $((${fsckret}&2)) -eq 2 ]; then
echo
echo "********************** REBOOT REQUIRED *********************"
echo "* *"
echo "* The system will be rebooted automatically in 15 seconds. *"
echo "* *"
echo "************************************************************"
echo
/bin/sleep 15
else
echo
echo "***************** FILESYSTEM CHECK FAILED ****************"
echo "* *"
echo "* Please repair manually and reboot. Note that the root *"
echo "* file system is currently mounted read-only. To remount *"
echo "* it read-write type: mount -n -o remount,rw / *"
echo "* When you exit the maintenance shell the system will *"
echo "* reboot automatically. *"
echo "* *"
echo "************************************************************"
echo
/sbin/sulogin -p
fi
echo "Automatic reboot in progress..."
/bin/umount -a
/bin/mount -n -o remount,ro /
/sbin/reboot -f
exit 0
fi
stat_done
fi
stat_busy "Mounting Local Filesystems"
/bin/mount -n -o remount,rw /
/bin/rm -f /etc/mtab*
# make sure / gets written to /etc/mtab
/bin/mount -o remount,rw /
# Write /proc, /sys and /dev to /etc/mtab
if [ -e /proc/mounts ]; then
/bin/grep -e "/proc " -e "/sys " -e "/dev " /proc/mounts >> /etc/mtab
fi
# now mount all the local filesystems
/bin/mount -a -t $NETFS
stat_done
status "Activating Swap" /sbin/swapon -a &
stat_busy "Configuring System Clock"
if [ ! -f /var/lib/hwclock/adjtime ]; then
echo "0.0 0 0.0" > /var/lib/hwclock/adjtime &
fi
/bin/rm -f /etc/localtime
/bin/cp "/usr/share/zoneinfo/Europe/Brussels" /etc/localtime &
/sbin/hwclock --hctosys --localtime --directisa &
stat_done
if [ -f /var/run/random-seed ]; then
stat_busy "Initializing Random Seed"
/bin/cat /var/run/random-seed >/dev/urandom &
stat_done
fi
stat_busy "Removing Leftover Files"
/bin/rm -f /etc/nologin &>/dev/null
/bin/rm -f /etc/shutdownpid &>/dev/null
/bin/rm -f /var/lock/* &>/dev/null
/bin/rm -rf /tmp/* /tmp/.* &>/dev/null
/bin/rm -f /forcefsck &>/dev/null
(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; )
: > /var/run/utmp
# Keep {x,k,g}dm happy with xorg
/bin/mkdir /tmp/.ICE-unix && /bin/chmod 1777 /tmp/.ICE-unix
/bin/mkdir /tmp/.X11-unix && /bin/chmod 1777 /tmp/.X11-unix
stat_done
#status "Updating Shared Library Links" /sbin/ldconfig
status "Setting Hostname: Pinguin" /bin/hostname "Pinguin" &
#status "Updating Module Dependencies" /sbin/depmod -A &
# Flush old locale settings
: >/etc/profile.d/locale.sh
/bin/chmod 755 /etc/profile.d/locale.sh
# Set user defined locale
[ -z "$LOCALE" ] && LOCALE="en_US"
stat_busy "Setting Locale: en_US"
echo "export LANG=en_US" >>/etc/profile.d/locale.sh
stat_done
stat_busy "Setting Consoles to UTF-8 mode"
# UTF-8 consoles are default since 2.6.24 kernel
# this code is needed not only for older kernels,
# but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8.
for i in $(/usr/bin/seq 0 63); do
usr/bin/kbd_mode -u < /dev/vc/${i}
printf "\e%%G" > /dev/vc/${i}
done
# the $CONSOLE check helps us avoid this when running scripts from cron
echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e%%G"; fi' >>/etc/profile.d/locale.sh
stat_done
status "Loading Keyboard Map: be-latin1" /bin/loadkeys -q -u "be-latin1" &
# Adding persistent network/cdrom generated rules
if [ -f "/dev/.udev/tmp-rules--70-persistent-cd.rules" ]; then
stat_busy "Adding persistent cdrom udev rules"
/bin/cat /dev/.udev/tmp-rules--70-persistent-cd.rules >> /etc/udev/rules.d/70-persistent-cd.rules
stat_done
fi
if [ -f "/dev/.udev/tmp-rules--70-persistent-net.rules" ]; then
stat_busy "Adding persistent network udev rules"
/bin/cat /dev/.udev/tmp-rules--70-persistent-net.rules >> /etc/udev/rules.d/70-persistent-net.rules
stat_done
fi
# Save our dmesg output from this boot
if [ -f /var/log/dmesg.log ]; then
/bin/rm /var/log/dmesg.log
fi
/bin/dmesg > /var/log/dmesg.log &
# End of file
Simplefy /etc/rc.conf
No network stuff needed on boot
Background most deamons
Strip unused variables
# /etc/rc.conf
USECOLOR="yes"
MOD_AUTOLOAD="yes"
MODULES=()
DAEMONS=(syslog-ng @hal @fam @crond @alsa)
Replacing /lib/udev/load-modules.sh
Disables blacklisting, see http://wiki.archlinux.org/index.php/Spe … ng_modules
#! /bin/sh
# /lib/udev/load-modules.sh
/sbin/modprobe $1 &
Cleaning up mkinitcpio.conf
Only sata drivers for my harddrive
# /etc/mkinitcpio.conf
MODULES="ahci"
BINARIES=""
FILES=""
HOOKS="base udev autodetect sata usbinput filesystems"
Fixing /etc/rc.shutdown (because time got lost)
Stripping out LVM, RAID, Encrypted
Defaulting hwclock behavior
#!/bin/bash
# /etc/rc.shutdown
. /etc/rc.conf
. /etc/rc.d/functions
# avoid staircase effect
/bin/stty onlcr
echo " "
printhl "Initiating Shutdown..."
echo " "
# avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
if [ -x /bin/domainname ]; then
/bin/domainname ""
fi
if [ -x /etc/rc.local.shutdown ]; then
/etc/rc.local.shutdown
fi
if [ "$PREVLEVEL" = "3" -o "$PREVLEVEL" = "5" ]; then
# Shutdown daemons
let i=${#DAEMONS[@]}
while [ $i -ge 0 ]; do
if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
fi
let i=i-1
done
# find any leftover daemons and shut them down in reverse order
if [ -d /var/run/daemons ]; then
for daemon in $(/bin/ls -1t /var/run/daemons); do
stop_daemon $daemon
done
fi
fi
# Terminate all processes
stat_busy "Sending SIGTERM To Processes"
/sbin/killall5 -15 &> /dev/null
/bin/sleep 5
stat_done
stat_busy "Sending SIGKILL To Processes"
/sbin/killall5 -9 &> /dev/null
/bin/sleep 1
stat_done
stat_busy "Saving Random Seed"
/bin/dd if=/dev/urandom of=/var/run/random-seed count=1 bs=512 2> /dev/null
stat_done
stat_busy "Saving System Clock"
/bin/rm -f /etc/localtime
/bin/cp "/usr/share/zoneinfo/Europe/Brussels" /etc/localtime
/sbin/hwclock --systohc --localtime --directisa
stat_done
# removing psmouse module to fix some reboot issues on newer laptops
/sbin/modprobe -r psmouse >/dev/null 2>&1
# Write to wtmp file before unmounting
/sbin/halt -w
stat_busy "Deactivating Swap"
/sbin/swapoff -a
stat_done
stat_busy "Unmounting Filesystems"
/bin/umount -a -r -t noramfs,notmpfs,nosysfs,noproc
stat_done
stat_busy "Remounting Root Filesystem Read-only"
/bin/mount -n -o remount,ro /
stat_done
# Power off or reboot
if [ "$RUNLEVEL" = "0" ]; then
printsep
printhl "${C_H2}POWER OFF"
/sbin/poweroff -d -f -h -i
else
printsep
printhl "${C_H2}REBOOTING"
# if kexec is installed and a kernel is loaded, use it
[ -x /sbin/kexec ] && /sbin/kexec -e > /dev/null 2>&1
/sbin/reboot -d -f -i
fi
# End of file
References
http://wiki.archlinux.org/index.php/The … ot_process
http://wiki.archlinux.org/index.php/Fas … the_kernel
http://wiki.archlinux.org/index.php/Udev
http://wiki.archlinux.org/index.php/Speedup_udev
http://wiki.archlinux.org/index.php/Daemons
http://wiki.archlinux.org/index.php/Rc.conf
http://wiki.archlinux.org/index.php/Con … mkinitcpio
http://bbs.archlinux.org/search.php a lot of searching :D
http://kmandla.wordpress.com/howtos/
And others...
Last edited by Duologic (2009-09-01 15:14:45)
Offline
good work. what does changing wait -> once do?
Offline
I'll try anything too speed up boot for my system, and I found that hack here: http://kmandla.wordpress.com/2007/01/28 … n-inittab/
I didn't pay much attention to inittab.
Offline
How do you login?
Offline
Amount of seconds used to achieve faster boot time: 60*60*24*2 = 172800
Amount of seconds saved each boot: 11
Great! Now you just need to boot your computer 15709 times to make up the time
EDIT: Nice writeup, by the way -- I'm sure people will find it useful.
Last edited by fwojciec (2009-01-07 17:14:30)
Offline
Nice, should add it to the wiki
Offline
Amount of seconds used to achieve faster boot time: 60*60*24*2 = 172800
Amount of seconds saved each boot: 11Great! Now you just need to boot your computer 15709 times to make up the time
EDIT: Nice writeup, by the way -- I'm sure people will find it useful.
That's 43 years if you turn on your computer once a day.
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
Zariel: With agetty and I got 'xinit &' in ~/.bash_profile to load X directly. Maybe I will add it to the wiki, but that takes more work than just posting it here.
fwojciec: 15702 times divided by the people who use this to speed up there boot time, and actualy I didn't spend the full two days to do this, just thought it sounded nice (check the dates on the bootcharts).
Last edited by Duologic (2009-01-07 17:27:59)
Offline
fwojciec wrote:Amount of seconds used to achieve faster boot time: 60*60*24*2 = 172800
Amount of seconds saved each boot: 11Great! Now you just need to boot your computer 15709 times to make up the time
EDIT: Nice writeup, by the way -- I'm sure people will find it useful.
That's 43 years if you turn on your computer once a day.
I've said it before, and I'll say it again: time used when you can spare it to save time when you can't isn't wasted, even if you end up using more overall than you actually save.
0 Ok, 0:1
Offline
A great post like this and then without a single 'edit'. Nice job!
Offline
I've got my secrets on doing that
Offline
Nice post! I was doing something similar yesterday . I found that if I take out all the kernel hooks except base in mkinitcpio.conf and just load all the modules I need manually, I can save time. I went down from about 35 seconds to about 15 seconds on a virtual machine.
Offline
That sounds great, I'm planning to do the same in the near future to go below 10 seconds.
In theory if I would have done that in first place and count 20 seconds of my first boot, I'm booting in $-) like 4 seconds.
I gues that's to good to be true...
Offline
It wasn't that alone that brought the boot down 20 seconds. It was almost everything you did plus that.
And a 4 second boot sounds great. i have a laptop and suspend is iffy, unfortunately.
Offline
Cleaning up mkinitcpio.conf
Only sata drivers for my harddrive
# /etc/mkinitcpio.conf MODULES="ahci" BINARIES="" FILES="" HOOKS="base udev autodetect sata usbinput filesystems"
you could also kick some HOOKS:
add to MODULES array
MODULES="ahci <your fst here - eg: ext3>"
(though i think you also need sd-mod - not sure)
and omit sata (you have already ahci so you do not even need sata) and filesystems.
if you do not have an usb keyborard you can also drop usbinput.
then you HOOKS look like:
HOOKS="base udev"
you could also omit udev, but if you use persistent partition naming (which is very useful), you'll need that.
however, the hooks don't take so much time. you'll save perhaps only one second or so.
Last edited by DonVla (2009-01-08 01:41:52)
Offline
Very impressive, I dream of a 13 second boot time.
Offline
Nice! I'll definitely take a closer look at this guide, maybe I'll try it out.
Offline
All of this doesn't help me any since my board takes ~45-60 seconds in BIOS before passing on to GRUB. This board (Intel D5400XS) is the slowest booting board that I've ever had.
Still, keep up the good work.
Offline
All of this doesn't help me any since my board takes ~45-60 seconds in BIOS before passing on to GRUB. This board (Intel D5400XS) is the slowest booting board that I've ever had.
Still, keep up the good work.
Ouuch. That sucks.
Very nice info, OP Thanks.
Offline
iBertus wrote:All of this doesn't help me any since my board takes ~45-60 seconds in BIOS before passing on to GRUB. This board (Intel D5400XS) is the slowest booting board that I've ever had.
Still, keep up the good work.
Ouuch. That sucks.
Very nice info, OP Thanks.
Yeah, I'm happy with the system, but wish the boot performance were better. The worst part is that this machine is an energy whore and so I pretty much have to shutdown when I step away from the computer for any length. I'd feel bad about drawing ~500W from the mains when it can be avoided.
Offline
Duologic wrote:Cleaning up mkinitcpio.conf
Only sata drivers for my harddrive
# /etc/mkinitcpio.conf MODULES="ahci" BINARIES="" FILES="" HOOKS="base udev autodetect sata usbinput filesystems"
you could also kick some HOOKS:
add to MODULES arrayMODULES="ahci <your fst here - eg: ext3>"
(though i think you also need sd-mod - not sure)
and omit sata (you have already ahci so you do not even need sata) and filesystems.
if you do not have an usb keyborard you can also drop usbinput.
then you HOOKS look like:HOOKS="base udev"
you could also omit udev, but if you use persistent partition naming (which is very useful), you'll need that.
however, the hooks don't take so much time. you'll save perhaps only one second or so.
I got as far as this now, can you refer me to some documentation that helps me with non-persistent naming. I would love to try it out, but can't find good documentation.
I did needed the sd-mod, forgot to make a copy of a working kernel image and didn't got further than ramfs$. I got to save my installation with the install USB. ( I'll be writing another topic on that later, think it would be interesting for people that forget to make backups :-D )
Offline
Nevermind, already got it, i have only the base hook now, but boot slowed down by 1 sec now :-s
Offline
I need to do some of this to get my 12 second bootchart lower
Offline
My cold boot to getty is ~30s, that isn't too bad I guess. I added some & to rc.sysinit and moved udev trigger up the rc.sysinit some.
I havn't tried the /lib/udev/load-modules.sh trick yet, nor the inittab 'once'.
Offline
Great write up. Would you mind if I put this in the wiki? Under your name of course.
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline