sudo does not change sysfs parameters [duplicate]
Solution 1:
The "echo 300" is executed using sudo, which outputs 300 to stdout in the normal way. Then as your normal user, you are trying to take that output and write to /sys/
Sudo isn't a magic command that elevates privileges for your whole command line. It takes the arguments you passed to it and executes them as a program. Bash (which is running as a normal user) executes 'sudo echo 300' then takes that output and tries to write it to a file. Note that the writing to the file is done by bash which is running as the normal user.
This should work:
sudo bash -c "echo 300 > /sys/block/md0/md/stripe_cache_size"
sudo will execute bash with higher privileges, and then that root bash will execute the whole command.
Solution 2:
You run here only echo with sudo command, but - his input/output/stderr are from regular user.
If you wish to write to file as root user, you can't use > from shell. Instead use for example tee command:
echo 300 |sudo tee /sys/block/md0/md/stripe_cache_size