Mount virtual disk linux

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

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

  • This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
  • This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

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.

1 Answer 1

You can use libguestfs-tools to achieve this.

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

sudo apt-get install libguestfs-tools 
guestmount --add yourVirtualDisk.vhdx --inspector --ro /mnt/anydirectory 

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.

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

When the vhd file is too big (say 1TB with millions of files), guestmount could successfully mount it but fail in reading files (you can’t even ls -1f to see the files). This must be an unsolved bug. Anyone who encounters this problem can try qemu.

And guestmount (with no args at all) just segfaults on me (after newly installed here on a Raspbian Jessie).

Thanks for bringing up guestmount which I hoped would allow me to mount my .vhd containing a single partition with a exFAT-volume inside. Sadly, guestmount (v1.38.4) did not accept my specification of the volume within the .vhd and asking me Did you mean to mount one of these filesystems? . /dev/sda1 (exfat) . What I had specified was -m «/dev/sda1» as this was what virt-filesystems had returned. When the volume is NTFS, mounting works. And yes, I’ve got exfat-utils.x86_64 (v1.2.8, a fuse-fs-driver) installed.

Читайте также:  Installing nagios on linux

Источник

How to mount a virtual hard disk?

Have you searched Google? It abounds with guides on mounting VMDK, VDI, VHD, and raw disk image files on Ubuntu.

4 Answers 4

Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256.

mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint 

For other types of qemu images, you can use qemu-nbd

modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 image.qcow2 partprobe /dev/nbd0 mount /dev/nbd0p1 /mnt/image 

Plus, usually, you can convert image from one format to another.

raw - (default) the raw format is a plain binary image of the disc image, and is very portable. On filesystems that support sparse files, images in this format only use the space actually used by the data recorded in them. cloop - Compressed Loop format, mainly used for reading Knoppix and similar live CD image formats cow - copy-on-write format, supported for historical reasons only and not available to QEMU on Windows qcow - the old QEMU copy-on-write format, supported for historical reasons and superseded by qcow2 qcow2 - QEMU copy-on-write format with a range of special features, including the ability to take multiple snapshots, smaller images on filesystems that don't support sparse files, optional AES encryption, and optional zlib compression vmdk - VMware 3 & 4, or 6 image format, for exchanging images with that product vdi - VirtualBox 1.1 compatible image format, for exchanging images with VirtualBox. 

I found this solution for (VirtualBox) .VDI when I searched, on this website:

modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 /path/to/some.vdi mount -o loop /dev/nbd0p1 /mnt # do stuff umount /mnt qemu-nbd -d /dev/nbd0 rmmod nbd 

The same as «Qemu’s way» commands. No borders!

Источник

How to Mount VirtualBox Disk Image (VDI) to Access VM File-System in Ubuntu

Virtualbox

This tutorial shows how to mount the VirtualBox virtual disk image in Ubuntu, so you can access the Guest OS file system with read and write permission, if it does not boot.

Читайте также:  Linux virtual machines on windows

After misconfigured my VirtualBox Guest OS, it does not longer work. I know how to correct the issue to make it boot again, but firstly accessing to the file system is required!

Since the VBox user manual does not work, here’s what I did in Ubuntu 20.04 host with VirtualBox 6.1.x:

Before getting started, make sure Guest OS is shutdown. And the disk image is not in use. Also UN-MOUNT the disk once the job done.

1.) Firstly open terminal from system application launcher. When it opens, run command:

vboximg-mount is a utility to make VBox disk images available to the host. With —list , it list all Disk Images as well as the UUID.

In the case, I have all Guest OSes on single Disk Image (.vdi). And the uuid is: “3db5fd91-fd56-46af-a2d2-98cd62b05ea3”

2.) Next perform a FUSE mount of the virtual disk image:

    First create a folder as mount point, vbox_sysdisk for instance:

vboximg-mount -i 3db5fd91-fd56-46af-a2d2-98cd62b05ea3 -o allow_root vbox_sysdisk

