Get rid of freeze-ups during disk I/O activity in Ubuntu


If you are using Ubuntu(or it’s variants), and your computer locks/freezes up or becomes unusable during copying files or heavy disk activity, this post is for you.

Ubuntu currently employs the kernel default I/O scheduler, CFQ or Completely Fair Queuing. It has been known to cause lags and lock-ups during heavy disk activity like copying/moving or backing up data, and one (still-active) bugs report demands the use of an alternative I/O scheduler by default in future Ubuntu releases.

Personally, my computer became virtually unusable during moving/copying files and it has been completely eradicated by the use of an alternative scheduler, Deadline. I’ll be using it for the examples here. Other alternative I/O schedulers include :

  • noop
  • anticipatory

At first, you need to check whether you really benefit from the use of an alternative i/o scheduler. To do this, run this from the console :

echo "deadline" | sudo tee /sys/block/sda/queue/scheduler

Now copy a large file to/from your hard drive. If the lock-ups vanish, this has worked for you. Now, we need to make this permanent for your system. To do this, you need to know which version of Ubuntu you are using. If you are using Ubuntu 9.10 (Karmic Koala) or higher, you will be using Grub2, else you’ll be using Grub Legacy. I have got instructions for both.

For Grub2 :

gksudo gedit /etc/default/grub

For Kubuntu and Xubuntu, you will need to use kdesu kate and gksudo mousepad in place of gksudo gedit respectively.

Find :

GRUB_CMDLINE_LINUX_DEFAULT=""

Add elevator=deadline before the end of the closing double-quotes. For me, after the edit, that line looked like this :

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=deadline"

After you are done, save and close the file. Now run “update-grub” from the terminal.

sudo update-grub

You’ll get something like this :

Generating grub.cfg ...<br /> Found linux image: /boot/vmlinuz-2.6.31-20-generic<br /> Found initrd image: /boot/initrd.img-2.6.31-20-generic<br /> Found memtest86+ image: /boot/memtest86+.bin<br /> done

It means grub.cfg has been rebuilt successfully. You are now good to go.

For legacy Grub :

gksudo gedit /boot/grub/menu.lst

For Kubuntu and Xubuntu, you will need to use kdesu kate and gksudo mousepad in place of gksudo gedit respectively.

Find the kernel line for your current kernel. It will be something like :

kernel /boot/vmlinuz-2.6.12-10-386 root=/dev/hda2 ro quiet splash

It will differ according to the kernel version and the logical drive to which Ubuntu is installed. Now add elevator=deadline to it. After the edit, it should look like this :

kernel /boot/vmlinuz-2.6.12-10-386 root=/dev/hda2 ro quiet splash elevator=deadline

Reboot your system and you are good to go.