Backtrack:  
 
by lunarg on June 17th 2015, at 10:34

Linux distros with a 3.x kernel running on virtualized hardware (e.g. pvscsi on VMware) may ever so often spit out the following error:

$ dmesg | grep "WRITE SAME"
kernel: sda2: WRITE SAME failed. Manually zeroing.

This is because the disk driver (in our case: the VMware paravirtual driver) does not support the WRITE SAME SCSI command, resulting in this message.

While this poses no problem for the system at all, you may want to get rid of these messages, which is done by disabling the use of the WRITE SAME command. This can be done through a bit of configuration. Most modern systems have systemd on board which can be used for this, but in case your system doesn't, there's also another (manual) approach (in the background, it's basically the same as what systemd does).

First, determine the list of devices we need to add to our config:

$ find /sys | grep max_write_same_blocks

The output you get depends on the number of disks in your system, but it will look a little bit like this (there are two disks in the system I ran the command on:

/sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0/max_write_same_blocks
/sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/scsi_disk/2:0:1:0/max_write_same_blocks

Reconfigure using systemd (works on Debian 8 "Jessie")

Create a config file (e.g. write_same.conf) and save in it the directory /etc/tmpfiles.d so systemd can pick it up.

Note: the file must end with .conf for systemd to include the file.

For each device, add a line so the file looks like below:

# Type Path        Mode UID  GID  Age Argument
w /sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0/max_write_same_blocks  -   -   -   -  0
w /sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/scsi_disk/2:0:1:0/max_write_same_blocks  -   -   -   -  0

Add the lines exactly as they appear here. Replace only the complete device path with the ones you got from the first command in this post. The very first line is a commented line, and is not required to be added to the file (I added it for readability).

Reboot the system. If you've done things correctly, you will no longer see WRITE SAME errors appearing in the kernel message log.

Reconfigure without systemd

If you system does not support the method above (i.e. it does not use systemd), you can also reconfigure to suppress the messages in another way.

For each device path you got from the first command, "set" it to zero:

echo 0 > /sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0/max_write_same_blocks
echo 0 > /sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/scsi_disk/2:0:1:0/max_write_same_blocks

This will do the same as with systemd, but now only manually. You can add these lines to a startup script so they get executed after a reboot. (Where to put it depends greatly on your distro. Check the documentation for your distro. For Debian, this would mean adding the lines to the file /etc/rc.local.)

Note that unlike the systemd method, this is effective immediately (does not require a reboot).

Technical explanation

The WRITE SAME SCSI command is not supported by the hardware (i.e. the disk) you're using. Most modern physical disks do support this command, but when running virtual, using paravirtualized hardware, this command (along with several others) are not supported, resulting in the error you see appearing in the kernel message log.

By setting the maximum blocks the WRITE SAME command can operate on to zero, the command will not be used, preventing the error messages from appearing (the command never gets executed so there's no error to log).

 
 
« March 2024»
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31      
 
Links
 
Quote
« If the batteries of a TV remote run out, why do we press the buttons so much harder? »