NOTE: You may need to edit the “/etc/fuse.conf” to make the -o allow_root flag work. To do so, run command sudo gedit /etc/fuse.conf and enable (remove # at its beginning) “user_allow_other” line.

3.) As the previous picture shows, I have 5 disk partitions: vol0, vol1, …, vol4. Now mount either partition (vol4 for instance) to /mnt via command:

sudo mount vbox_sysdis/vol4 /mnt

Finally go to /mnt directory and there you are.

Unmount:

To un-mount the guest os file system, run command:

To un-mount the VBox disk image, run command:

And you may finally remove that folder either from file manager or by running command in terminal:

permalink

Ji m

I’m a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

Источник

Mounting VMDK disk image

I have a single vmware disk image file with vmdk extension I am trying to mount this and explore all of the partitions (including hidden ones). I’ve tried to follow several guides, such as : http://forums.opensuse.org/showthread.php/469942-mounting-virtual-box-machine-images-host I’m able to mount the image using vdfuse

vdfuse -w -f windows.vmdk /mnt/ 
# ll /mnt/ total 41942016 -r-------- 1 te users 21474836480 Feb 28 14:16 EntireDisk -r-------- 1 te users 1569718272 Feb 28 14:16 Partition1 
mount -o loop,ro /mnt/Partition1 mnt2/ 

But that gives me the error ‘mount: you must specify a filesystem type’ In trying to find the correct type I tried

dd if=/mnt/EntireDisk | file - which outputs a ton of information but of note is: /dev/stdin: x86 boot sector; partition 1: . FATs . 
mount: wrong fs type, bad option, bad superblock . etc 

Did you try ntfs? Did you try fdisk /mnt/EntireDisk or gparted /mnt/EntireDisk and looking at the partitions there? Do they show up correctly?

Читайте также:  Vmware tools kali linux установка

fdisk returned: ‘WARNING: GPT detected on ‘. ‘. The util fdisk doesnt support GPT’. gparted is able to show me there are 4 partitions but all fail to initalize. It lists several required packages for ntfs and fat32 that i might need so I’ll install those and see if it gets me anything

Also, you might want to move this question over to serverfault.com, I bet you would get more help there as this isn’t really a software dev or computer science question.

I saw a lot of solution, but finally I use the simple solution: add the VMDK file to an existed linux VM. Boot to that VM and mount the partition normally. You can use GUI tool to mount (such as gnome-disks in gnome) or mount command line

6 Answers 6

For newer Linux systems, you can use guestmount to mount the third partition within a VMDK image:

guestmount -a xyz.vmdk -m /dev/sda3 --ro /mnt/vmdk 

Alternatively, to autodetect and mount an image (less reliable), you can try:

guestmount -a xyz.vmdk -i --ro /mnt/vmdk 

Do note that the flag —ro simply mounts the image as read-only; to mount the image as read-write, just replace it with the flag —rw .

Installation

guestmount is contained in following packages per distro:

  • Ubuntu: libguestfs-tools
  • OpenSuse: guestfs-tools
  • CentOS / Fedora: libguestfs-tools-c

Troubleshooting

error: could not create appliance through libvirt

$ guestmount -a file.vmdk -i --ro /mnt/guest libguestfs: error: could not create appliance through libvirt. Try running qemu directly without libvirt using this environment variable: export LIBGUESTFS_BACKEND=direct Original error from libvirt: Cannot access backing file '/path/to/file.vmdk' of storage file '/tmp/libguestfssF6WKX/overlay1.qcow2' (as uid:107, gid:107): Permission denied [code=38 int1=13] 

Solution: use LIBGUESTFS_BACKEND=direct , as suggested:

LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest 

fusermount: user has no write access to mountpoint

LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest/ fusermount: user has no write access to mountpoint /mnt/guest libguestfs: error: fuse_mount failed: /mnt/guest/, see error messages above 

Solution: use sudo , or change file permissions on the mountpoint

Источник

Оцените статью
Adblock
detector