[How to]Setup e4rat: Improves boot time with EXT4!

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Level 1
Level 1
Posts: 2
Joined: Fri Jul 13, 2012 8:00 pm

[How to]Setup e4rat: Improves boot time with EXT4!

Postby Thme » Tue Jul 24, 2012 10:55 pm

Well there have been references here and there about this tool on the mint forums but no tutorials that I've found unless I've not looked hard enough. Either way this is coming from a former Mint user who still advocates mint to people new to linux. I have since switched to Arch Linux but maintain a few friends computers with mint(either LMDE or the Ubuntu variant). I'm going to try and explain thoroughly what this tool is how it works why one would want to use it and who it applies to. If you've already read up on it then you can skip to the Tutorial further down.

So what is E4rat? well it's a utility or, rather, set of utilities that optimize the way data is loaded/cached from a hard drive into ram during the boot process. There are other utilities that work similarly however e4rat targets how this data is loaded in a hardware optimized way as opposed to software optimization. ureadahead attempts something similar to e4rat but makes no attempt to optimize actual disk usage. Note:This does not affect SSD users!
e4rat has 3 utilities and they are intended specifically for use on ext4 partitions. hence e4rat stands for "Ext4 Reduced Access Time".
Here's each utility and it's function...

e4rat-collect: This tool is used to log data on what files are accessed during the first 120 seconds of boot, login and whatever is accessed thereafter until the time is up. It is loaded from the kernel command line(part of grub configurations) during normal boot then generates a log that later used by the next utility to reallocate the data as close to the beginning of the partition as possible. Think of it as "smart defragmenting" for ext4 filesystems because that is exactly what it does. During boot a lot of files are accessed for various activities such as the scripts which deal with daemons, login managers, and other executed services along with their config files and so on. These files are physically scattered out on the hard drive from a fresh install because each one used wasn't copied over necessarily after the other and therefore located in a somewhat hierarchical/chrological manner...

e4rat-realloc: After e4rat-collect has been run once it will generate a the log file @ /var/lib/e4rat/startup.log this filepath is used by e4rat-realloc which MUST be ran in single user mode(AKA runlevel S or runlevel 1) getting to this mode may vary on different distros however they basic steps should be about the same. I'm going to cover how it is done on the ubuntu-based mint releases in this tutorial. For debian it should be nearly the same. e4rat-realloc tries to optimize disk i/o by moving(reallocating) the data collected to the beginning of each partition that is mounted during startup which should be towards the beginning of the disk but may/may not be the case for those who've installed in a dual boot setup on a machine with a current windows ok installation. Either way it will still improve boot performance. This is because all the files needed during startup through login are now physically closer to each other on the disk. This has impact by reducing seek time when that data is needed. In most cases this translates to faster boot times.

e4rat-preload: This final tool is started immediately at boot to do exactly what its name means... Pre-load the data that was reallocated with the previously by scanning the inodes/blocks containing it, then pushing that data directly into ram as page cache. This forces the CPU to crank it's performance up as there's less wait during disk I/o operations since the files needed are already cached by e4rat-preload at the very beginning. The results can be impressive but will vary on different systems and setups. Currently my both of my netbooks boot fast.... Asus 1015pn netbook averaged about 35 to 45 seconds from the grub to startup. After e4rat it boots at just over 16 seconds with all services started and running idle within 2 seconds after my desktop loaded. so the results can be very impressive. That is over a 50% reduction in boot time. my older netbook is about 5 seconds shy of that... Your results may vary on Mint to which i'll offer a few suggestions at the end of the actual tutorial.

So here's the setup....
More than likely you have ureadahead pre-installed so you'll want to remove it first.

Step 1: Open synaptic package manager search for it and mark for complete removal then apply the changes.
or if you wish, a teminal method:

Code: Select all

$sudo dpkg --purge ureadahead ubuntu-minimal

you may also want to check if the right libraries are already installed for e4rat(more than likely they are)

Code: Select all

$sudo apt-get install libblkid1 e2fslibs

Step 2: You can download the latest e4rat.deb package here and install through the software-center, synaptic or gdebi... You can likely just navigate to the folder you saved the e4rat.deb to and either double click or right click to install it...

