How to retain blockdev changes after server restart?

Michael Rogers asked:

I am setting block device read ahead buffer size like so:

blockdev --setra 8192 /dev/sda

As suggested here.
The problem is after restart it goes back to 256 (default). I need it to retain the value i set it to. How can i do this?
I’m on Ubuntu 16.04 x64.

My answer:


You need to arrange to have the command run at boot time.

In the past, you could do this by placing it in the file /etc/rc.local. You can still do this, if you wish. Just create the file (as it does not exist by default anymore) and it will be run on next boot.


You can also simply create a new systemd oneshot unit which runs your desired command at boot time. For example:

[Unit]
Description=Set readahead for the hard drive device
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/sbin/blockdev --setra 8192 /dev/sda

[Install]
WantedBy=multi-user.target

You might use this latter method if you expect admins of this server to not be familiar with the old rc.local script.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.