Last active
November 6, 2024 04:12
-
-
Save allenyllee/0a4c02952bf695470860b27369bbb60d to your computer and use it in GitHub Desktop.
mount vhdx in linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# install qemu utils | |
sudo apt install qemu-utils | |
# install nbd client | |
sudo apt install nbd-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VHDX_IMG="$1" | |
MOUNT_POINT="$2" | |
# [ubuntu] How do you mount a VHD image | |
# https://ubuntuforums.org/showthread.php?t=2299701 | |
# | |
# Load the nbd kernel module. | |
sudo rmmod nbd;sudo modprobe nbd max_part=16 | |
# mount block device | |
sudo qemu-nbd -c /dev/nbd0 "$VHDX_IMG" | |
# reload partition table | |
sudo partprobe /dev/nbd0 | |
# mount partition | |
sudo mount -o rw,nouser /dev/nbd0p1 "$MOUNT_POINT" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MOUNT_POINT="$1" | |
#unmount & remove nbd module | |
sudo umount "$MOUNT_POINT" && sudo qemu-nbd -d /dev/nbd0 && sudo rmmod nbd | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On 64-bit Slackware 15.0 I didn't have to specify
max_part=16
(default). Usingqemu-nbd -r
both*.vhd
and*.vhdx
works withoutpartprobe
and I didn't even neednbd-client
from thenbd
package and I didn't have to reload thenbd
kernel module after each try. BTW, I runmodprobe -r nbd
instead ofrmmod nbd
for the final cleanup.