Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / wslMount.ps1
Last active December 3, 2023 20:13
Attach one or more physical disks to a wsl instance, using encryption and formatting options `wsl --mount` doesn't support
<# calling the wslMount function will attach one or more physical disks to a wsl instance
-drives
This parameter specifies which disks, and is an array of what Windows calls the Friendly Name.
You can see these by calling `Get-PhysicalDisk`.
-count
The list of friendly names are not necessarily unique (eg if you have multiple of the same model of drive).
Count is required so that you know how many disks have been matched, and will be passed to WSL.
-wsl
The name of the wsl install you want to interact with, defaults to the default wsl instance.
-mount
#!/usr/bin/env bash
set -e # Exit on error
if [ "$EUID" -ne 0 ]; then
echo "To ensure correct permissions, this script must be run as root."
exit 1
fi
install_location="/var/lib/safing-portmaster" # Must not include trailing slash