Randomly the video is frozen and the PC does not respond to anything while the audio continues to play. A reset is necessary.
The problem is related to the default I/O scheduler used by kernels to manage the HDDs and its short timeout default value. I have tried different HDDs with the same result, but the system works fine if I unplug them.
You can see the used scheduler and those available for the current kernel with:
cat /sys/block/sd*/queue/scheduler
On kernel 4.14 and earlier:
The solution is to assign "CFQ" scheduler to the rotational disks. For this you have to create/edit the file:
sudo nano /etc/udev/rules.d/60-ioschedulers.rules
And paste in it:
# set scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"
Then reboot.
* 4.14 is the last kernel that supports "cfq".
On kernel 4.19 and later:
The solution is to assign "BFQ" scheduler to the rotational disks. For this you have to create/edit the file:
sudo nano /etc/udev/rules.d/60-ioschedulers.rules
And paste in it:
# set scheduler for rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
Then reboot.
With BFQ you also have to raise the "timeout_sync" default value from 124ms to 200, e.g. with:
echo '200' | sudo tee /sys/block/sdX/queue/iosched/timeout_sync
* You can try higher values if the problem continues.
But this setting is lost on reboot, so we have to create a script:
sudo nano /usr/bin/hdd-timeout.sh
With the content:
#!/bin/bash
echo '200' | tee /sys/block/sd[a-z]/queue/iosched/timeout_sync
And we make it executable:
sudo chmod +x /usr/bin/hdd-timeout.sh
Now we create a new systemd service for to launch it on every boot:
sudo nano /lib/systemd/system/hdd-timeout.service
With the content:
[Unit]
Description=Tunning BFQ timeout for HDDs.
[Service]
Type=simple
ExecStart=/bin/bash /usr/bin/hdd-timeout.sh
[Install]
WantedBy=multi-user.target
We start up and enable it:
sudo systemctl enable --now hdd-timeout
We can check if it works well by consulting the value of "timeout_sync":
cat /sys/block/sdX/queue/iosched/timeout_sync