Forget about rc.local
.
You're using CentOS 7. You have systemd. /etc/rc.local
is a double backwards compatibility mechanism in systemd, because it is a backwards compatibility mechanism for a mechanism that was itself a compatibility mechanism in System 5 rc
. And as shown by the mess in the AskUbuntu question hyperlinked below, using /etc/rc.local
can go horribly wrong. So make a proper systemd service unit.
First, create a template service unit. For the sake of example, let's call it /etc/systemd/system/[email protected]
:
[Unit]
Documentation=https://unix.stackexchange.com/questions/247436/
Description=Set custom read-ahead on storage device %I
BindsTo=dev-%i.device
[Service]
Type=oneshot
ExecStart=/sbin/blockdev --setra 128 /dev/%I
Arrange for that service unit to be started by the plug-and-play device manager (udev) when the appropriate devices arrive. Your rule, which you'll have to tailor to your specific needs, will look something like:
SUBSYSTEM=="block", ACTION=="add|change", KERNEL=="sd[a-z]", ENV{SYSTEMD_WANTS}="custom-readahead@%k"
The SYSTEMD_WANTS
setting causes udev to start the named service — an instantiation of the template against the device %k
. This service then runs blockdev
.
There is apparently another way of doing this, which relies on udev's ability to set these settings directly. For this, you don't need the systemd template unit or instantiated services. Instead, simply instruct udev directly in its rule:
SUBSYSTEM=="block", ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{bdi/read_ahead_kb}="128"
Notice the difference between ==
and =
.
There is no rc.local
involved anywhere, either way.
Further reading
rc.local
file?