Created
June 12, 2018 02:08
-
-
Save enihcam/ad9dca6310c169394404c045a8d14cab to your computer and use it in GitHub Desktop.
Powershell script to deploy Archlinux VM in Azure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#part I: upload VHD | |
$location = "East Asia" | |
$rgStorName = "backup" | |
$rgStor = New-AzureRmResourceGroup -Name $rgStorName -Location $location | |
$storName = "archstor" | |
$stor = New-AzureRmStorageAccount -ResourceGroupName $rgStorName -Name $storName -Location $location -SkuName Standard_LRS | |
$vhdUri = "https://archstor.blob.core.windows.net/vhd/Archlinux.vhd" | |
$localPath = "C:\Backup\Archlinux.vhd" | |
$vhd = Add-AzureRmVhd -ResourceGroupName $rgStorName -Destination $vhdUri -LocalFilePath $localPath -NumberOfUploaderThreads 8 | |
#part II: remove existing resources | |
$rgName = "arch" | |
$vmName = "archVm" | |
$vm = Remove-AzureRmVM -Name $vmName -ResourceGroupName $rgName -Force | |
$diskName = "archDisk" | |
$disk = Remove-AzureRmDisk -ResourceGroupName $rgName -DiskName $diskName -Force | |
#part III: create VM | |
$location = "East Asia" | |
$rgName = "arch" | |
$rg = New-AzureRmResourceGroup -Name $rgName -Location $location | |
$nsgName = "archNsg" | |
$rule1 = New-AzureRmNetworkSecurityRuleConfig -Name "22" -Description "22" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 22 | |
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rgName -Location $location -Name $nsgName -SecurityRules $rule1 | |
$subnetName = "archSubnet" | |
$singleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24 -NetworkSecurityGroup $nsg | |
$vnetName = "archVnet" | |
$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location -AddressPrefix 10.0.0.0/24 -Subnet $singleSubnet | |
$ipName = "archIp" | |
$pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -DomainNameLabel $rgName -Location $location -AllocationMethod Dynamic -IdleTimeoutInMinutes 30 | |
$nicName = "archNic" | |
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id | |
$location = "East Asia" | |
$rgName = "arch" | |
$vmName = "archVm" | |
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_B2" | |
$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id | |
$vhdUri = "https://archstor.blob.core.windows.net/vhd/Archlinux.vhd" | |
$diskConfig = New-AzureRmDiskConfig -AccountType StandardLRS -Location $location -CreateOption Import -SourceUri $vhdUri -OsType Linux | |
$diskName = "archDisk" | |
$osDisk = New-AzureRmDisk -DiskName $diskName -Disk $diskConfig -ResourceGroupName $rgName | |
$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType StandardLRS -DiskSizeInGB 30 -CreateOption Attach -Linux | |
$vm = New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment