Skip to content

Instantly share code, notes, and snippets.

@scusi
Forked from allenyllee/install_tools.sh
Last active December 30, 2021 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scusi/86cc5ba5dfbb694d7ccf675d735541b7 to your computer and use it in GitHub Desktop.
Save scusi/86cc5ba5dfbb694d7ccf675d735541b7 to your computer and use it in GitHub Desktop.
mount vhdx in linux
#!/bin/bash
#
# this shell script will install nbd-client package on desinfect
#
cd ~/Downloads
echo "[*] download nbd-client package for AMD64 architecture"
wget -O -J http://de.archive.ubuntu.com/ubuntu/pool/universe/n/nbd/nbd-client_3.20-1_amd64.deb
echo "[*] install nbd-client package"
sudo dpkg -i nbd-client_3.20-1_amd64.deb
echo "[*] delete downloaded package file"
rm nbd-client_3.20-1_amd64.deb
cd
#!/bin/bash
#
# use this script to install requirements in a native debian based linux.
#
# install qemu utils
sudo apt install qemu-utils
# install nbd client
sudo apt install nbd-client
#!/bin/bash
#
# This script takes two arguments:
# SYNTAX: mount_vhdx.sh <path/to/vhdx_image.vhdx> </path/to/mountpoint>
#
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
#
# This script takes one argument, which is the mountpoint where the VHDX image was mounted.
# Note: this is the second argument used when executing mount_vhdx.sh
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