Linux raw to vmdk

How To Convert A Linux Disk Or Image File To VMDK File

In this post I will show you how to convert a Linux disk or raw image file to a VMDK file so you can create a VMWare Workstation virtual machine from it. The basic steps are creating a raw image file of the physical disk using dd and converting the raw image file to a VMware disk/vmdk file. I was using Windows to do this but I’ll mention some Linux instructions as well.

Why this scenario

For on-line Linux machines you can use vCenter Converter to create a virtual machine the catch is it only supports ESXi. In my case I had to create a virtual machine from a disk /off-line machine for VMware Workstation on a Windows machine. At the time I couldn’t find a free native Windows tool that would create a raw image of the Linux disk. Potentially you could use disk imaging software to clone the disk in a virtual machine but the free Windows ones I tried didn’t have the necessary drivers included in their boot environments for VMWare disk controllers.

Creating the raw image file

To run dd on Windows requires Cygwin, there are no additional settings or packages required. I just accepted all the defaults during installation. It is important to run Cygwin as administrator in Windows or you will get permission denied errors in Linux when you run dd. Once inside Cygwin run the following to identify your attached disks:

The device name of your disks will depend on the type and number of attached devices, in my case it was /dev/sdc (the third disk). You can read about Linux device naming here. I wanted to write the image file to my Windows D: drive which will be mounted as /cygdrive/d. Once you identified the source and destination you can run dd to create the image file.

dd if=/dev/sdc of=/cygdrive/d/diskimage.img

Note: I looked into using Windows Subsystem for Linux instead of Cygwin but from what I Googled WSL doesn’t have the ability to address block devices so dd won’t work.

Converting the raw image file to VMDK

I used Starwind V2V Converter to convert the raw img file to a VMDK file, it is free but you have to supply some personal details to get the download link. The app is easy enough to use so I won’t show all the steps here, just choose Local file for the source and Local file VMDK as the destination. Starwind V2V has the option to convert a physical disk to a VMDK file but it didn’t show my Linux disks as a source, only the Windows ones.

Читайте также:  Две операционные системы линукс

On Linux you can use Qemu to convert img files to VMDK and other virtual disk formats. You can also use Qemu to convert a physical disk directly to VMDK file without creating the raw image file first.

I looked into using Qemu in Cygwin instead of Starwind V2V Converter but at the time Qemu packages weren’t available for Cygwin but I guess you could compile it from source and install the dependencies if you really want to go that way.

Creating the VM

Once you have the VMDK file you can create a new Linux virtual machine in VMWare Workstation. Be sure to match the Linux distribution of your source machine. I was converting an Ubuntu machine and it booted successfully without any additional work.

LinuxVM

The final step is to install open-vm-tools for desktop or server.

#Desktop
sudo apt install open-vm-tools-desktop
#Server
sudo apt install open-vm-tools

I am a cloud and devops consultant, technology fan and previously a professional C# developer with a keen interest in system design and architecture. Currently I am involved in projects using Azure, the Microsoft stack and DevOps. I am based in Melbourne, Australia. Email: [email protected]

Источник

Конвертирование виртуального диска Proxmox в диск VMware

Обновлено и опубликовано

Опубликовано: 22.02.2022

  • Доступы к гипервизорам по SSH.
  • Достаточно пространства для новых дисков.
  • Доступ к Proxmox по веб-интерфейсу (не обязательно).
  • Сетевая доступность между серверами Proxmox и VMware (желательно).

Для начала нужно посмотреть и найти диск виртуальной машины Proxmox, который мы будем конвертировать. Это можно сделать в веб-интерфейсе, перейдя на виртуальную машину, вкладку Hardware:

* в данном примере нам нужно будет конвертировать диск vm-101-disk-0.

Получить любую информацию о виртуальной машине в Proxmox можно и в командной строке:

* где 101 — идентификатор виртуальной машины.

В моем случае меня интересует:

Теперь давайте найдем, в какой директории на сервере находится данный диск:

* в нашем примере мы ищем vm-101-disk-0.

Мы будем работать с данным путем. Приступаем к конвертации:

qemu-img convert -f raw /dev/pve/vm-101-disk-0 -O vmdk /tmp/vm-101-disk-0.vmdk

