Skip to content

Instantly share code, notes, and snippets.

@z-eh
Forked from allenyllee/install_tools.sh
Created March 16, 2021 16:37
Show Gist options
  • Save z-eh/837d403508bd923946d30750f570aa9e to your computer and use it in GitHub Desktop.
Save z-eh/837d403508bd923946d30750f570aa9e to your computer and use it in GitHub Desktop.
mount vhdx in linux
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment