Azure CLI creates VM from image in different region - azure

I have an image that I created in Azure that located in eastus. I want to deploy VM from that image in a different region (westeurope). I tried this CLI command but nothing is happening.
az vm create --resource-group Automationsystem --name VMEurope --location westeurope --image MyCustomImage --admin-username azureuser --size Standard_F4S --no-wait --ssh-key-value ~/mykey.pub
Is the option to deploy VM from image at another region exists?

As Lech Migdal said, you must have the image in the same region as VM.
For now, image does not support copy to other location. You need create a new image on westeurope location. Please refer to the following steps.
1.Use the image to create a VM in the current location.
2.Create a storage account in westeurope.
3.Stop VM and copy VM's managed disk to new storage account.
$sas = Grant-AzureRmDiskAccess -ResourceGroupName "[ResourceGroupName]" -DiskName "[ManagedDiskName]" -DurationInSecond 3600 -Access Read
$destContext = New-AzureStorageContext –StorageAccountName "[StorageAccountName]" -StorageAccountKey "[StorageAccountAccessKey]"
$blobcopy=Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer "[ContainerName]" -DestContext $destContext -DestBlob "[NameOfVhdFileToBeCreated].vhd"
Note: Use image to create VM, the OS disk is managed disk.
4.Use the VHD to create a new VM, you could use the template to do this.
5.Use the VM to create a new image. Please refer to this link.

Related

use azure cli command to change the reference image of vmss and update the vm running under the vmss

I want to use azure cli command to change the reference image of vmss and update the vm running under the vmss.
I used to use UI to update the reference image as shown below.
I tried following https://learn.microsoft.com/en-US/cli/azure/vmss?view=azure-cli-latest#az_vmss_update
but not getting exact command, am I going in wrong direction?
I have tested in my environment to change the reference images of VMSS but it seems not possible using below cmd.
Update-AzVmss ` -ResourceGroupName "myResourceGroup" ` -VMScaleSetName "myScaleSet" ` -ImageReferenceId /subscriptions/{subscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myNewImage
If you want to update the version of reference image you can change with the below command.
Update-AzVmss -ResourceGroupName "myResourceGroup" -VMScaleSetName "myScaleSet" -ImageReferenceVersion 16.04.201801090
This is the CLI command I have used
az vmss update --name MyScaleSet --resource-group MyResourceGroup --set virtualMachineProfile.storageProfile.imageReference.id=imageID

Why cant i simply create a Business Central container in Azure?

Im trying to create a Business Central container in Azure and am using the following in powershell.
$imageName = “mcr.microsoft.com/businesscentral:10.0.17763”
$resourceGroup = “d365rg”
$location = “EastUS”
$containerName = “d365bcdemo02”
$dnsName = “d365bcdemo02.eastus.azurecontainer.io”
$artifactUrl = Get-BCArtifactUrl -type sandbox -country us -select Latest
az container create -g $resourceGroup -n $containerName --image $imageName --os-type Windows --cpu 2
--memory 16 --ip-address public -e artifactUrl=$artifactUrl ACCEPT_EULA=Y USESSL=N ClickOnce=Y
publicDnsName=$dnsName --dns-name-label $containerName --ports 80 7046 7047 7048 7049 8080
But am constantly getting the error:
"az : The image 'mcr.microsoft.com/businesscentral:10.0.17763' in container group 'd365bcdemo02' is
not accessible. Please check the image and registry credential."
What credentials , i dont have a container registry and dont think you need one. What could be happening here ?
The issue is caused by the wrong image tag. So the solution is to use the tag available in the image.

Azure - VMSS - Data disk

I have created a vmss and added an addition Fisk from Fisk storage but it’s not available in the VM’s disk management as we usually get for normal VM(not from VMSS)
So how I can attach the new data disk on my VM from vmss.
There are a bunch of tutorials (in the official docs) available for this:
https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/tutorial-use-disks-cli
https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/tutorial-use-disks-powershell
https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-attached-disks
powershell cmd:
# Get scale set object
$vmss = Get-AzVmss `
-ResourceGroupName "myResourceGroup" `
-VMScaleSetName "myScaleSet"
# Attach a 128 GB data disk to LUN 2
Add-AzVmssDataDisk `
-VirtualMachineScaleSet $vmss `
-CreateOption Empty `
-Lun 2 `
-DiskSizeGB 128
# Update the scale set to apply the change
Update-AzVmss `
-ResourceGroupName "myResourceGroup" `
-Name "myScaleSet" `
-VirtualMachineScaleSet $vmss
cli:
az vmss disk attach \
--resource-group myResourceGroup \
--name myScaleSet \
--size-gb 128
Check this link for ARM template Data Disk Link
You can find detailed options of how to use data disk and use prepopulated data disk here:
Azure virtual machine scale sets and attached data disks
Azure VM Scale Sets attach-detach disk preview

Restoring Azure App Service backup to different site