* в данном примере мы будем преобразовывать наш диск /dev/pve/vm-101-disk-0 из формата raw в vmdk. Новый диск будет сохранен по пути /tmp/vm-101-disk-0.vmdk.

Очень важно заранее убедиться в наличие свободного места по пути, куда мы пытаемся сохранить диск нового формата. В противном случае, команда вылетит с ошибкой.

В зависимости от размера диска, процесс может занять много времени. После того, как конвертация закончится, необходимо перенести файл с новым диском на целевой сервер с VMware. Надежнее всего это сделать с использованием утилиты scp:

scp /tmp/vm-101-disk-0.vmdk 192.168.0.15:/vmfs/volumes/disk1

  • /tmp/vm-101-disk-0.vmdk — сконвертированный диск.
  • 192.168.0.15 — IP-адрес сервера VMware.
  • /vmfs/volumes/disk1 — путь на сервере VMware, где нужно сохранить новый диск.

Посмотреть на сервере VMware список носителей и свободное на них пространство можно командой:

Помимо scp, мы можем попробовать использовать графические интерфейсы для скачивания и загрузки диска. Однако, если работать с большими файлами, такой способ может оказаться ненадежным (обрыв соединения и ограничения со стороны графического инструментария).

Последнее, что необходимо сделать для преобразования диска — клонировать его с преобразованием в формат Thin Provision. Это значить, что диск будет ещё раз продублирован, и для этого потребуется дисковое пространство.

Читайте также:  Find string in all file linux

vmkfstools -i /vmfs/volumes/disk1/vm-101-disk-0.vmdk /vmfs/volumes/disk1/vmware_vm_thin-disk-0.vmdk -d thin

* где /vmfs/volumes/disk1/vm-101-disk-0.vmdk — путь к диску, который мы перенесли с Proxmox; /vmfs/volumes/disk1/vmware_vm_thin-disk-0.vmdk — новый файл уже в формате Thin Provision.

Готово. Для проверки диска создаем виртуальную машину и подключаем к ней наш новый диск. На запущенную машину устанавливаем VMware Tools.

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

Источник

Convert disk images to various formats using qemu-img

In this article, we would focus on how to convert disk images to various formats using command-line utility qemu-img in Ubuntu distribution. Disk images are virtual hard disks which are used with virtual machines. These disk images are used to emulate disk storage devices. Furthermore depending on virtualization used, different disk images are utilized by different applications like QEMU/KVM, VirtualBox etc.

First we would discuss how to get command-line utility qemu-img (Qemu disk image utility).

Note: Following operations would require you to have superuser privileges. In case you don’t have one, then contact your System Administrator for assistance.

Install qemu-img in Ubuntu distribution

The required package is already available in standard Ubuntu repository. Therefore, we need to first update the repository. So, issue the following in terminal –

Now, qemu-img command-line utility is packaged with qemu-utils. Hence –

sudo apt install qemu-utils

Convert RAW image to Qcow2, VDI, VMDK & VHD

I. Convert Raw image to Qcow2:

qemu-img convert -f raw image.raw -O qcow2 image.qcow2

II. Convert Raw image to VDI:

qemu-img convert -f raw image.raw -O vdi image.vdi

III. Convert Raw image to VMDK:

qemu-img convert -f raw image.raw -O vmdk image.vmdk

IV. Convert Raw image to VHD:

qemu-img convert -f raw image.raw -O vpc image.vhd

Convert Qcow2 image to RAW, VDI, VMDK & VHD

I. Convert Qcow2 image to RAW:

qemu-img convert -f qcow2 image.qcow2 -O raw image.raw

II. Convert Qcow2 image to VDI:

qemu-img convert -f qcow2 image.qcow2 -O vdi image.vdi

III. Convert Qcow2 image to VMDK:

qemu-img convert -f qcow2 image.qcow2 -O vmdk image.vmdk

IV. Convert Qcow2 image to VHD:

qemu-img convert -f qcow2 image.qcow2 -O vpc image.vhd

Convert VDI image to RAW, Qcow2, VMDK & VHD

I. Convert VDI image to RAW:

qemu-img convert -f vdi image.vdi -O raw image.raw

II. Convert VDI image to Qcow2:

qemu-img convert -f vdi image.vdi -O qcow2 image.qcow2

