[SOLVED] How to disable linux virtual hard disk cache
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
'd like to disable write cache for a virtual hard drive on linux. Is it possible ?
Actually, I'd like to use the same virtual hard disk mounted within 2 different WSL instances running at the same time, and in such a way that this virtual hard disk is synced between both WSL instances. Up to now, I can mount the same virtual hard disk and access it with 2 different WSL instances, but modifications to this virtual hard disk are not synced between the different WSL instances. To sync modifications from the other WSL instance, I have to umount and remount the virtual hard disk.
I've tried echo 1 | sudo tee /proc/sys/vm/drop_caches;
and also sudo hdparm -W 0 /mnt/d/VHD_home.img ( VHD_home.img is the mounted VHD ), but neither trick works.
Sharing a VHD between guests (as WLS2 instances are) would be a function of the virtualizing hipervisor. That would be Windows. Unless it is specifically supported, it ain't.
The fact that drop_caches has no effect proves it ain't a Linux problem.
Personally it sounds like crazy talk, but I've never seen the need to use WSL for anything other than CLI bits and pieces.
And you would never want to disable the cache anyway, because your computer would instantly turn into a slow pig that's shaking the spindles off the drives, beating them to death.
Finally googling, I've found the solution to my problem that was to find a way to share a directory between several different running linux distributions using WSL.
It is actually possible using mount bind to a directory within /mnt/wsl, such directories are accessible to any distribution without concurrent access trouble.
From the distribution containing the directory, let's say /home/user:
mkdir /mnt/wsl/user
sudo mount -o bind /home/user /mnt/wsl/user
From another distribution, to access /home/user from the first distribution and mount it on /home/user, for instance, it's then just sufficient to do:
mount -o bind /mnt/wsl/user /home/user
This way, in both distribution /home/user represents the same directory and files and it's as quick as with other linux filesystem on wsl, thus far quicker than 9P.
Using .profile, it's possible to do that each time both distributions are launched, provided the first one is launched first in order that /mnt/wsl/user is bind mounted before the other distributions are run.
As to the question of the need or interest to share home directory between several distribution, it seems obvious to me: you can test different distribution without needing to backup and reinstall all your data. Why test new distribution ? To get newer versions of packages for instance, stay up to date and skip buggy distribution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.