Booting Linux in Less Than 40 Seconds
Have you ever dreamt about booting Linux in less than one minute? Now this dream can come true: in less than 40 seconds after pressing the power button, you will have a perfect fully-functional operating system, exactly as you left the last session. Even better than you thought, right? Now you could say: "Crazy boy - I don't believe you!" Well then, check it out for yourself.
Amazing, huh? I bet you want it too. It's very simple, and it's all about one word: hibernate.
The hibernation process writes the contents of RAM into the swap partition before powering off the system. Later the system can be restored to the state it was in when hibernation was invoked, so that programs can continue executing as if nothing happened. As I showed in the video, restoring from hibernation is much faster than a hard reboot.
First of all, you need a swap partition: create it if you don't have one yet. It should be at least as big as your RAM - so if it's too small, increase it. To create a swap partition, you can use applications like parted, fdisk, cfdisk (shell programs), or gparted (a GUI program). Once you have created or modified the swap partition, you have to set and activate it:
# mkswap /dev/devX # swapon /dev/devX
where devX is the swap partition (e.g. hda8, sda1, etc).
Patching the kernel
Now it's time to patch the kernel: this patch will add hibernation functionalities to the system. Download the patch for your kernel version from:
If you can't find a patch for your version, then it's time to update the kernel ;-) . Don't worry about the minor version, by the way: for example, if your kernel version is 22.214.171.124 (as mine is), the closest you'll find is a patch for 126.96.36.199. Don't even think of downgrading your kernel! Download the patch for 188.8.131.52 and apply to 184.108.40.206: it will work just fine.
Once you have downloaded it, apply it:
cd /usr/src/linux-2.6.xx.xx bzcat /path/to/patch | patch -p1
where 2.6.xx.xx is the kernel version to patch. Then configure it and add the hibernation features:
Power management options ---> [*] Power Management support [*] Hibernation (aka 'suspend to disk') <*> Enhanced Hibernation (TuxOnIce) (NEW) ---> <*> File Allocator <*> Swap Allocator <*> Compression support <*> Userspace User Interface support [ ] Allow Keep Image Mode [*] Replace swsusp by default < > Cluster support ---> [*] Checksum pageset2 (25) Default waiting time for emergency boot messages < > Test pageflags
Make sure to have the DMA Engine support enabled: it will really improve the hibernation speed:
Device Drivers ---> DMA Engine support ---> [*] Support for DMA engines
Also enable LZF compression algorithm: it will compress data and make hibernation faster:
Cryptographic API ---> <*> LZF compression algorithm
Now compile and install it as usual.
Updating the bootloader
The next step is modify the boot loader. You have to add "resume=swap:/dev/devX resume2=swap:/dev/devX" (where devX is your swap partition) to the append section. If you have Lilo, modify /etc/lilo.conf as the example:
image = /boot/vmlinuz root = /dev/hda6 label = Slackware append = "fb=no resume=swap:/dev/hda8 resume2=swap:/dev/hda8"
now update the boot sector:
# lilo -v
If you have Grub, modify /boot/grub/menu.lst as below:
title Slackware root (hd0,5) kernel /boot/vmlinuz root=/dev/hda6 fb=no resume=swap:/dev/hda8 resume2=swap:/dev/hda8 ro quiet splash boot
Now it's time to reboot into your new kernel. If everything is fine, during the boot or into the dmesg output you could see lines like these:
TuxOnIce 3.0-rc3, with support for checksumming, usm, compression, swap storage, file storage, userui. TuxOnIce: Normal swapspace found.
If not, check if you have set up the swap partition:
$ free|grep Swap Swap: 497972 115020 382952
If the results are a series of zeroes, you've forgotten to set up the swap space. Create and activate it, then reboot and check again.
Installing the hibernation script
Now you need to install the hibernate script. Download it from:
$ tar -xzvf hibernate-script-x.xx.tar.gz $ cd hibernate-script-x.xx # ./install.sh
Modifying the hibernate files
Once your installation is in place, you need to modify some files. Open and modify /etc/hibernate/hibernate.conf as below:
TryMethod suspend2.conf TryMethod disk.conf TryMethod ram.conf
Open and modify /etc/hibernate/suspend2.conf as below:
UseSuspend2 yes Reboot no EnableEscape yes DefaultConsoleLevel 1 Compressor lzf Encryptor none ImageSizeLimit 0 SuspendDevice swap:/dev/devX PowerdownMethod 5 FullSpeedCPU yes Include common.confwhere devX is your swap partition.
Check the DMA Engine
Check if the DMA Engine is enabled for your hard drive:
# hdparm /dev/hda|grep dma using_dma = 1 (on)
'hda', of course, should be your hard disk device. If you don't see this, enable it:
# hdparm -d1 /dev/hdaAutomate it by adding these lines to your rc.local (/etc/rc.d/rc.local or /etc/rc.local):
# Enabling DMA Engine echo "Enabling DMA Engine on /dev/hda" hdparm -d1 /dev/hda
It's time to freeze!
It's time to try the hibernation process:
# hibernate -n
With the -n option, it will only simulate the hibernation process. If the process succeeds, you can now test the real thing:
For these test runs, though, I'd advise you to use the -r1 option. That won't make the system halt - it'll simply reboot. So:
# hibernate -r1
If hibernation works correctly, the system should come up exactly as you left it the last time. If something doesn't work (e.g. the sound system, or the LAN connection), you should add some modules to /etc/hibernate/blacklisted-modules, for example the audio modules, the graphic card modules and the ethernet card modules:
ipw2100 nvidia snd_maestro3
In this example, you're "black-listing" the NVIDIA graphic driver, the ipw2100 wireless card, and the Maestro audio card.
If you have any other problem, you should visit the project web page:
In conclusion, depending on your CPU and hard drive performance, less than a minute from a powered-down state to a running Linux system is a reasonable expectation. Enjoy!
Born in 1988, Alessandro lives in Bologna, Italy. While a Computer Science student at the Universita' di Bologna, he was the 1st Prize winner in year 2007 of the 4th edition of The Research Language Competition, held by the Italian Research Council. He is Linux-addicted, especially about services and the network world: he created and currently manages Web and Mail services at the-root.org. In the summer of 2005 he worked in a DB software house as developer; in 2006, he taught a Linux OS basics class at his High School. Starting in 2007, he has worked as a consultant in private and business venues.