Change I/O scheduler not using sd* to refer to the disk
I'd like to change the I/O scheduler to deadline for one particular disk on my system. All resources I found, however, use methods I can not use because they either refer to the disk using sd* (sda, sdb, etc.) or they are using Grub instead of Grub2.
The reason I can't use labels like sd* to refer to a disk is obvious: it can and will change for a disk. I've looked at UUIDs (/dev/disk/by-uuid) to see if they can offer a solution but alas. Lots of resources found on the internet talk about referencing a drive or disk by using a UUI开发者_运维知识库D, while you can only really reference a partition on a disk this way. It seems to me that referencing to partitions using UUIDs is a welcome change to safely reference partitions but the lack of having something similar for disks as a whole is really a shame.
Any of the following are no option:
In /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline quiet splash"
Would cause the same scheduler to be used for all disks.
In /etc/rc.local
echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch
Is using the sd* labels.
In /etc/sysfs.conf
block/sda/queue/scheduler = deadline
Is using the sd* labels again.
How does one change the I/O scheduler using a safe way to refer to the disk?
I guess there's no easier/cleaner solution then to create a script, as osgx suggested.
In dmesg I did not find anything like a SerialID of the disks so I came up with a different solution which might also be easier for others to apply.
Create a file called setscheduler.sh in /etc/init.d/ and add the following content:
#!/bin/bash
# List of UUIDs (one per line)
# For each drive: Add the UUID of a single partition located on the drive of which you want to change the I/O-scheduler
UUID_LIST=(
2669b09e-75cd-4f45-bedb-8cb405444287
)
DISK_PATH="/dev/disk/by-uuid"
BLOCK_PATH="/sys/block"
for UUID in ${UUID_LIST[@]} ; do
if [[ -L "${DISK_PATH}/${UUID}" ]] ; then
TARGET=$( readlink "${DISK_PATH}/${UUID}" )
DISK=`expr "${TARGET}" : '.*\(sd[a-z]\)'`
if [[ -d "${BLOCK_PATH}/${DISK}" ]] ; then
echo deadline > "${BLOCK_PATH}/${DISK}/queue/scheduler"
echo 1 > "${BLOCK_PATH}/${DISK}/queue/iosched/fifo_batch"
fi
fi
done
Make the file executable:
sudo chmod +x /etc/init.d/setscheduler.sh
Register it as an init.d script:
sudo update-rc.d setscheduler.sh defaults
精彩评论