This commit is contained in:
2026-06-03 01:22:16 +02:00
parent 8aa0d0ff61
commit b3194e66e2
13 changed files with 90 additions and 34 deletions
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
# Description:
# Mount a WSL VHDX file to a specified mount point using guestmount.
#
# Requirements:
# - libguestfs-tools
# - sudo privileges
#
# Memo:
# - set `LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1` to show details when guestmount fails.
# - A common issue is that the VHDX file has logs that needs to be "replayed".
# This can be done using `qemu-img check -r all <VHDX_PATH>`
[ "$(id -u)" -eq 0 ] && {
echo "Do not run this script in sudo mode."
exit 1
}
[ -z "$1" ] && echo "Usage: $0 <VHDX_PATH>" && exit 1
vhdx_path="$1"
[ -z "$2" ] && mount_point="/mnt/wsl" || mount_point="$2"
[ -d "$mount_point" ] || sudo mkdir -p "$mount_point"
username=$(whoami)
sudo chown "$username:$username" "$mount_point"
export LIBGUESTFS_BACKEND=direct
# replay log
# qemu-img check -r all "$VHDX_PATH" || {
# echo "Failed to check VHDX file."
# exit 1
# }
guestmount --add "$vhdx_path" --inspector --ro "$mount_point" || {
echo "Failed to mount VHDX file."
exit 1
}
echo "Successfully mounted $vhdx_path to $mount_point"