Step 3:This step is preparation ahead of time so it's easier to remember and perform the next few steps.
You'll need to edit /etc/default/grub. I'm gonna give a brief intro to nano as a text editor but you can open this with gedit or any other editor as long as you open it with root permissions.

Nano method: Inside a teminal run:

Code: Select all

$sudo nano /etc/default/grub

you'll be presented with a bunch grub text options. use the arrows to navigate/scroll your cursor to the line near the top that reads: GRUB_CMDLINE_LINUX_DEFAULT=".....bunch or parameters...etc.."
leave whatever is written in the"..." area and add this line to it at the end:

Code: Select all


It should look something like this(note mine may be the same parameters as those you see in yours):

Code: Select all

GRUB_CMDLINE_LINUX_DEFAULT="quiet init=/sbin/e4rat-preload"
this must be on one line.

Now to save these changes in nano just hold "ctrl" then press "x" it'll prompt near the bottom of the window if you wish to save. Type "y" for yes hit enter and enter again to confirm the file you're writting to is /etc/default/grub....

Now we'll need to update grub with these changes. Run...

Code: Select all

$sudo update-grub

Step 4: Now when you reboot don't let grub begin boot yet! On the first(default) selection hit "e" to bring up the grub editing option. This will present you with more information about this menu entry to which you can make temporary edits/changes before booting. near the bottom lines you should see where the "init=/sbin/e4rat-preload" parameter you added earlier is. If it is not there you likely missed one of the details in the previous steps. Just replace the word "preload" with "collect" so that it reads like so:

Code: Select all


Now boot up normally as you would by pressing "ctrl+x" or F10 and wait 2 minutes before going to Step 5

Note: e4rat-collect will log everything you load so if you wish to speed up loadtimes of certain applications you use a lot go ahead and open them as soon as you get to you're desktop after login. Keep in mind that this will slightly affect the effectiveness of e4rat with boot time while offering faster load times for applications after boot. This is somewhat negligible as it should still improve boot time regardless. The differences will vary based on your setup and hardware. If aiming for lightweight and fast boot time it's recomended to choose you're favorite lightweight DE(Desktop Environment) be it XFCE4, LXDE or something else and boot into it when running e4rat-collect. Taking some suggestions from these posts:http://community.linuxmint.com/tutorial/view/114 and http://forums.linuxmint.com/viewtopic.php?t=89689&f=42 may also improve the effectiveness of e4rat. What you decie to go with on those posts is up to you. Read up on them if unsure what they actually do or whether you'd want the results they offer.

Step 5:After awaiting the alotted 2 minutes you can check to see if the startup log was created with:
$ls /var/lib/e4rat/
and see if it prints "startup.log" showing that it has been generated. If so reboot and choose "recovery mode" from grub and press "e" to edit as before this time replace "init=/sbin/e4rat-preload" if it's present with "single" otherwise add "single to the line where e4rat was located before. You'll be presented with another set of menu style options once started up. Select the drop to root terminal option at the bottom and hit enter. you'll be Prompted for your password. After entering it run:

Code: Select all

#e4rat-realloc /var/lib/e4rat/startup.log

Now wait until you're presented with a '#' prompt again. Once done type "reboot" and you're finished. Grab a stopwatch and time the difference for yourself...

Further advice and hopefully a well layed out video explaining these steps will be uploaded to youtube.(that will be a universal tutorial as I'll try to cover the slight differences in setup.). Further reading and more links will be posted soon so check back here. If you like my first post let me know. There's a few typos grammar errors I'm sure. Some was typed from phone.

Level 1
Level 1
Posts: 11
Joined: Sat Jul 14, 2012 2:54 pm

Re: [How to]Setup e4rat: Improves boot time with EXT4!

Postby BillV » Tue Jul 31, 2012 12:51 pm

Good job!
With LMDE1204 Xfce/Mate/Cinnamon 64bit launched in Xfce mode, Step 1 and 2 weren't required but good info and good to check. I have an Asus M5A88M mobo with AMD_64 FX6100 cpu, 16GB ram. Boots from Grub in 32s when set to auto-login. BIOS is about 25s from cold boot to Grub (unrelated)

Return to “Tutorials”