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:

cd /dev
ls -la

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

Francois Delport

How To Configure Docker On Windows

I recently started playing around with Docker on Windows and one of the first hurdles was how to configure Docker on Windows. Since I’m completely new to containers I’m going to share what I  figured out in case it can help someone else.

I followed this quick start from Microsoft which actually works very well. I used the server version but heads up if you want to use Docker with Windows 10. Docker requires Hyper-V and if you use VMWare Workstation you can’t have both installed at the same time.

There is a ton of information about Docker for Windows on their website but I wanted to highlight a few practical bits which most people would need to get started.

How to configure Docker on Windows

By default the Docker executables are located in “C:\Program Files\Docker” and its data is stored in %programdata%\docker. You’ll see the default container, image and configuration directories are here as well. When you install Docker it will be running with default values. To change the defaults you have to create a configuration file %programdata%\docker\config\daemon.json. The full configuration reference is here. The part I was interested in was changing the location where containers and images are stored to get them of my OS disk. The setting turned out to be the “graph” settings.

{"data-root": "D:\\Data\\Docker\\"}

Take note this changes the root directory for Docker data, not just the containers and images.

How to get clean Windows  Images

If you ran the quick start mentioned earlier, you’ll see it was running a container using the Nano Server image with a sample application. I wanted to firstly get an empty Windows image to play around with and secondly I wanted to run full .NET applications which require a Server Core image. The command to pull down the images from the Docker Hub are:

docker pull mcr.microsoft.com/windows/servercore:1903

docker pull mcr.microsoft.com/windows/nanoserver:1903

You can explore the Docker Repository to see which other images are available, link.

Exploring The Container Environment

I wanted to see what you get in a container and play around a bit. To start a new container interactively run:

docker run -i mcr.microsoft.com/windows/nanoserver:1903

docker run -i mcr.microsoft.com/windows/nanoserver:1903 powershell.exe

In the second instance the container will run PowerShell.exe after it started or you just run it from the command prompt yourself. In a future post I’ll dive into the isolation and integration between the host and container in more detail. For now I could see you get your own filesystem, network, installed windows features and registry but you get the users from the host.

Note: These Docker Hub repos did not maintain a “latest” tag, you have to specify the image tag for example 1903. The host Windows OS version can’t be lower than the container version. When you run a container that is an older version than the host it will use Hyper-V isolation. I was on Windows 10 version 1909 and I was able to run NanoServer 1903 and Server Core ltsc2019 but not 20H2 more info here.

Francois Delport

Nano Server CTP 5 In Azure

In this post I’m having a look at running Nano Server CTP 5 in Azure. Keep in mind this is CTP 5 so it is very far from done.

Nano Vs Core
Turns out there is a huge difference between Nano and Core 2016. Nano doesn’t have the full .NET framework, it is running .NET Core and you can’t install the full .NET framework even if you wanted to and support for the full .NET framework was not planned at the time of writing. Since you don’t have the full .NET framework you also don’t have full PoweShell, you get PowerShell Core.

Nano Server CTP 5 In Azure

There is no GUI, not even a command prompt, you can’t RDP into it, you don’t have a basic console like Core but there is a recovery console to help you establish network connectivity. You manage it using remote tools like PowerShell or Server Manager. In CTP5 DSC Push is working but you can’t use a Pull server. Here is a comprehensive list of PowerShell features and commands that are not working in the CTP 5 preview on Nano server.

Creating The Image And Installing Features
Nano server is basically empty if you use the base image, you have to inject features you need to turn it into anything useful. There is detailed documentation here. Basically you install a PowerShell module, copy the base image from Windows 2016 install media and execute New-NanoServerImage to create the Nano VHD. Most features are switched on or off by passing the correct switch parameter. It is mostly aimed at running in virtual environments but you can install it on a physical machine. At this point you need Windows already installed on the physical machine and you have to manually configure it to boot from the Nano VHD. It is possible to install components while the server is running but the current experience is very cumbersome using dism.exe. Apparently in the release version it will be streamlined and you’ll be able to use PowerShell commands to manage the features.

Nano On Azure
There are a few extra steps when you create your Nano server in Azure, most of it is covered here. The long and the short of it is:

  • Add a rule in your Network Security Group to allow WinRM over HTTP on port 5895.
  • At the remote machine public IP to the trusted hosts on your local machine
     Set-Item WSMan:\localhost\Client\TrustedHosts "AzureNanoPIP"
  • Connect to is using Powershell:
    Enter-PSSession -ConnectionUri "http://AzureNanoPIP:5985/WSMAN" -Credential (Get-Credential)

Side note: I used an A0 instance for testing and the Nano instance was using around 260MB Ram and 1.8 GB harddrive space.

Francois Delport