Linux hdd to vmdk

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!

Источник

Overview

vmdk ’s, the underlying filesystem commonly used in vmware , can be mounted on a Linux server using the qemu utilities. In this example, I downloaded an ova , unarchived it, and retrieved the vmdk files. Once exposed, I am able to mount the filesystems embedded within the vmdk .

In this example, the ova is a virtual “appliance” which prohibits access a low level root shell. By mounting the vmdk file system directly, we can take a peek at the hidden secrets the vendor keeps under lock and key.

Details

sudo apt install qemu-utils 

Load the network block device module:

jemurray@home-server:~/ib$ sudo modprobe nbd 

Create the network block devices from the vmdk image:

jemurray@home-server:~/ib$ sudo qemu-nbd -r -c /dev/nbd1 ./vnios-disk.vmdk 

Examine the images qemu created:

jemurray@home-server:~/ib$ ls -al /dev/nbd1p* brw-rw---- 1 root disk 43, 33 Jan 9 14:28 /dev/nbd1p1 brw-rw---- 1 root disk 43, 34 Jan 9 14:28 /dev/nbd1p2 brw-rw---- 1 root disk 43, 35 Jan 9 14:28 /dev/nbd1p3 brw-rw---- 1 root disk 43, 36 Jan 9 14:28 /dev/nbd1p4 brw-rw---- 1 root disk 43, 37 Jan 9 14:28 /dev/nbd1p5 brw-rw---- 1 root disk 43, 38 Jan 9 14:28 /dev/nbd1p6 brw-rw---- 1 root disk 43, 39 Jan 9 14:28 /dev/nbd1p7 

Create mount points for the new filesystems:

jemurray@home-server:~/ib$ mkdir p1 jemurray@home-server:~/ib$ mkdir p2 jemurray@home-server:~/ib$ mkdir p3 jemurray@home-server:~/ib$ mkdir p4 jemurray@home-server:~/ib$ mkdir p5 jemurray@home-server:~/ib$ mkdir p6 jemurray@home-server:~/ib$ mkdir p7 

Attempt to mount each individual directory:

jemurray@home-server:~/ib$ sudo mount /dev/nbd1p1 ./p1 mount: /home/jemurray/ib/p1: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p2 ./p2 mount: /home/jemurray/ib/p2: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p3 ./p3 NTFS signature is missing. Failed to mount '/dev/nbd1p3': Invalid argument The device '/dev/nbd1p3' doesn't seem to have a valid NTFS. Maybe the wrong device is used? Or the whole disk instead of a partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around? jemurray@home-server:~/ib$ sudo mount /dev/nbd1p4 ./p4 mount: /home/jemurray/ib/p4: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p5 ./p5 mount: /home/jemurray/ib/p5: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p6 ./p6 mount: /home/jemurray/ib/p6: WARNING: device write-protected, mounted read-only. jemurray@home-server:~/ib$ sudo mount /dev/nbd1p7 ./p7 mount: /home/jemurray/ib/p7: unknown filesystem type 'swap'. 
jemurray@home-server:~/ib/p1$ ls -al total 104 drwxr-xr-x 23 root root 4096 Oct 8 12:42 . drwxrwxr-x 9 jemurray jemurray 4096 Jan 9 14:31 .. drwxr-xr-x 2 root root 4096 Oct 8 12:41 bin drwxr-xr-x 4 root root 4096 Oct 8 12:42 boot drwxr-xr-x 4 root root 4096 Oct 8 12:41 dev drwxr-xr-x 29 root root 4096 Oct 8 12:42 etc drwxr-xr-x 2 root root 4096 Oct 8 12:41 home drwxr-xr-x 7 root root 4096 Oct 8 12:42 lib drwx------ 2 root root 16384 Oct 8 12:58 lost+found drwxr-xr-x 5 root root 4096 Oct 8 12:41 media drwxr-xr-x 2 root root 4096 Oct 8 12:41 mnt 

Источник

Читайте также:  Linux oracle настроить сетевой интерфейс

Как смонтировать виртуальный жесткий диск?

Можно ли смонтировать виртуальный жесткий диск (VHD, HDD, VDI, VMDK) в Ubuntu? Как это может быть сделано?

4 ответа

Linux и другие Unix-подобные хосты могут монтировать образы, созданные в необработанном формате, с помощью устройства обратной связи. Из имени пользователя root (или с помощью sudo) смонтируйте петлю со смещением 32 256.

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

Для других типов изображений qemu вы можете использовать qemu-nbd

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

Плюс, как правило, вы можете конвертировать изображения из одного формата в другой.

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. 

Попробуйте Google, я нашел решение для (VirtualBox) .VDI в одну секунду:

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 

Так же, как команды «Qemu’s way». Нет границ!

Читайте также:  Linux для офисного сервера

Это на Ubuntu 16.04.

Как корень:

Установите и смонтируйте используя affuse.

apt-get install afflib-tools affuse /path/file.vmdk /mnt/vmdk 

Проверьте размер сектора

fdisk -l /mnt/vmdk/file.vmdk.raw # example Disk file.vmdk.raw: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x000da525 Device Boot Start End Sectors Size Id Type /mnt/vmdk/file.vmdk.raw1 * 2048 41943039 41940992 20G 83 Linux 

Умножьте сектор и начальный сектор. В примере это будет 2048*512

Смонтировать, используя это смещение

mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk 

Теперь диск должен быть смонтирован и доступен для чтения в /mnt/vmdisk

