You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement tmpfs file system for /tmp that writes to volatile memory instead of persisting to disk #6999
Is your feature request related to a problem? Please describe.
I'd love to be able to use /tmp like I would on linux machines, as a tmpfs file system. At the moment the tmpfs file system on WSL 2 is actually implemented by mapping it to disk instead of writing to RAM. This results in files not being cleaned with restarts (e.g. wsl --shutdown) that accumulate over time. Furthermore, this can result in performance issues with code that relies on temp files since they will be actually written to disk.
Describe the solution you'd like
Implement the tmpfs by writing to volatile memory
Describe alternatives you've considered
At least autoclean /tmp in the meantime at the startup of the distro instead of relying on the user to do it.
Reacted by Brad Krane, Lasath Fernando, Erica S. Kane, nonylene, Faiz Ilham, Arad Alvand, Ltrlg, Artur Gordashnikov, Tim Schwenke, Matheus Lozano and 18 more
changed the title [-]Implement true tmpfs file system for /tmp instead of persisting to disk[/-][+]Implement tmpfs file system for /tmp that writes to volatile memory instead of persisting to disk[/+]on May 27, 2021
like I would on linux machines, as a tmpfs file system
Label "feature" loophole, but /tmp is not a tmpfs on Real Linux either (on Debian derived distros, anyway). This is for all intents by-design/linux-behavior. If you want /tmp to be tmpfs, you can mount a tmpfs at /tmp. Test for the tmpfs mount in .bashrc, and if it isn't there, mount it.
At least autoclean /tmp in the meantime
That much is dupe #1278 ➡️ #344 (➡️ #994). Fire up cron or just call your tmp cleaning script directly from .bashrc.
Reacted by Blue, Chris Coutinho and Antonio Ossa-Guerra
It's simple. Open a terminal, then put a file into the /tmp drive, even with something as simple as touch /tmp/test then launch another, create another file, and see that neither has the others file.
There are a number of other ways to confirm, and that could be specific to WSL1 - I'm unfortunately stuck on WSL1 due to using features unavailable on WSL2.
Indeed you can use either systemd or fstab to use a tmpfs for /tmp. Closing since this is user-configurable
Note that currently (WSL 2.2.4.0, and since 2.0.12.0), doing so will break GUI applications, because the new tmpfs mount will hide the /tmp/.X11-unix that WSL creates at startup (microsoft/wslg#1156).
Indeed you can use either systemd or fstab to use a tmpfs for /tmp. Closing since this is user-configurable
Note that currently (WSL 2.2.4.0, and since 2.0.12.0), doing so will break GUI applications, because the new tmpfs mount will hide the /tmp/.X11-unix that WSL creates at startup (microsoft/wslg#1156).
Nahor In the interest of saving others from this unfortunate bad default behaviour who find this GH issue, an easy manual fix is to create /etc/tmpfiles.d/wslg.conf as root with the following contents:
# This file is part of the debianisation of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See tmpfiles.d(5) for details
# Type Path Mode UID GID Age Argument
L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
and then wsl --shutdown and start it again to see the effect.
This results in the symlink being created, and it happens after tmpfs is mounted by systemd.
Reacted by Nahor, wang1zhen, prajwal yashasvi, eZio Pan, Smith1970, Mateusz Mikuła, biggestsonicfan, Pedro Magalhães, Jake Moss and Tariya
Reacted by Nahor, Arin Abdulmajeed, Smith1970, Martin Kock-Faltin and SoonHyouk
Indeed you can use either systemd or fstab to use a tmpfs for /tmp. Closing since this is user-configurable
Note that currently (WSL 2.2.4.0, and since 2.0.12.0), doing so will break GUI applications, because the new tmpfs mount will hide the /tmp/.X11-unix that WSL creates at startup (microsoft/wslg#1156).
Nahor In the interest of saving others from this unfortunate bad default behaviour who find this GH issue, an easy manual fix is to create /etc/tmpfiles.d/wslg.conf as root with the following contents:
# This file is part of the debianisation of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See tmpfiles.d(5) for details
# Type Path Mode UID GID Age Argument
L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
and then wsl --shutdown and start it again to see the effect.
This results in the symlink being created, and it happens after tmpfs is mounted by systemd.
Thanks so much for the snippets. Maybe off-topic, but should this be included in the distribution provided by Microsoft Store for future fix?
Alan Fregtman (@darkvertex) Wonderful tip, thank you! I find it a bit odd that with systemd the /etc/wsl.confautmount setting isn't honored by the wslg mounting, but this worked a treat.
Does this mean that tmpfs has a real implementation now (actually in RAM)? I'm aware the implementation was simply faked as of 2017, but I would appreciate proper confirmation regarding any changes.
Activity
[-]Implement true tmpfs file system for /tmp instead of persisting to disk[/-][+]Implement tmpfs file system for /tmp that writes to volatile memory instead of persisting to disk[/+]therealkenc commentedon May 27, 2021
Label "feature" loophole, but
/tmpis not atmpfson Real Linux either (on Debian derived distros, anyway). This is for all intents by-design/linux-behavior. If you want/tmpto betmpfs, you can mount atmpfsat/tmp. Test for thetmpfsmount in.bashrc, and if it isn't there, mount it.That much is dupe #1278 ➡️ #344 (➡️ #994). Fire up
cronor just call your tmp cleaning script directly from.bashrc.xploSEoF commentedon Jun 14, 2021
As almost all linux machine hardening guides suggest, the
/tmpdrive should always be mounted astmpfswith a few additional settings.As per the recommendations here, doing this directly in the .bashrc isn't ideal but works:
I've also added this answer to the only stack overflow question I can find on the matter: https://superuser.com/questions/1170939/simulate-reboot-to-clear-tmp-on-the-windows-linux-subsystem/1656653#1656653
massimosala commentedon Aug 26, 2021
/etc/fstab ... this seems to be creating a new /tmp mount for each bash terminal
Liam Le Brun (@xploSEoF) Liam could you please write how to test it?
Update auto.md
mati865 commentedon Nov 15, 2022
Since addition of Systemd this can be easily enabled using instruction from this post https://askubuntu.com/a/1416156/588206:
xploSEoF commentedon Nov 21, 2022
Wow, late reply, sorry.
It's simple. Open a terminal, then put a file into the /tmp drive, even with something as simple as
touch /tmp/testthen launch another, create another file, and see that neither has the others file.There are a number of other ways to confirm, and that could be specific to WSL1 - I'm unfortunately stuck on WSL1 due to using features unavailable on WSL2.
OneBlue commentedon Jun 4, 2024
Indeed you can use either systemd or fstab to use a tmpfs for /tmp. Closing since this is user-configurable.
Nahor commentedon Jun 23, 2024
Note that currently (WSL 2.2.4.0, and since 2.0.12.0), doing so will break GUI applications, because the new
tmpfsmount will hide the/tmp/.X11-unixthat WSL creates at startup (microsoft/wslg#1156).darkvertex commentedon Aug 21, 2024
Nahor In the interest of saving others from this unfortunate bad default behaviour who find this GH issue, an easy manual fix is to create
/etc/tmpfiles.d/wslg.confas root with the following contents:and then
wsl --shutdownand start it again to see the effect.This results in the symlink being created, and it happens after tmpfs is mounted by systemd.
wang1zhen commentedon Aug 22, 2024
Thanks so much for the snippets. Maybe off-topic, but should this be included in the distribution provided by Microsoft Store for future fix?
py563 commentedon Sep 30, 2024
thanks, this works.
biggestsonicfan commentedon Jan 1, 2025
Alan Fregtman (@darkvertex) Wonderful tip, thank you! I find it a bit odd that with systemd the
/etc/wsl.confautmountsetting isn't honored by the wslg mounting, but this worked a treat.koyae commentedon Jan 28, 2025
Does this mean that tmpfs has a real implementation now (actually in RAM)? I'm aware the implementation was simply faked as of 2017, but I would appreciate proper confirmation regarding any changes.