Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No network if %temp% moved #5437

Closed
gtumanyan opened this issue Jun 18, 2020 · 29 comments
Closed

No network if %temp% moved #5437

gtumanyan opened this issue Jun 18, 2020 · 29 comments

Comments

@gtumanyan
Copy link

Windows build number: 10.0.20150.1000
Your Distribution version: Ubuntu 18.04
Linux version 4.19.121-microsoft-WSL2-standard

Steps to reproduce

New-Item -Path $env:SystemDrive\Temp -ItemType Directory -Force
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "User")
New-ItemProperty -Path HKCU:\Environment -Name TMP -PropertyType ExpandString -Value %SystemDrive%\Temp -Force
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "User")
New-ItemProperty -Path HKCU:\Environment -Name TEMP -PropertyType ExpandString -Value %SystemDrive%\Temp -Force
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Machine")
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TMP -PropertyType ExpandString -Value %SystemDrive%\Temp -Force
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Machine")
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name TEMP -PropertyType ExpandString -Value %SystemDrive%\Temp -Force
[Environment]::SetEnvironmentVariable("TMP", "$env:SystemDrive\Temp", "Process")
[Environment]::SetEnvironmentVariable("TEMP", "$env:SystemDrive\Temp", "Process")
reboot-computer

Expected behavior

ip address show eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:cf:68:53 brd ff:ff:ff:ff:ff:ff
inet 172.27.23.53/20 brd 172.27.31.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fecf:6853/64 scope link
valid_lft forever preferred_lft forever

Actual behavior

ip address show eth0
4: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:15:5d:cf:62:05 brd ff:ff:ff:ff:ff:ff

@therealkenc therealkenc added the needs-investigation likely actionable and/or needs more investigation label Jun 18, 2020
@therealkenc
Copy link
Collaborator

therealkenc commented Jun 18, 2020

Ref #4731 and #5336. Related confirmed repro from #5286:

C:\> wsl.exe --shutdown
C:\> compact /C %temp% /i /Q
C:\> wsl.exe
$ ip address show eth0

@benhillis benhillis self-assigned this Jun 18, 2020
@benhillis
Copy link
Member

Thanks for reporting, looks like if there are issues creating the swap file we skip network initialization too. I've submited a fix to resolve this issue. In the meantime you can work around this by disabling swap file via .wslconfig.

@gtumanyan
Copy link
Author

Symlink to a new user temp location does the trick too.

@LaurentOngaro
Copy link

@gtumanyan
Can you be more precise for your trick: What original temp location do you replace by a symlink ?
thanks

@benhillis
Copy link
Member

benhillis commented Jun 21, 2020

I'd suggest disabling swap in the meantime:

%userprofile%\.wslconfig
[wsl2]
swap=0

@benhillis benhillis added workaround-available and removed needs-investigation likely actionable and/or needs more investigation labels Jun 21, 2020
@LaurentOngaro
Copy link

I've disabled the swap, and the problem has gone

@ericct
Copy link

ericct commented Jul 9, 2020