Вы также можете использовать qemu:

За .vdi

sudo modprobe nbd sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi 

если они не установлены, вы можете установить их (в Ubuntu эта команда)

sudo apt install qemu-utils 

За .vmdk

sudo modprobe nbd sudo qemu-nbd -r -c /dev/nbd1 ./linux_box/VM/image.vmdk 

обратите внимание, что я использую опцию -r это потому, что VMDK версии 3 должен быть доступен только для чтения, чтобы его можно было смонтировать с помощью qemu

я использую nbd1 так как nbd0 иногда выдает ‘mount: специального устройства /dev/nbd0p1 не существует’

Для.ova

tar -tf image.ova tar -xvf image.ova 

Выше будет извлекать .vmdk диск, а затем смонтировать это.

За vmdk а также vhd файлы, мне повезло только с kpartx команда ниже:

Проверьте вывод для losetup , он должен содержать петлевое устройство /dev/loop0 ; также проверьте sudo blkid для раздела /dev/mapper/loop0p1 , затем используйте его в команде mount:

sudo mount -o rw /dev/mapper/loop0p1 /mnt/vmdk 

Где /mnt/vmdk — ваша точка монтирования, которая будет создана с sudo mkdir /mnt/vmdk если не существует.

sudo umount /mnt/vmdk sudo kpartx -d -v

Источник

Converting and cloning virtual HDDs between VDI, VMDK and VHD

There are several disk image formats used by virtualization software; VDI for Oracle VM VirtualBox, and VMDK for VMware vSphere, to name a few. If you want to convert VirtulBox VDI image to VMware VMDK image, or vice versa, there are two command-line utilities available to use.

The first tool is VBoxManage (vboxmanage.exe on Windows), which is a command-line utility that comes with VirtualBox. If you already installed VirtualBox on your system, VBoxManage is ready for use right away without installing any other software.

The second Linux tool is qemu-img command which is part of qemu hardware virtualization package.

To use qemu-img on Ubuntu or Debian:

$ sudo apt-get install qemu-utils

To use qemu-img on CentOS, Fedora or RHEL:

Читайте также:  Void linux kde plasma

Assuming that you have either of these two command-line tools available on your system, I will show how to convert between VirtualBox VDI and VMware VMDK formats, and how to import a converted standalone disk image in a VM. Before conversion, make sure to power off the VM whose disk image is being converted.

Convert VMware VMDK to VirtualBox VDI

To convert VMDK to VDI with VboxManage:

>$ VBoxManage clonehd --format VDI input.vmdk output.vdi

The output of this command will be similar to the following:

>$ /usr/bin/VBoxManage clonehd image_to_convert.vmdk converted.vdi --format VDI --variant standard --type normal 

Sun VirtualBox Command Line Management Interface Version 3.1.6
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.

0%. 10%. 20%. 30%. 40%. 50%. 60%. 70%. 80%. 90%. 100%
Clone hard disk created in format 'VDI'. UUID: 84f005f6-bbf8-4a0e-9fe8-3b7bf0df14d5

To convert VMDK to VDI with qemu-img:

$ qemu-img convert input.vmdk -O vdi output.vdi

Import VDI disk image in VirtualBox VM

Once you create a VDI-formatted disk image from a VMDK counterpart, you can create a new VM on VirtualBox, and attach the VDI image to the VM. While creating a VM, just choose «Use an existing virtual hard drive file» option, and use the existing VDI image file.

The clonehd command of VBoxManage supports the conversion between VDI, VMDK, VHD, so the three major virtualization’s hypervisors are supported (Oracle, VMware and Microsoft).

clonehd  
[--format VDI|VMDK|VHD|RAW|]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--existing]

Converting virtual HDDs between VDI, VMDK and VHD

Converting virtual HDDs between VDI, VMDK and VHD

Convert VirtualBox VDI to VMware VMDK

To convert VDI to VMDK with VboxManage:

$ VBoxManage clonehd --format VMDK input.vdi output.vmdk

To convert VDI to VMDK with qemu-img:

$ qemu-img convert input.vdi -O vmdk output.vmdk

Import VMDK disk image in VMware VM

Once you obtained a VMDK disk image from a VDI image, you can attach the standalone VMDK disk image to a VMware VM as follows.

First, create a new VM by using VM creation wizard. When asked to choose an OS installation option, choose «I will install operating system later» option, as shown in the following. That way, it will skip disk image creation.

Converting virtual HDDs between VDI, VMDK and VHD

Converting virtual HDDs between VDI, VMDK and VHD

Once.vmx file is created, edit the .vmx file to specify the existing VMDK image file as follows.

Clone VirtualBox disks VDI to duplicate a virtual machine

First you need to eelease and remove the VMware image from virtualbox’s virtual media manager if the disk is already in use by one of your virtual machines.

Copy the disk using VBoxManage:

>$ VBoxManage clonevdi disk.vdi disk_clone.vdi 

Sun VirtualBox Command Line Management Interface Version 3.1.6
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.

0%. 10%. 20%. 30%. 40%. 50%. 60%. 70%. 80%. 90%. 100%
Clone hard disk created in format 'VDI'. UUID: 124fbdf2-4e63-44dc-abfc-cef2899eaf6f

Now add the two disks back into Virtual Media Manager, they are ready to be used in your virtual machines!

Download

Instructions about VBoxManager and his syntax is available, in HTML format, here:

Источник

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