Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I attach a VHDx or VHD file in Linux? [closed]

Tags:

linux

vhd

How can I attach a VHDX or VHD file in Linux?

I mean attach the virtual hard disk as a block device, and use external tools to read these devices.

The filesystem inside is not mountable. I do not need to mount the filesystem, but deal with it as if it was on a real hard disk.

I read the manual page of guestfish, but could not find how to do it.

like image 227
Qin Yuhao Avatar asked Apr 24 '16 05:04

Qin Yuhao


People also ask

How do I permanently attach a VHD?

Steps to Attach A VHD / VHDX Permanently Windows 10, 8, 7In Disk Management, select Action >> Attach VHD. Click Browse and navigate to the location of VHD/ VHDX and select it. Click Open. Finally, click OK.


1 Answers

You can use libguestfs-tools to achieve this.


  1. First, you need to install it, on Ubuntu/Debian-like Linux that would be:

    sudo apt-get install libguestfs-tools 
  2. Then, you can mount almost whatever you wish:

    guestmount --add yourVirtualDisk.vhdx --inspector --ro /mnt/anydirectory 

    This is just an example of read-only extraction point.


Hints:

  1. Run it as normal user, i.e.:

    guestmount ... 

    Instead of:

    sudo guestmount ... 
  2. Switches; citations from man page:

    --add 

    Add a block device or virtual machine image.

    --inspector 

    Using virt-inspector(1) code, inspect the disks looking for an operating system and mount filesystems as they would be mounted on the real virtual machine.

    --ro 

    Add devices and mount everything read-only. Also disallow writes and make the disk appear read-only to FUSE.

like image 137
LinuxSecurityFreak Avatar answered Sep 21 '22 13:09

LinuxSecurityFreak