How can I use Restore-AzureRmWebAppBackup to restore an app service to a different existing site? This can usually be done in the portal, but for some reason the destination app service is not listed, even though it's in the same resource group.
How can I use Restore-AzureRmWebAppBackup to restore an app service to a different existing site?
Here is a sample code of restore web app from PowerShell.
$resourceGroupName = "target web app resource group name"
$appName = "target web app name"
$blobName = "backup blob name"
$storageAccountURL = "SAS URL of your blob container"
Restore-AzureRmWebAppBackup -ResourceGroupName $resourceGroupName -Name $appName -StorageAccountUrl $storageAccountURL -BlobName $blobName -Overwrite
We can find the blob name from the restore page after you backup your web app.
For more information, link below is for your reference.
Use PowerShell to back up and restore App Service apps
Following is the solution using Bash CLI:
prerequisite: A storage account with a container and the container URL for the same. The container URL contains the access the key (SAS). More information about the container URL can be found here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
You can also use the following command to generate the SAS token:
az storage container generate-sas --name <container-name> --expiry <sas-expiry> --permissions <permissions> --account-name <account-name> --account-key <account-key>
To clone the app, use the following commands:
backupname=appname_`date "+%Y%m%d%H%M%S"`
az webapp config backup create --resource-group $OriginresourceGroupName --webapp-name $originAppName --backup-name $backupname --slot $OriginSlotName --container-url "$ContainerURL"
az webapp config backup restore --backup-name $backupname --container-url $ContainerURL --resource-group $TargetresourceGroupName --webapp-name $TargetAppname --overwrite --ignore-hostname-conflict
Use below cmdlets to restore last successful backup to slot or app
$resourceGroupName = "<<RG NAME>>"
$primarywebappname = "<<APP NAME>>"
$slotname = "<<SLOT NAME>>"
# Get the last Sucessfull BackupID of the backup you want to restore
$backupID=Get-AzWebAppBackupList -ResourceGroupName $resourceGroupName -Name `
$primarywebappname|where BackupStatus -EQ "Succeeded" |select -Last 1 |select BackupId
# Get the backup object that you want to restore by specifying the BackupID
$backup = (Get-AzWebAppBackupList -ResourceGroupName $resourceGroupName -Name
$primarywebappname | where {$PSItem.BackupId -eq $backupID.BackupId})
# Restore the app by overwriting it with the backup data in the slot
$backup |Restore-AzWebAppBackup -Slot $slotname -IgnoreConflictingHostNames -Overwrite
# Restore the app by overwriting into the exsisting App
$backup |Restore-AzWebAppBackup -Overwrite

azure cannot create vm from vhd image

I'm currently running into difficulty in creating an Azure VM from a custom VM image. I am following the guide from Azure from here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/
I've used Waagent and deprovisioned the machine as instructed, and deallocated, generalized, and captured my machine image (I have made some modifications to the core Ubuntu 16.04LTS image available from Azure software wise). I have successfully created the template.json file (Can provide it if needed). I then completed all the tasks below in the powershell script as outlined in the article, just extracting the parameters to variables to make things a bit easier.
## Global
$rgName = "testrg"
$location = "eastus"
## Storage
$storageName = "teststore"
$storageType = "Standard_GRS"
## Network
$nicname = "testnic"
$subnetName = "subnet1"
$vnetName = "testnet"
$vnetAddressPrefix = "10.0.0.0/16"
$vnetSubnetAddressPrefix = "10.0.0.0/24"
$ipName = "TestIP"
## Compute
$vmName = "testvm"
$computerName = "testcomputer"
$vmSize = "Standard_D1_v2"
$osDiskName = $vmName + "osDisk"
#template
$fileTemplate = "C:\AzureTemplate\template.json"
azure group create $rgName -l $location
azure network vnet create $rgName $vnetName -l $location
azure network vnet subnet create --resource-group $rgName --vnet-name $vnetName --name $subnetName --address-prefix $vnetSubnetAddressPrefix
azure network public-ip create $rgName $ipName -l $location
azure network nic create $rgName $nicName -k $subnetName -m $vnetName -p $ipName -l $location
azure network nic show $rgName $nicname
azure group deployment create $rgName $computerName -f $fileTemplate
I am able to successfully run all the commands to create the resource group and the network components, however, when I try to run the deployment command at the bottom of the powershell script, I get the following and it just hangs here indefinitely. Am I using the right approach to create a VM from a custom image? Or is that Azure guide outdated?
azure group deployment create $rgName $computerName -f $fileTemplate
[32minfo[39m: Executing command [1mgroup deployment create[22m
[32minfo[39m: Supply values for the following parameters
EDIT: Link to image showing the issue: http://imgur.com/a/Fgh8K
I believe your understanding is not complete. If you see at the last line it says Supply values for the following parameters
You need to pass the values for VM name, the admin user name and password, and the Id of the NIC you created previously. My be you should re-read the documentation. Here is the screenshot for your reference from https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/#deploy-a-new-vm-from-the-captured-image -

Resources