-
Star
(118)
You must be signed in to star a gist -
Fork
(21)
You must be signed in to fork a gist
-
-
Save allenyllee/0a4c02952bf695470860b27369bbb60d to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # install qemu utils | |
| sudo apt install qemu-utils | |
| # install nbd client | |
| sudo apt install nbd-client |
| #!/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" | |
| #!/bin/bash | |
| MOUNT_POINT="$1" | |
| #unmount & remove nbd module | |
| sudo umount "$MOUNT_POINT" && sudo qemu-nbd -d /dev/nbd0 && sudo rmmod nbd | |
Anyway to resize the image please @allenyllee
On 64-bit Slackware 15.0 I didn't have to specify max_part=16 (default). Using qemu-nbd -r both *.vhd and *.vhdx works without partprobe and I didn't even need nbd-client from the nbd package and I didn't have to reload the nbd kernel module after each try. BTW, I run modprobe -r nbd instead of rmmod nbd for the final cleanup.
Ty! Awesome script 👌
https://github.com/kenkin360/nbd-vhdx
I built a service for this purpose and install on my laptop for daily work. My use case is mounting a Bitlocker partition as the main local storage of Proxmox and connect vhdx images in the storage as NBDs, and then passthrough to VMs as their boot device. Thank to qemu-nbd and cryptosetup, everything works like a charm for years.

Thank you very much! @allenyllee ! Is it also possible with VHDX configured with Bitlocker encryption?