- Windows 10 Fall Creators Update installation and features - Thu, Nov 2 2017
- Install Microsoft SQL Server on Ubuntu Linux - Thu, Jan 5 2017
- Use PowerShell with Google Cloud Platform - Thu, Dec 8 2016
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:
- 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.
- Download the latest Ubuntu Server .iso and copy the file locally to a directory on your Hyper-V server.
- Open the Hyper-V Manager console, right-click on your Hyper-V server and click New, then Virtual Machine.
Create new Virtual Machine
- 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.
- Create a Virtual Disk, and select Ubuntu.iso as your CD/DVD drive.
Select Ubuntu .ISO
- 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.
- 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.
- Take note of your GoldMaster VM’s MAC/HW Address, and IP address by entering ifconfig into a terminal.
Identify MAC address with ifconfig
- Shutdown the baseline VM by issuing the command sudo shutdown –h now.
- 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.
- 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.
- 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
- Now go back to Step 3 and create a new VM with your required settings.
- 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
- 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
- The next step is to configure networking for your virtual machine. Choose the appropriate virtual switch and click
- 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
- Click Next and then
- 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.
- Shutdown the newly cloned VM (the original VM should also be powered off).
- In the Hyper-V Manager, right-click on the new Virtual Machine named ubuntuclone1 and choose Settings.
- Select Network Adapter on the left and click the Remove button in the right-hand pane.
Remove default network adapter
- Boot the new VM with no NIC attached.
- Log in to your new clone.
- Delete the leases file with sudo rm /var/lib/dhcp/dhclient.eth0.leases
- Shutdown the VM again
- 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.
- Power on the new VM and log in.
- Run ifconfig and check for your new IP and MAC address.
- Edit /etc/hostname to include your new hostname.
- Edit /etc/hosts file to contain your new hostname for 127.0.0.1 . Save and close the file and then restart your cloned VM one last time.
- 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.