Create a VM from an unmanaged custom image
There are many documents on the official website that show you how to create a custom image. I have been using azure for more than two years and many machines are not hosted disks, therefore, to help customers test and use a VM created from an unmanaged custom image, the entire script is simple. You only need to change one parameter. However, this is not directly described in the document, at that time, it took time to test the VM. Therefore, you can directly share the success script with everyone. You only need to modify the imageurl to create a custom unhosted disk VM in batches. The created hosted disk will be shared with you later.
- The script is as follows:
$ Rgname = "myresourcegroup"
$ Subnetname = "mysubnet"
$ Singlesubnet = new-azurermvirtualnetworksubnetconfig-name $ subnetname-addressprefix 10.0.0.0/24
$ Location = "China North"
$ Vnetname = "myvnetname"
$ Vnet = new-azurermvirtualnetwork-name $ vnetname-resourcegroupname $ rgname-location $ location'
-Addressprefix 10.0.0.0/16-subnet $ singlesubnet
$ Ipname = "myip"
$ Pip = new-azurermpublicipaddress-name $ ipname-resourcegroupname $ rgname-location $ location'
-Allocationmethod dynamic
$ Nicname = "mynicname"
$ Nic = new-azurermnetworkinterface-name $ nicname-resourcegroupname $ rgname'
-Location $ location-subnetid $ vnet. subnets [0]. ID-publicipaddressid $ Pip. ID
$ Nsgname = "mynsg"
$ Rdprule = new-azurermnetworksecurityruleconfig-name myrdprule-description "allow RDP "'
-Access allow-protocol TCP-direction inbound-priority 110'
-Sourceaddressprefix Internet-sourceportrange *'
-Destinationaddressprefix *-destinationportrange 3389
$ NSG = new-azurermnetworksecuritygroup-resourcegroupname $ rgname-location $ location'
-Name $ nsgname-securityrules $ rdprule
$ Vmname = "myvm"
$ Vmconfig = new-azurermvmconfig-vmname $ vmname-vmsize "standard_a2"
$ Vm = add-azurermvmnetworkinterface-VM $ vmconfig-Id $ Nic. ID
$ Osdiskuri ="Https://xxxxxxxxxxxx.vhd", change to your own vhd URL
$ Osdiskname = $ vmname + "osdisk"
$ Vm = set-azurermvmosdisk-VM $ VM-name $ osdiskname-vhduri $ osdiskuri-createoption attach-Linux
You can create it through powershell. The last three lines are the focus, especially attach-linux. If it is Windows, it is attach-Windows.
Create a VM from an unmanaged custom image