Skip to content

Instantly share code, notes, and snippets.

@gtirloni
Created May 2, 2022 12:44
Show Gist options
  • Save gtirloni/5b62ad835a06da21a6bd11aa78d3f7c4 to your computer and use it in GitHub Desktop.
Save gtirloni/5b62ad835a06da21a6bd11aa78d3f7c4 to your computer and use it in GitHub Desktop.
Windows WSL2 and LUKS

If you have a LUKS-encrypted partition on another disk, it's easy to mount it inside WSL.

List your disks:

> wmic diskdrive list brief

Mount the whole disk inside WSL (using --bare so WSL doesn't attempt to mount it automatically):

> wsl --mount \\.\PHYSICALDRIVE1 --bare

Now inside WSL, check the device name of the mounted disk (something like /dev/sd*):

$ dmesg | tail

Open the LUKS device (it'll prompt for your passphrase):

$ sudo cryptsetup luksOpen /dev/sdd3 my-encrypted-disk

And mount it somewhere:

$ sudo mount /dev/mapper/my-encrypted-disk /somewhere

Avoid mounting on /mnt because that's usually used by WSL itself to mount your C: drive.

@ninbura
Copy link

ninbura commented Aug 23, 2024

I getting the following error when attempting to mount my USB drive:

wsl --mount \\.\PHYSICALDRIVE4 --bare
The system cannot find the drive specified.
Error code: Wsl/Service/AttachDisk/0x8007000f

You haven't run into this? There's some discussion here → microsoft/WSL#9290, but doesn't seem helpful.

@nhooyr
Copy link

nhooyr commented Nov 4, 2024

I'm able to mount and access the encrypted disk within Linux but the mounted folder shows as empty within Windows Explorer. wslview also errors when trying to open a file within the encrypted disk.

@huyz
Copy link

huyz commented Dec 20, 2024

@ghost thanks for the warning. I made sure to back up

@AymaneHrouch
Copy link

@nhooyr did you figure out any way to open the folder withing Windows Explorer?

@torum
Copy link

torum commented May 6, 2025

@nhooyr, @AymaneHrouch looks like /somewhere needs to be under /mnt/wsl/ such as /mnt/wsl/MyExtDisk. I can access the drive using Windows Explorer by accessing \\wsl.localhost\Ubuntu\mnt\wsl\MyExtDisk.
However, the directory under /mnt/wsl/ will be cleared after the reboot, so you'd need to create the directory each time... I'd like to know if there is a better way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment