Azure : In place upgrading the Windows Operating System


This guide came about because sometimes it’s not feasible to do a clean install, especially if you’ve got an old legacy application that you need to maintain, sometimes despite the recommendations, you need to do an in place upgrade.

The main requirement here is for a legacy IIS application that uses older .Net technology and the feasibility of updating the OS needs ot be assess and an impact assessment needs to be completed.

The plot thickens

Let’s raise the steaks a little more with this particular scenario where the current operating system is Server 2008 R2 - this operations system has been out of support by Microsoft since 14 January 2020 - Which means at the time of this entry this is nearly 5 years out of support and the upgrade plan from this dinosaur version is Server 2012 R2 then to Server 2016/Server 2019 you are not able to go from Server 2008 R2 straight to Server 2016 or greater.

Azure increases the challenge

The next challenge you have is in Azure You have absolutely no access to the hypervisor, which means to provision servers you would have to do a clean install, it means we need a slightly different approach because of lack of hypervisor access.

Virtual machine is required for your virtual machine!

You need to build a virtual machine in Azure that has enough performance capacity to run a virtual machine inside that server using Hyper-V - so I would suggest you need a SKU size with a minimum of 16GB of RAM as you will be running a VM in a VM.

Install Hyper-V

We now need to install Hyper-V which can be completed with the command below, this will however not create the virtual switch or custom settings that comes later:

Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

Wait for this to install and when done yes you will neeed a reboot:


Start Hyper-V Manager

Once the server has rebooted from the Hyper-V manager from the administrator tools as below:



Install the Virtual Switch

How you need to start the Hyper-V manager then you need to create a switch for the VM devices inside Hyper-Right click the server name then choose "Virtual Switch Manager" as below:


We now need to choose the option for "External" and then we need the "Create Virtual switch" option as below:



You now need to give a relevant name and ensure its set to External network, if you need to select the VLAN option that is at the bottom of these options in the red box:


Then you need to click OK that will remind you that the Hyper-V server will not respond for a couple of seconds, this normal when adding a new switch:


If you pop back into the switch manager you will now see your new switch is ready for assigment:


Configure Hyper-V Settings

This will depend on your company requirements but for this you need to right click the server and choose "Hyper-V settings" as below:



This options I have changed for this are the "Virtual Hard Disk" and "Virtual Machine" file locations from the default to a folder off the root of the C: - this is only a temporary server but if you are using Hyper-V on Production you may wish to have a dedicated drive for both of these options.


This completes the Hyper-V setup, so now we need to get the disk that we are going to use from the Azure VM

Subscriptions and copying Disks

If you have subscriptions to divide your servers and you have a test server in a "Development" subscription and your Hyper-V is in a "Production" subscription when you try to create the "snapshot" you will be told that this is not supported.


That does not mean all hope is lost, create the snapshot and the disk (which is included in the sections below) in the current resource group then get Storage Explorer which will enable you to copy the drive between subscriptions.

Storage Explorer once connected to your account find the subscriptions and then expand the disks options, this will show you all the "resource groups" from there find the resource groups for your VMtoClone and HyperV-Manger then right click on those resource groups and "add to quick launch"


You should now see those resource groups at the top of Storage Explorer as below:


Click on the resource, in this case will contain VMtoClone and you will see the disk TestClone-Disk that is unattached, right click this disk and choose Copy...


Now click on the other resource groups, the one that contains HyperV-Manager and on the space under the disk right click and choose paste, then give the disk a name and do not forget that it will default to Premium SSD, I have reverted this back to Standard HDD, then click Paste.


Locate the VM in Azure you need to "clone"

Now we need to find the VM is Azure that we are looking to clone, this will create a copy of the disk that we can use with Hyper-V later, so first locate the VM in the Azure subscription

Now  we need to get the disk that we are going to use from the Azure VM here we have the device named "VMtoClone" so from the VM details under Settings>Disk find the system drive and click that disk link:


Create a snapshot from System Drive

You then need to "Create a Snapshot" as below:



You will need to give the snapshot a name and ensure you move it to the resource group where you have your Hyper-V server built so that the snapshot is in the same resource group, this makes it easier to locate, the default location will be the resource group the server is in:


Create disk from that snapshot

Navigate to your resource group and locate your newly created snapshot, as you can see from below here is the snapshot, when you have found it click on the snapshot:


You will then notice you have the option to create a disk from that snapshot as below:



Now we need to create the disk, that requires a name, the resource group should be in the location of your Hyper-V resource group as that is where the snapshot should be located:

Important : I have used the disk name TestClone-VM - however, please ensure you give your new disk A relevant name - for example, if you call the disks The name of the server with the drive letter then for example at this stage called the drive “BearAppLegacy-OSUpdated” - this disk will be used later When it’s swapped out for the existing disk, So please make sure you’re happy with the name you provide here!!!



If you check your resource group you will now notice you have a disk along with that snapshot, which is excellent as that disk now needs to be attached on the Hyper-V VM in a moment:


Attach the disk to the HyperV server (as additional data disk)

Now you have the disk created navigate to the VM for your Hyper-V sever in this case called "HyperV-Manager" then choose Disks notice that the disk in the red box is the system drive DO NOT amend this disk we need the section for "Data disks"

Under "data disks" click the "Attach existing disks" as below:


When you click attached disk, you will then need to locate the disk we have created in the previous step, the name of this should be TestClone-Disk - This disk should also be in the same resource group as your server so it should be pretty easy to find.

When you click on the Attach button you will get a "disk" line added by the name is blank as below, so click on the down arrow:


This will then show you a list of disks, and all the disks in your resource group should be at the top so there should only be one disk here as you can see from below:


When you choose that it will fill in all the details like Type, Size, Max IOPS and other values as you can see below, once happy click on the apply button, this will attach the disk the VM:


Once you apply this disk to server and it shows as "Attached" then you need to have a remote desktop session to HyperV-Manager.

Check Disk Management

Now you have attached a new disk to the server, you will need to navigate to disk management which you can do with this command:

compmgmt.msc

When this opens click on the Disk Management option, you should see one disk listed here, this is the system drive with the C:\ drive letter, however you will see no further disks.....


Right click Disk Management and then choose "Rescan Disks"


This will then show you the new disk you have just added to your HyperV-Manager notice here that it is offline: under the "Disk 2" we see Offline, this is good:


If you disk is online then you need to take it offline with a right click and "Offline" option:


Important : This disk needs to be offline for the Hyper-V part to work without issues

Create the VM in Hyper-V Manager

Now we have the disk assigned to the HyperV-Manager server need to create the VM on the Hyper-V manager so with that open right click the server name and choose New>Virtual Machine


Then we need to give the VM a name as below and click next:


In this example we require a Generation 1 virtual machine as the OS is legacy and may not support UEFI based boot options, so set Generation 1 to be sure:


I have then assigned 8196mb of memory which is not dynamic this means it will all be reserved for the VM without sharing:


We at this stage do not require a network connection so we can set this to "not connected" we will need to sysprep this OS to make sure it does not have the same GUID as the original server so that can be done off network, we will add the networking later on:


Next for the disk options we need to setup the disk later on, as the type of mount we require cannot be done in a wizard:


You will now have your VM setup as below, and it should be Off, it cannot be powered on as it has no boot volume, that will come now:


Configure the VM in Hyper-V

Right click on the VM and choose Settings:


Then you need to find IDE Controller 0, click on that item then choose "Hard Disk" and Add:


When you click add choose physical hard drive which is Disk 2 from the options as below:

Note : If this is greyed out your Disk 2 is online and it needs to be offline


Once you have add the disk you also need to increase the Processor value which is under Processor:


Then update the value on the right from "one" to "eight" as below:



Ignition : Power up the VM

Now this is all setup you can Start your VM and get it to the running state, to do that right click the VM and choose Start:


This will then confirm that the VM is now running,


If  you look in the screenshot "peek" window at the bottom left you will notice you can see the login screen already this means your VM is powered up and the OS is running:


You now need to take control by right clicking the VM and choosing "Connect" as below:


When you will have a remote desktop style window to the VM as below, which is obviously running Server 2008 R2 as we mentioned earlier.


Drop with Workgroup 

This VM will obviously be mimicking another VM with the same name as the other server, which is not good, hence the call for no networking, so we need to remove domain status and join to a workgroup called "Secure" with this command:

Important : Ensure you know the local join, if you do not then create a new account that is a Administrator so you can login

Remove-Computer -UnjoinDomaincredential bear.local\Lee -WorkgroupName Workgroup -PassThru -Verbose -Restart

This will prompt me for my password which will then remove it from bear.local and add it Workgroup then reboot the computer.

Provide "alternative" computer name

Once the servers starts up you now need to change the name of the computer, this cannot be done with 
Rename-Computer this is Server 2008 so the command is based on netdom, but first you need the current computer name so run these commands:

hostname
netdom renamecomputer <current_name> /NewName:TestVM1a

That should look like this:


Reboot the computer as instructed.

Randomisation with sysprep 

We now need a new GUID for the device first we need to know the current GUID of the device which can be done with this command:

wmic csproduct get uuid

That will return your current UUID like this:

UUID :9C6EAC36-64E3-4E52-94FE-22FCF289BE69

Now we need to change this as another service is using this GUID, so open up explorer and navigate to c:\windows\system32\sysprep and then run the sysprep.exe executable folder you can see here:


That will then show you the preparation tool, ensure you choose OOBE and tick the box generalize and then reboot then click OK:


This will then start this process, you will need to wait for this to finish, when its complete your server will reboot:


When the server does reboot you will need to confirm your country and accept the EULA, then you will need to provide a new administrator password as OOBE has completed and you need to initialise the administrator account:



Once at the desktop start a command prompt again and run this command:

wmic csproduct get uuid

This should return a new UUID which is does, excellent:

UUID : 30373237-3132-5A43-3334-3434464E4452

Upgrading the operating system

There is no direct upgrade path from server 2008 R2 to our target operating system server 2019, these steps so far  have only got us to a point where we now have the option to upgrade the operating system, we have already confirmed the operating system is running as it did before and it’s ready to be upgraded.

Preflight upgrade housekeeping

Due to the age of the server in place upgrades will need to copy all User application data, If you do not keep this data, it will simply reset the server back to the build default, which will not be valid For this test, we need to keep everything on the server intact.

This means now is a good idea to clean up all the old profiles that have not been used in a while and get rid of unnecessary user data, I would recommend you remove the profiles correctly using this command:

rundll32.exe sysdm.cpl,EditUserProfiles

This will display this dialogue where you can remove inactive profiles from the system and it will be done cleanly:



Prepare your ISO files

Using Hyper-V you will need the ISO to mount as a virtual CD, this means you would need to have the ISO files preferably on the local drive of your Hyper-V server.

You will need the following ISO files:
  1. Microsoft Server 2012 R2 ISO
  2. Microsoft Server 2019 ISO
I have downloaded these to the folder C:\VXHD\ISO as you can see below:


Execute : Server 2012 R2 Upgrade

We are now in a position to start first upgrade to the jump operating system to get us to where we need to be, to start the first upgrade, mount the Server 2012 R2 ISO to the CD drive, this needs to be done from the HyperV-Server:


Now jump back to the VMtoClone remote session and you should be after running setup.exe from that drive be asked to "Install" the Server 2012 R2 update:


The only option you need to ensure you need to choose that is different from the normal install is this option, the option needs to be "Upgrade" as below:


Detour: Upgrade Error : No Server 2008 R2 SP1

However after we click this option we immediately get this, and this turns out that we do not have SP1 installed on Server 2008 R2 - so its running RTM the needs to be fixed:


We now need another ISO as shown below which is the SP1 update ISO:


This means we need to go back to HyperV-Server and mount this ISO to the CD drive and then from the VMtoClone we can now get SP1 installed for Server 2008 R2:


Then we are off with the update, this should not take to long and you get a reboot after this update as well:


This should then allow us to install Server 2012 R2, so from HyperV-Server mount the Server 2012 R2 ISO once again and start the setup one again, remembering to choose upgrade.

Execute : Resume after Server 2008 R2 SP1 : Server 2012 R2 Upgrade

Start the setup and get to the upgrade option and this time when you click on the "upgrade" option this time its all good, we are upgrading:


We need to wait for this to finish, then you need a reboot again:


The reboot will take a moment of two as it needs to setup all the new setting and user data this may take a moment of two, this could be a good break for a coffee.

Confirm : Server 2012 R2 Upgrade completed!

This is a very simple step, after the reboot has got the VM to the login screen it should look something like this, which means the upgrade is now complete.


Execute : Server 2019 Upgrade

We are now in a position to start second upgrade to the final operating system to get us to where we need to be, to start the second upgrade, mount the Server 2019 ISO to the CD drive, this needs to be done from the HyperV-Server:


Now jump back to the VMtoClone remote session and you should be after running setup.exe from that drive be asked to "Install" the Server 2019 update:



You will need to for Server 2019 provide a key for the install, the key used here is a GVLK key so you need a KMS host key for this key to activate (so no its not a free key you can use for Retail):


The same as we need to "keep all the data" which is the top option:


You will then get some preflight checks and after a short moment you will told you are "ready to install" then setup is now upgrading your platform to Server 2019:


You will once again need to wait for this to complete, so this another prefect moment to get a cup of coffee, or if you are like me, drink you cold coffee from earlier.

When you get the first reboot will get you to this point, however more waiting is required:


The next reboots will get you to this point, which looks very promising this looks like Server 2019:


If you then login you will notice that this is Server 2019 which means the upate has been successful:


What about IIS after the upgrade? 

Yes, good point we need to check IIS to ensure that it is still functioning as it should be and the Application Pools are still available, which as you can see below is the case


We also have the option to use switch to the newer version of .Net as well, however this is down to the application:


That means we have now upgraded Server 2008 R2 to Server 2008 R2 then to Server 2012 R2 then finally to Server 2019 with a VM in Azure.

Restore Networking

If you remembered, we purposely didn’t set and network interface for this virtual machine which means you will not be able to access this machine remotely.

The operating system has been successful Rated so now is the time to add the network back, this will allow it to operate normally on your network with a completely separate address from the device you’ve cloned.

To complete this action from the Hyper-V manger by right clicking on the VM and choosing settings then click the Network Card option:


Then on the right choose the Virtual Switch  and for this example we need VLAN 20 and a bandwidth limit of 20Mbps both as a Download/Upload - you may not require either of these: 


Virtual disk Options

You now have a decision to make, What you get to this point the following is now true:

You have a disk that’s been cloned from a snapshot and has been upgraded to Server 2019 - that disk has a new UUID and is currently not joined to the domain it’s in a workgroup.

Now you have to decide if:

1) You would like to use this duplicated disk with a new UUID that is in a workgroup, you will need to do your housekeeping activities to get this server back into the domain with the correct name (edited disk)

2) Re-clone the disk again, which will put the operating system back to Server 2008 R2, and then go through this guide again this time ignoring the sysprep part, which means it will have the same UUID as the actual server. (Unedited disk)

‼️ Unattached cloned disk 

You need to ensure that this new desk is unattached from your Hyper-V server, unfortunately, you will not be able to unattached it while it’s running as a virtual machine on your Hyper-V server.

Start Hyper-V manager then right, click your test virtual machine and choose Shutdown….


You should notice the status changes to “Off” as below:


You now need to right click your virtual machine and choose the delete option, this will delete the virtual machine, but this will not delete the disk, it will simply put it back in off-line mode:


You will need to confirm this action:


You will now need to find the, in this case, HyperV-Manager VM and remove the additional data drive from this server, here in the green box you can see the data drive mounted and you will need to click the red "dismount" icon:


Once you click the dismount icon you will notice you will now see "Non data disks attached" which then need to be applied with the Apply button:


This will change the disk state from attached to unattached, you can now continue on with reattaching that disk to the correct server.

Option 1 : Swap the OS disk with the “cloned” edited disk

Remember you need to update the computer name and then join the server to the domain, you can find the command for that further up in this post.

The old will simply be unattached until you have confirmed the new drive is working and then you can delete the old disk.

Navigate to the actual virtual machine then choose the option Manage>Disks that should look something like this:


All that required from the screen is to make a note that the name of the disk that is currently attached to the VM, that name will be required with the script in a moment.

This means we first need to shut down the virtual machine, Then the processes we need to copy the Drive with the new name and then attach it back to the virtual machine.

Luckily, this can be accommodated for with the script, however, please remember to shut the VM down before running the script.

Note : The script will also clean up the old disk with the previous name by removing it, If you would like to leave it unattached, then please uncommonly the last line of code

 #Define the following parameters.
$location = "CentralUS"
$resourceGroup = "VMtoClone-RG"
$originalOsDiskName "TestCloneDisk”
$newOsDiskName = "BearAppSystem-DriveUpdated"
$virtualMachineName = "BearAppLegacy"
#Get a list of all the managed disks in a resource group.
#Get-AzDisk -ResourceGroupName $resourceGroup | Select Name
#Get the source managed disk.
$sourceDisk = Get-AzDisk -ResourceGroupName $resourceGroup -DiskName $originalOsDiskName
#Create the disk configuration.
$diskConfig = New-AzDiskConfig -SourceResourceId $sourceDisk.Id -Location $sourceDisk.Location -CreateOption Copy -DiskSizeGB 127 -SkuName "Premium_LRS"
#Create the new disk.
New-AzDisk -Disk $diskConfig -DiskName $newOsDiskName -ResourceGroupName $resourceGroup
#Swap the OS Disk out for the renamed disk.
$virtualMachine = Get-AzVm -ResourceGroupName $resourceGroup -Name $virtualMachineName
$newOsDisk = Get-AzDisk -ResourceGroupName $resourceGroup -Name $newOsDiskName
Set-AzVMOSDisk -VM $virtualMachine -ManagedDiskId $newOsDisk.Id -Name $newOsDisk.Name
Update-AzVM -ResourceGroupName $resourceGroup -VM $virtualMachine
#Delete the original disk.
#Remove-AzDisk -ResourceGroupName $resourceGroup -DiskName $originalOsDiskName -Force

