Debian & HyperV just do not mix ! How to mitigate Debian freeze on HyperV

Cat and Dog angryIn these days I’ve found an issue related a guest Debian 7 in Hyper-V vers. 6.3 on Windows 2012 R2.
On a random Basis the file system will be mounted Read-Only due to a disk error: as a result Debian hangs and I need to force a reboot to get the system working again.
I made several configuration changes… I’m not sure they have solved the random issue but it’s been three months now and the problem is no longer happened.
In the next some notes about how I have (partially ?) solved the problem.
1) Upgrade system to latest kernel vers

apt-get update
apt-get upgrade

2) I suppose that the problem was the long latency that linux kernel get when accessing to the virtual HD. I had a backup process that created compressed files on the local (virtual) HD and at the end moved them in other place. To minimize the disk activity I’ve modified the process that save the file directly without using local HD like temp dir.
3) Always to minimize disk activity (see step #2) I’ve set the swappiness to 10. In /etc/sysctl.conf


4) Change dirty_ratio and dirty_backgroud_ratio
By default Linux uses some % of the available RAM for file system caching, and periodically flush all to disk causing a lot of IO.
vm.dirty_background_ratio is the percentage of RAM that can be filled with dirty pages (=memory pages that still need to be written to disk) before the background processes write these pages to disk.
vm.dirty_ratio is the absolute maximum amount of RAM that can be filled with dirty pages before everything must get committed to disk.
In VM enc you can optimiza this value like modifyng /etc/sysctl.conf.


5) Modified driver timeout. In /etc/rc.local I added this line (before exit 0).

echo 180 > /sys/block/sda/device/timeout

6) Force dynamic tick
In /etc/default/grub in parameters of the line GRUB_CMDLINE_LINUX_DEFAULT add nohz=true.


Then do a grup-update.

sudo update-grub

7) Change NOOP I/O schedulers better disk disk performance.
In /etc/default/grub in parameters of the line GRUB_CMDLINE_LINUX_DEFAULT add elevator=noop.

GRUB_CMDLINE_LINUX_DEFAULT="nohz=true elevator=noop quiet"

Then do a grup-update.

sudo update-grub

8) From Debian Backports install hyperv-daemons
In /etc/apt/sources.list add this line

deb wheezy-backports main

Then install hyperv-daemon

apt-get update
apt-get install hyperv-daemons

I hope this post can help someone else.
CentOS & HyperV just do not mix !
Ubuntu 14.04 hangs intermittently under Hyper-V
Best Practices for running Linux on Hyper-V
Supported Debian virtual machines on Hyper-V
Linux Kernel panic issue: How to fix hung_task_timeout_secs and blocked for more than 120 seconds problem