III. Convert VDI image to VMDK:

qemu-img convert -f vdi image.vdi -O vmdk image.vmdk

IV. Convert VDI image to VHD:

qemu-img convert -f vdi image.vdi -O vpc image.vhd

Convert VMDK image to RAW, Qcow2, VDI & VHD

I. Convert VMDK image to RAW:

qemu-img convert -f vmdk image.vmdk -O raw image.raw

II. Convert VMDK image to Qcow2:

qemu-img convert -f vmdk image.vmdk -O qcow2 image.qcow2

III. Convert VMDK image to VDI:

qemu-img convert -f vmdk image.vmdk -O vdi image.vdi

IV. Convert VMDK image to VHD:

qemu-img convert -f vmdk image.vmdk -O vpc image.vhd

Convert VHD image to RAW, Qcow2, VDI & VMDK

I. Convert VHD image to RAW:

qemu-img convert -f vpc image.vhd -O raw image.raw

II. Convert VHD image to Qcow2:

qemu-img convert -f vpc image.vhd -O qcow2 image.qcow2

III. Convert VHD image to VDI:

qemu-img convert -f vhd image.vhd -O vdi image.vdi

IV. Convert VHD image to VMDK:

qemu-img convert -f vpc image.vhd -O vmdk image.vmdk

In conclusion, we have discussed how to convert disk images to various formats using qemu-img in Ubuntu.

Читайте также:  Add existing users to group linux

Источник

How to convert flat raw disk image to vmdk for virtualbox or vmplayer?

On windows, use https://github.com/Zapotek/raw2vmdk to convert raw files created by dd or winhex to vmdk. raw2vmdk v0.1.3.2 has a bug — once the vmdk file is created, edit the vmdk file and fix the path to the raw file (in my case instead of D:\Temp\flash_16gb.raw (created by winhex) the generated path was D:Tempflash_16gb.raw). Then, open it in a vmware virtual machine version 6.5-7 (5.1 was refusing to attach the vmdk harddrive). howgh!

First, install QEMU. On Debian-based distributions like Ubuntu, run:

Then run the following command:

$ qemu-img convert -O vmdk imagefile.dd vmdkname.vmdk 

I’m assuming a flat disk image is a dd -style image. The convert operation also handles numerous other formats.

For more information about the qemu-img command, see the output of

Since the question mentions VirtualBox, this one works currently:

VBoxManage convertfromraw imagefile.dd vmdkname.vmdk --format VMDK 

Run it without arguments for a few interesting details (notably the —variant flag):

VBoxManage convertfromraw 

To answer TJJ: But is it also possible to do this without copying the whole file? So, just to somehow create an additional vmdk-metafile, that references the raw dd-image.

Yes, it’s possible. Here’s how to use a flat disk image in VirtualBox:

First you create an image with dd in the usual way:

dd bs=512 count=60000 if=/dev/zero of=usbdrv.img 

Then you can create a file for VirtualBox that references this image:

VBoxManage internalcommands createrawvmdk -filename "usbdrv.vmdk" -rawdisk "usbdrv.img" 

You can use this image in VirtualBox as is, but depending on the guest OS it might not be visible immediately. For example, I experimented on using this method with a Windows guest OS and I had to do the following to give it a drive letter:

  • Go to the Control Panel.
  • Go to Administrative Tools.
  • Go to Computer Management.
  • Go to Storage\Disk Management in the left side panel.
  • You’ll see your disk here. Create a partition on it and format it. Use FAT for small volumes, FAT32 or NTFS for large volumes.

You might want to access your files on Linux. First dismount it from the guest OS to be sure and remove it from the virtual machine. Now we need to create a virtual device that references the partition.

label: dos label-id: 0xd367a714 device: usbdrv.img unit: sectors usbdrv.img1 : start= 63, size= 48132, type=4 

Take note of the start position of the partition: 63. In the command below I used loop4 because it was the first available loop device in my case.

sudo losetup -o $((63*512)) loop4 usbdrv.img mkdir usbdrv sudo mount /dev/loop4 usbdrv ls usbdrv -l 
total 0 -rwxr-xr-x. 1 root root 0 Apr 5 17:13 'Test file.txt' 

Источник

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