How to escape spaces of kernel path in .wslconfig file (WSL2)

Sherman 20 Reputation points
2023-06-15T00:42:20.5066667+00:00

To access USB Storage Device on WSL2, I follow the instruction https://github.com/jovton/USB-Storage-on-WSL2/blob/master/README.md . When I create the file ".wslconfig" on my Windows host's "Users\your-user-name" folder, the content is as below

[wsl2]
kernel=C:\\Users\\XXX YY ZZZ\\bzImage
swap=0
localhostForwarding=true

After executing the command "wsl --shutdown" and "wsl", the system displays the following message.

PS C:\WINDOWS\system32> wsl

The operation timed out because a response was not received from the virtual machine or container.

Error code: Wsl/Service/CreateInstance/CreateVm/HCS_E_CONNECTION_TIMEOUT

I modify the content of the file ".wslconfig" as below.

[wsl2]
kernel=C:\Users\XXX YY ZZZ\bzImage
swap=0
localhostForwarding=true

It seems well but there is also a line message shown.

wsl: Invalid escaped character: 'U' in C:\Users\XXX YY ZZZ.wslconfig:2

I'd like to know how to escape spaces of kernel path in .wslconfig file. Thanks!

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,776 questions
0 comments No comments
{count} votes

Accepted answer
  1. Limitless Technology 44,541 Reputation points
    2023-06-15T10:43:05.4433333+00:00

    Hello Sherman,

    Thank you for your question and for reaching out with your question today.

    To specify a path with spaces in the .wslconfig file for WSL2, you need to use double quotes to enclose the path. Here's how you can modify the content of the .wslconfig file correctly:

    
    [wsl2]
    
    kernel="C:\Users\XXX YY ZZZ\bzImage"
    
    swap=0
    
    localhostForwarding=true
    
    

    By enclosing the path in double quotes, you ensure that the entire path with spaces is treated as a single entity and correctly interpreted by the WSL2 configuration.

    Make sure to save the modified .wslconfig file and then restart WSL by running the following commands:

    
    wsl --shutdown
    
    wsl
    
    

    This should load the updated configuration and resolve the error you encountered.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    Best regards.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.