Increase drive readahead

You can run: sudo hdparm -Ttv /dev/sda to benchmark your hard drives (changing 'sda' to whichever drive you want to benchmark).

It also prints out some additional data about the drive, notably the readahead, which defaults to 256.

Well, say you want to increase readahead in attempting to improve data throughput?

You can do the following: sudo blockdev --setra 512 /dev/sda (again changing 'sda' to whichever drive's readahead you want to change)

But when you reboot, it's reset back to 256. What to do, what to do...

You can do the following to make the changes permanent (ie: applied on every boot):

Create a file as sudo (the easiest way to do this is to sudo apt install nautilus-admin, then open any file under /etc/init.d/ (right-click, then select "Edit As Administrator"), then save-as that file with a different name (drive-readahead in this case).

Then select all the existing text in that file and delete it, then paste the following in:

	#!/bin/sh
	#
	# Change hard drive readahead from 256 (default) to 512
	
	for drivefound in $(sudo blkid -o device); do
		sudo blockdev --setra 512 $drivefound
	done

Save it to /etc/init.d/ as drive-readahead.

Set the file as executable:
sudo chmod +x /etc/init.d/drive-readahead

Create a sym-link in the proper run level directory:
sudo ln -s /etc/init.d/drive-readahead /etc/rc5.d/S01drive-readahead

Now, when you reboot, it should set drive readahead to 512 from the default 256, for all available drives, no matter how many or how few drives you've got.

Now when you run sudo hdparm -Ttv /dev/sda, it'll show the readahead to be 512 for each drive you test.

This is the first fully-working bash script I've whipped up (aside from some one-line scripts). It's been tested and it works on my setup (HP 17-cp1035cl laptop, ZFS filesystem, Zorin Core 16.2-r1).

In reading the Microsoft best practices for drive readahead, they recommended a script which sets drive read-ahead via a .rules file... but I only want this set if the computer attains run level 5 (ie: the desktop)... so if something goes wrong and you're in a shell because you can't get to the desktop, that's one less thing to contend with as a potential cause of trouble.

[EDIT]
I'd originally set readahead to 2048, but while read speed does increase with that setting, latency also increases and memory caches fill faster. A good middle-ground is 512, you get nearly all the speed increase, with very little of the latency increase. I've corrected the text above accordingly.