That script will execute and swap your old drive with Server 2008 R2 for the new disk that has been upgraded to Server 2019.

Exception : I gave the disk a stupid name and can’t change it?

Yes, indeed if you ignored the warning about giving it a relevant name then you’ve just generated yourself a little bit more work to get the correct name.

First, you will need to create a snapshot of that disk, the name of the snapshot is not important, you only need the snapshot to do the next bit, ensure you choose a full snapshot, not an incremental.

You now need to select your snapshot and use the disk option from earlier, This time ensure you give the irrelevant name that will be used on your production server.

Once you have created that you can delete the snapshot it’s no longer required, Then I would recommend moving that newly created to the same resource group as your production server (the one you want to swap it with)

Option 2 : Swap the OS disk with the “cloned” unedited disk

If you have chosen this option, you need to be careful about keeping this device off the network, remember the UUID for this device is exactly the same as the one that’s in production.

This means the server has exactly the same name and it’s also in the same domain, if you boot of this disk with networking it may conflict with the record you already have in your domain!

If you have chosen this option, you need to follow the following steps to get yourself to a point where we can swap the OS disk:

‼️ Ensure you create a local account that will enable you to login into this server, Remember, it will have no networking through the entire process, So unless you have cashed credentials, you will be unable to login, however, I would recommend it safer to create a local account that means you can access the server with zero networking.
  1. Clone the current disk as a snapshot (full)
  2. Convert that snapshot to a disk
  3. Provide a relevant name for that copied disk
  4. Attached this disk it your Hyper-V instance
  5. Confirm that attached disk is off-line
  6. Create a new VM in Hyper-V
  7. Leave networking disconnected
  8. Update CPU and memory allocation
  9. Edit the VM setting,  assign your attached disk
  10. Start your VM
  11. Mount Server 2008 R2 SP1 ISO
  12. Install Server 2008 R2 SP1 (Upgrade mode)
  13. Reboot
  14. Mount Server 2012 R2 ISO  (Upgrade mode)
  15. Install Server 2012 R2
  16. Reboot 
  17. Mount Server 2019 ISO  (Upgrade mode)
  18. Install Server 2019
  19. Reboot
If you have completed the checklist above and you looking at the server 2019 login screen then you can now swap the OS disk from the existing disk to the one you have created from above, therefore from the production VM you will need to navigate to Manage>Disks then on the OS disk you will need to click in the "Swap OS disk" button as below:


You will then presented with a list of disks you can use, click on the "Select an existing disk" and choose your disk, in our example this is the one at the top of the list, if you cannot see it search for its name:



Once selected you will need t confirm the name of the server then click the OK button the VM will be powered off the disk will be swapped, once this operation completes you may need to manually power on the VM from de-allocated.


Wen the VM is back online and the OS is at the login screen and as you have swapped the disk it will also be back on the network and ready for login.

Bitlocker causing you an issue?

If you are using Bitlocker with ADE encryption then from the VM you have tried to clone you will need to start a command prompt evelated and then run this command:

manage-bde -protectors c: -get

In this case the server only has disk and that the system disk on C:\ so that command will return the Bitlocker recovery key as below, this is the password value, you will need this later on:


Now with your new disk that has been created from the snapshot bring the disk online (ensure the virtual VM in Hyper-V is stopped) which will immediately ask you for the Bitlocker recovery key like this, you need to enter that password here and click Unlock:

This will unlock it one and it will be required on every boot, not very good for OS upgrades so from here right click that new drive and choose "Manage Bitlocker"



You then need to turn off Bitlocker with the options below:


This will then start the decryption process as you can see below:



When you are done with the upgrade you can re-enable Bitlocker if you need to keep your drives secure with ADE.


Previous Post Next Post

نموذج الاتصال