# identify disk
GET-CimInstance -query "SELECT * from Win32_DiskDrive"
# mount disk (DiskPath: \\.\PHYSICALDRIVE*)
wsl --mount <DiskPath> --bare
在 WSL 中:
# 1
sudo apt-get update
sudo apt-get install cryptsetup
# 2 identify partition of interest
lsblk
# 3 Mount the encrypted partition
sudo cryptsetup open /dev/sdXn cryptpart
# 4 create mountpoint and mount
sudo mkdir /mnt/your-mount-point
sudo mount /dev/mapper/cryptpart /mnt/your-mount-point
# 5 check ownership of partition and of logged user
ls -l /mnt/your-mount-point/
id USERNAME
# if they match, proceed to read/modify files
# 7 Unmount
sudo umount /mnt/your-mount-point
sudo cryptsetup close cryptpart
如果拥有已挂载分区的 ID 与已登录的 WSL 用户 ID 不同
# create a user with the id of
# the owner of /mnt/your-mount-point
EXISTING_UID=<id-of-owner-of-files-in-mount-point>
NEWUSER=<your_username> # name can be different from linux system name
useradd --create-home --shell /usr/bin/zsh --user-group --groups \
adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev --uid \
$EXISTING_UID --password $(read -sp Password: pw ; echo $pw | openssl passwd \
-1 -stdin) $NEWUSER
# change default user, for vscode purposes, modify `/etc/wsl.conf`
# adding username when its id is not 1000
[user]
default=username-when-its-id-is-not-1000
对于双启动(在 Linux 系统中)的建议:
lsblk
,因为它们在 WSL 下可能有完全不同的名称,以便稍后识别加密的分区。在 Powershell 中
在 WSL 中:
如果拥有已挂载分区的 ID 与已登录的 WSL 用户 ID 不同