Feb 1 2013
If you have been performance tuning your Ubuntu rig you may have run across a nifty tool called
e4rat. This tool allows you to optimize the location of files your system accesses during its boot process, and pre-load them in memory in order to speed up boot times. This idea is definitely not new, as there have been similar tools to do this in the past such as
e4rat is a new tool which uses some recent Linux kernel functionality introduced alongside the ext4 filesystem. On the e4rat homepage, the author goes into more detail:
e4rat (“Ext4 – Reducing Access Times”) is a toolset to accelerate the boot process as well as application startups. Through physical file realloction e4rat eliminates both seek times and rotational delays. This leads to a high disk transfer rate.
Placing files on disk in a sequentially ordered way allows to efficiently read-ahead files in parallel to the program startup. The combination of sequentially reading and a high cache hit rate may reduce the boot time by a factor of three, as the example below shows.
e4rat is based on the online defragmentation ioctl EXT4_IOC_MOVE_EXT from the Ext4 filesystem, which was introduced in Linux Kernel 2.6.31. Other filesystem types and/or earlier versions of extended filesystems are not supported.
This tool may be for you if you:
- Use Linux
- Use ext4 filesystem
- Have a non-SSD Hard Drive
- Want to speed up your boot time!
However, there is a rather unfortunate dependency issue that might have bugged some people (including myself). Currently in Ubuntu 12.04
e4rat conflicts with
ureadahead is a part of the
This caused the problem of having to uninstall
ubuntu-minimal if you wanted to use the
e4rat package, potentially opening the door to unexpected problems for your next dist-upgrade. On top of this,
e4rat requires that you modify your init kernel option in grub.cfg, and may not clean itself up when you remove the package. This could potentially leave your system in a non-bootable state if
e4rat is removed until you fix your grub config.
To address this problem and make things safer, I’ve created a PPA containing a rebuilt
ubuntu-minimal package without the
ureadahead dependency. It also includes a rebuilt
e4rat package containing a
postrm cleanup script to remove any
init=e4rat-* kernel options you may have added to your
Here’s what will happen:
- Upon dist-upgrade, this PPA will be disabled in
- The dist-upgrade will continue because this
ubuntu-minimalpackage is still installed
ubuntu-minimalwill be upgraded to the latest version, *with* dependency of
- apt will detect a conflict with
e4rat, and remove it when installing the new
- If you have my
e4ratpackage installed, the
postrmscript will take care of your
/etc/default/grubentry, and re-run
update-grubto update your
- Your system should now reboot fine!
How to install & use e4rat
To install e4rat from my PPA (and avoid potential issues later down the line), follow these simple steps:
Install my PPA, Remove stock
ureadahead & install re-packaged
sudo apt-add-repository ppa:trinitronx/minimal-no-ureadahead sudo dpkg --purge ureadahead ubuntu-minimal sudo apt-get update sudo apt-get install ubuntu-minimal e4rat
Setup e4rat to Optimize Your Boot Time
After you’ve got it installed, you’ll follow the same steps helpfully outlined in this article.
e4rat needs to analyze the files accessed within the first 120 seconds of your system boot process. If you wish to override the default timeout of 120 seconds, you’ll need to edit your
/etc/e4rat.conf before you reboot, and uncomment the line that looks like this:
; timeout 120
And change it to however long in seconds you want. Here’s an example for 4 minutes:
To collect the list of files, you’ll need to reboot and tell grub to run
e4rat-collect first thing (the init process is the first process started when booting). To do this, follow these steps:
- Reboot your system & wait for the GRUB menu to pop up. When it does, highlight your Linux kernel and hit the “e” key to edit the configuration. Search for the kernel line, which varies a bit on everyone’s system, but should look something like this:
linux /boot/vmlinuz-3.2.0-36-generic root=UUID=badcafe0-f00d-babe-feed-facef00d0000 ro quiet splash
init=/sbin/e4rat-collectto the end like so:
linux /boot/vmlinuz-3.2.0-36-generic root=UUID=badcafe0-f00d-babe-feed-facef00d0000 ro quiet splash init=/sbin/e4rat-collect
- Hit Ctrl+X or F10 to continue booting.
e4ratwill collect a list of files accessed within the first 120 seconds (or whatever timeout you chose)
- After 2 minutes (or your timeout) is up, check that /var/lib/d4rat/startup.log exists.
ls -l /var/lib/e4rat/startup.log -rw-r--r-- 1 root root 307549 Nov 26 11:50 /var/lib/e4rat/startup.log
If so, you can proceed. (Feel free to check what files it found too 😉
Note: After rebooting for this step, you may want to follow this helpful tip from LifeHacker:
For the purposes of collecting the right files, act as you normally would when you boot. E.g., if the first thing you do when you boot up your computer is open your browser and mail client, do that after you finish booting here. It’ll move those files too so those programs launch extra quickly. Once your two minutes are up, you can stop “acting”.
Next, reboot your computer again and edit your Grub line as before. This time, add the word
single to the end of the kernel line like so:
linux /boot/vmlinuz-3.2.0-36-generic root=UUID=badcafe0-f00d-babe-feed-facef00d0000 ro quiet splash single
This should reboot you into a terminal. (if you get a blue screen, pick the option to boot as normal) You can log in using your username and password. Once there, execute this command:
sudo e4rat-realloc /var/lib/e4rat/startup.log
Now you just need to set
e4rat-preload to run first thing on boot. This time to make the change persistent, we will edit the
/etc/default/grub config file, and change the
GRUB_CMDLINE_LINUX_DEFAULT boot line. First open your favorite editor (feel free to use
vi instead of
nano if you wish).
sudo nano /etc/default/grub
init=/sbin/e4rat-preload” to the end of the variable like so:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash init=/sbin/e4rat-preload"
Save the file and close it. Then run:
Congratulations, you’re done! On your next reboot, you’ll enjoy a much faster boot time!
DISCLAIMER: Although I have unit-tested the various pieces that will happen during the dist-upgrade process, I do not guarantee that you won’t run into any problems, so if you are in doubt, are paranoid, or are just extremely unlucky please remove
e4rat & check your
If something goes terribly wrong, you’ll probably need to remove the “
init=/sbin/e4rat-preload” grub parameter from your
/etc/default/grub file and run
sudo update-grub manually.
If you are stuck with a kernel panic on booting, just reboot, press ‘
e‘ to edit your grub command line, and remove any ‘
init=/sbin/e4rat-*‘ you see there, then press F10 to boot.