Disabling the swap is indeed a workaround (same problem in #5286). Nice.

@gtumanyan could you give details on symlinking to a new location? This workaround sounds much better than just disabling swap.

@gtumanyan
Copy link
Author

@gtumanyan could you give details on symlinking to a new location? This workaround sounds much better than just disabling swap.

cd $env:USERPROFILE\AppData\Local
New-Item -ItemType SymbolicLink -Path $env:USERPROFILE\AppData\Local\Temp -Value "YourCurrentTempFolder" -Force

@cyberofficial
Copy link

@gtumanyan could you give details on symlinking to a new location? This workaround sounds much better than just disabling swap.

cd $env:USERPROFILE\AppData\Local
New-Item -ItemType SymbolicLink -Path $env:USERPROFILE\AppData\Local\Temp -Value "YourCurrentTempFolder" -Force

After searching for like 16 hours, this worked for me. I changed my Temporary Directory 2 days ago to a external faster drive.
Thanks for this!

@gtumanyan
Copy link
Author

gtumanyan commented Aug 11, 2020

It's a pity that microsoft still cannot resolve such a trivial but yet critical issue.

@therealkenc
Copy link
Collaborator

/fixed 20185 [might have been '175 or '180 given fixinbound date]

@ghost ghost closed this as completed Aug 11, 2020
@ghost ghost added the fixedininsiderbuilds label Aug 11, 2020
@ghost
Copy link

ghost commented Aug 11, 2020

This bug or feature request originally submitted has been addressed in whole or in part. Related or ongoing bug or feature gaps should be opened as a new issue submission if one does not already exist.

Thank you!

@YorickLane
Copy link

I'd suggest disabling swap in the meantime:

%userprofile%.wslconfig
[wsl2]
swap=0

Thank you very much! it work for me

@K2ouMais
Copy link

This fix seems to fix it for me too, but there is another problem.

I am on a company PC and I dont have admin rights to do anything.

I tried putting swap=0 in the .wslconfig this morning and everything seemed to work again.

Using %temp% on the Explorer would take me to "C:\Temp\1". Now I tried again and WSL2 had again connectivity problems.

Using %temp% on the explorer would take me to "C:\Temp\2"... Seems that swap=0 is not working for me.

After some reboots I was getting "C:\Temp\1" again and my WSL2 had connectivity again.

Is there a way to put wich temp folder I want to use every single time?

@pmarreck
Copy link

pmarreck commented Feb 25, 2021

I had the same issue and was scratching my head for a while on this.

Turns out that I have compression turned on for my whole drive, so I set %temp% and its children to not be compressed, rebooted, and the problem went away.

I presume faster disk access for WSL entailed not going through the Windows file access stack, which might explain this issue, since Linux accessing compressed windows files directly, at a lower level, might not know wtf to do with them? Anyway.

@alexandermorgan
Copy link

I'd suggest disabling swap in the meantime:

%userprofile%.wslconfig
[wsl2]
swap=0

@benhillis could you please spell these commands out more? I'm not very familiar with OS build stuff, so I don't understand where to run them and what exactly to run. Is %userprofile% meant to be a stand-in for C:\Users\username\ ? There isn't a .wslconfig file there to execute. Or is this meant to be a file called .wslconfig where the file contents are the two lines of [wsl2] and swap=0? I know these are rudimentary questions so thanks for your patience.

@therealkenc
Copy link
Collaborator

could you please spell these commands out more?

Documentation here. You need to create C:\Users\username\.wslconfig. A wsl.exe --shutdown (or reboot) is required for changes to take.

@Brandon168
Copy link

Disable compression on your temp folder and subfolders

@jeefuji
Copy link

jeefuji commented May 26, 2021

Hello all, I come to the same conclusion as @Brandon168. The underlying issue is that the WSL2 distro files are compressed. Disabling compression on the swap file (default: %USERPROFILE%\AppData\Local\Temp\swap.vhdx) seems to solve the issue.
My whole image was also totally nuked because of that (vhdx was also compressed for no reason...)

@kaidokert
Copy link

Was dealing with the same stuff, and even though i thought i had disabled all file compression a long while ago ( it's really .. really evil for several reasons, if you do any development at all ) through several methods ( group policy, regedit and whatnot ) i still had to run uncompress on the whole drive just to get rid of remaining stuff. From admin cmd shell: cd \ and compact /u /s /i and then let it boil for a couple hours.

@tanuj-05
Copy link

I'd suggest disabling swap in the meantime:

%userprofile%.wslconfig
[wsl2]
swap=0

This worked for me finally after spending god knows how long trying to fix it. Thank you so much !

@msustik
Copy link

msustik commented Oct 18, 2021

I am a Windows noob. I do not understand where %userprofile%.wslconfig is to be found? Is that an actual file name? Or does % indicate some expansion I should now about?

@benhillis
Copy link
Member

that's an environment variable:

C:\Users\benhill>cmd.exe /c echo %userprofile%
C:\Users\benhill

@freeksegers
Copy link

I started to experience the same issue. I'm surprised to see that this thread was started more than a year ago and I never had the issue before until very recently.
Is this still some sort of defect in WSL2?
The solution is still valid. After disabling the swap, the issue was resolved for me. So thanks for that.

@Wolvverine
Copy link

WSL2 has network, startup and installation issues - solution:

Disable encryption and file compression:
for %TEMP% - the swap file there by default location
Or specify where to save in %USERPROFILE%\.wslconfig and disable there:

[wsl2]
...
swapFile = E:\\Temp\\swap.vhdx
...

Disable encryption and compression on directories with distributions:

%appdatalocal%\Packages\CanonicalGroupLimited.Ubuntu*
%appdatalocal%\Packages\TheDebianProject.DebianGNULinux* 

@abdulazizalmalki-gh
Copy link

Ref #4731 and #5336. Related confirmed repro from #5286:

C:\> wsl.exe --shutdown
C:\> compact /C %temp% /i /Q
C:\> wsl.exe
$ ip address show eth0

Before I do this I was able to ping but not update, NOW I cannot even ping, has this been resolved yet?

@GonziHere
Copy link

for the record, the .wslconfig didn't even exist on my machine, but I've created it and it has worked as stated here.

@Nazosan
Copy link

Nazosan commented Jul 20, 2022

Hello all, I come to the same conclusion as @Brandon168. The underlying issue is that the WSL2 distro files are compressed. Disabling compression on the swap file (default: %USERPROFILE%\AppData\Local\Temp\swap.vhdx) seems to solve the issue. My whole image was also totally nuked because of that (vhdx was also compressed for no reason...)

Oh wow. This was totally my issue. The problem is, my %temp% location is on a small SSD and every blasted program in the world wants to dump files in there (most forget even to remove them) so I use the compressed flag because otherwise it's too easy to run out of space. Disabling compression for %temp% universally is a no-go for me because it will create even more problems. It also shouldn't be necessary.

If it requires the swap.vhdx file it creates to have specific file attributes, it needs to just simply set (or unset in this case) the file flags itself when creating the file as is proper practice instead of just simply breaking in unexpected ways and leaving the user completely confused as to what is going on and having to google around for hours due to misleading results before finally finding a way to manually fix it.

@antonio-petricca
Copy link

On my colleague's PC the issue is still present, despite of the swap file disabling.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests