Ubuntu runs on Hyper-V perfectly fine, so you may want to run many Ubuntu Virtual Machines (VMs) on Hyper-V Server 2012. R2 This article will show you how to clone or duplicate a single Ubuntu server on Hyper-V with different network interfaces and host names. Cloning Linux servers on Hyper-V is easy and quick when you have the right knowledge and tools.

When you have a large server and have been tasked with creating multiple virtual machines on Microsoft Hyper-V 2012, you probably don’t want to answer the same questions over and over during the operating system installation process. It’s actually not too difficult to create a single Ubuntu Linux Server 12.04 Virtual Machine, and then clone (or in this case, export) the VM multiple times.

Using the export feature, you’ll create new VMs with the same .vhdx or .vhd disks. Linux doesn’t have SysPrep, of course, so there are just a couple of changes you need to make once the cloned VMs have been created. Below is the method I used to create five Ubuntu VMs with different disk names, MAC addresses, and host names:

  1. First, the Hyper-V role must be installed on Microsoft Server 2012 R2 Standard or Datacenter with sufficient storage, memory and CPU cores available locally to Hyper-V.
  2. Download the latest Ubuntu Server .iso and copy the file locally to a directory on your Hyper-V server.
  3. Open the Hyper-V Manager console, right-click on your Hyper-V server and click New, then Virtual Machine.
    Create a new Virtual Machine
    Create new Virtual Machine
  4. Create a new VM with the required settings: Name (in this example we’ll use GoldMaster for the hostname), Generation 1 Type VM, startup memory (we recommend using Dynamic Memory), and NIC/Virtual Switch.
  5. Create a Virtual Disk, and select Ubuntu.iso as your CD/DVD drive.
    Select Ubuntu .ISO
  6. Click Finish. Next, before powering on the new VM, double-check the settings of your VM and change the number of Virtual Processors, if necessary.
  7. Right-click on the new VM and choose Connect. Then start the Ubuntu VM and install Ubuntu. Configure as you like but use DHCP for your network interface. I won’t go through the Ubuntu installation steps, but you will typically create your sudo user account, change your time zone, and select your keyboard layout, among other configurations for your server. Once the installation finishes, and you’re in your Ubuntu desktop, you should now run sudo apt-get update/upgrade at this time, and install any other software you want to have present in your cloned VM’s. Restart the Linux VM once more and log in to make sure your system is setup to your standards.
  8. Take note of your GoldMaster VM’s MAC/HW Address, and IP address by entering ifconfig into a terminal.
    Identify MAC address with ifconfig
    Identify MAC address with ifconfig
  9. Shutdown the baseline VM by issuing the command sudo shutdown –h now.
  10. In the Hyper-V console, right-click on the VM and choose Export. Save the files to a location you will remember. In this case, we used c:\Exports\GoldMaster1_Export\GoldMaster_Export1. The status of your export will display in the Hyper-V Manager.
  11. Using Windows Explorer, browse to your Export folder and find the folder named GoldMaster_Export1. Then, go into the Virtual Hard Disks folder within, and copy the .vhd file that the Export created to your clipboard. You’ll paste this copy of the VM into the default Hyper-V VHD location with a HostName of your choice. In our case, we’ll rename it ubuntuclone1.
  12. With Windows Explorer, browse to the default Hyper-V Virtual Hard Disks directory: C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\. Paste the exported and copied .vhd into the default Hyper-V Virtual hard disks directory and rename the VHD file to ubuntuclone1.
    Create new folder with new VM name
    Create new folder with new VM name
  13. Now go back to Step 3 and create a new VM with your required settings.
  14. When it asks for the name, use ubuntuclone1 and place a checkmark in the setting Store the virtual machine in a different location and provide the path to a newly-created directory under the default location with our new name. In this case we will use C:\ProgramData\Microsoft\Windows\Hyper-V\ubuntuclone1\.
    Store Virtual Machine in different location
    Store Virtual Machine in different location
  15. For the virtual machine settings, choose the Generation 1 option and click Next. Change the Startup Memory to 1024 MB, place a checkmark in Use Dynamic Memory and click and click Next.
    Virtual machine memory settings
    Virtual machine memory settings
  16. The next step is to configure networking for your virtual machine. Choose the appropriate virtual switch and click
  17. When asked to connect a virtual hard disk, choose Use an existing hard disk and Browse to the location of our copied and renamed vhd file in C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\
    Connect virtual hard disk
    Connect virtual hard disk
  18. Click Next and then
  19. Turn On… the new VM and log in to Ubuntu. It may have the same IP address of the original VM, but notice the system probably has a new MAC address. We need to set a new dynamic MAC address and IP.
  20. Shutdown the newly cloned VM (the original VM should also be powered off).
  21. In the Hyper-V Manager, right-click on the new Virtual Machine named ubuntuclone1 and choose Settings.
  22. Select Network Adapter on the left and click the Remove button in the right-hand pane.
    Remove default network adapter
    Remove default network adapter
  23. Boot the new VM with no NIC attached.
  24. Log in to your new clone.
  25. Delete the leases file with sudo rm /var/lib/dhcp/dhclient.eth0.leases 
  26. Shutdown the VM again
  27. In the Hyper-V Manager, Right-click on the VM again, and choose On the left at the top, click Add Hardware, then Network Adapter, then Add, and finally choose your virtual switch and click OK.
  28. Power on the new VM and log in.
  29. Run ifconfig and check for your new IP and MAC address.
  30. Edit /etc/hostname to include your new hostname.
  31. Edit /etc/hosts file to contain your new hostname for . Save and close the file and then restart your cloned VM one last time.
  32. You should now have a newly cloned VM with its own identity. You can now modify the disk size in Hyper-V, expand your partitions if necessary, and change your server from DHCP to a Static IP.
  1. ubu_fan 7 years ago

    @Jason Coltrin
    I Disliked your post by accident (face palm) !!
    My Apologies for the mistake the instructions/content you posted was very helpful.
    Thanks Again

  2. norb 6 years ago

    is it allowed to use sda5 crypt (lock drive) on hyper-v ? it it possible to expoer and import secured vm with Ubuntu?

    • Author

      Hi Norb,If LUKS is being used for the encryption then I do believe the volume can be exported and imported perfectly fine, however, I’ve read reports that there have been problems with the keyboard after encryption and a workaround has been found here: https://askubuntu.com/questions/574296/cannot-enter-password-to-start-ubuntu. As always it’s best to test your systems for resilience and I recommend you spin up a test VM, encrypt, export, import and test again.

  3. Mike Eshva 6 years ago

    You have a few mistakes in your post. Bad mistakes.

    #sudo rm /var/lib/dhcp dhclient.eth0.leases – note a space between dhcp and dhclient. It should be / As well # is irrelevant.
    /etc./hostname – note the dot. It shouldn’t be there.
    /etc./hosts – same like, note the dot. It shouldn’t be there.

Leave a reply

Your email address will not be published.


© 4sysops 2006 - 2023


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account