Monday, 20 May 2024

(LAB)Create a Linux virtual machine with the Azure CLI on Azure

 

Create a Linux virtual machine with the Azure CLI on Azure

Applies to: ✔️ Linux VMs

Deploy to Azure

This quickstart shows you how to use the Azure CLI to deploy a Linux virtual machine (VM) in Azure. The Azure CLI is used to create and manage Azure resources via either the command line or scripts.

If you don't have an Azure subscription, create a free account before you begin.

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also open Cloud Shell in a separate browser tab by going to https://shell.azure.com/bash. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and select Enter to run it.

If you prefer to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.30 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI.

Define environment variables

The first step is to define the environment variables. Environment variables are commonly used in Linux to centralize configuration data to improve consistency and maintainability of the system. Create the following environment variables to specify the names of resources that you create later in this tutorial:

Bashexport RANDOM_ID="$(openssl rand -hex 3)"
export MY_RESOURCE_GROUP_NAME="myVMResourceGroup$RANDOM_ID"
export REGION=EastUS
export MY_VM_NAME="myVM$RANDOM_ID"
export MY_USERNAME=azureuser
export MY_VM_IMAGE="Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts-gen2:latest"

Log in to Azure using the CLI

In order to run commands in Azure using the CLI, you need to log in first. Log in using the az login command.

Create a resource group

A resource group is a container for related resources. All resources must be placed in a resource group. The az group create command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters.

Bashaz group create --name $MY_RESOURCE_GROUP_NAME --location $REGION

Results:

JSO
{
  "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup",
  "location": "eastus",
  "managedBy": null,
  "name": "myVMResourceGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

Create the virtual machine

To create a VM in this resource group, use the vm create command.

The following example creates a VM and adds a user account. The --generate-ssh-keys parameter causes the CLI to look for an available ssh key in ~/.ssh. If one is found, that key is used. If not, one is generated and stored in ~/.ssh. The --public-ip-sku Standard parameter ensures that the machine is accessible via a public IP address. Finally, we deploy the latest Ubuntu 22.04 image.

All other values are configured using environment variables.

Bashaz vm create \
    --resource-group $MY_RESOURCE_GROUP_NAME \
    --name $MY_VM_NAME \
    --image $MY_VM_IMAGE \
    --admin-username $MY_USERNAME \
    --assign-identity \
    --generate-ssh-keys \
    --public-ip-sku Standard

It takes a few minutes to create the VM and supporting resources. The following example output shows the VM create operation was successful.

Results:

JSON
{
  "fqdns": "",
  "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
  "location": "eastus",
  "macAddress": "00-0D-3A-10-4F-70",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "52.147.208.85",
  "resourceGroup": "myVMResourceGroup",
  "zones": ""
}

Enable Azure AD Login for a Linux virtual machine in Azure

The following code example deploys a Linux VM and then installs the extension to enable an Azure AD Login for a Linux VM. VM extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines.

Bash
az vm extension set \
    --publisher Microsoft.Azure.ActiveDirectory \
    --name AADSSHLoginForLinux \
    --resource-group $MY_RESOURCE_GROUP_NAME \
    --vm-name $MY_VM_NAME

Store IP address of VM in order to SSH

Run the following command to store the IP address of the VM as an environment variable:

Bash export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv)

SSH into the VM

You can now SSH into the VM by running the output of the following command in your ssh client of choice:

Bash
ssh -o StrictHostKeyChecking=no $MY_USERNAME@$IP_ADDRESS

Microsoft Azure Virtual Machine

 































































                Microsoft Azure Virtual Machine



What is a Virtual Machine?

It is a computer file known as an image that functions much like a real computer. One of the folders that contain everything is that one. Windows, Linux, and other operating systems can all run it. As a result, you have the flexibility to run several machines on a single physical computer. Different operating systems are possible for various systems.

Each virtual machine’s virtual hardware includes CPUs, RAM, hard drives, network connections, and other similar components.


What is Azure Virtual Machine?

Making your own instances is one of the services offered by Azure. It has a variety of applications.:

Development and test

Applications in the Cloud

Extended Datacenter

It is important to keep in mind that you must pay for computation time when using Azure on a per- minute basis.

Their size, operating system, and any installed licensed applications all factor into the price of this.

It is recommended that you set its state to Stopped when not in use to prevent corresponding charges (Deallocated)

With Microsoft Azure, you may receive general-purpose, general-purpose, compute-optimized, memory-optimized, and burstable virtual machines. This service is much more appealing to companies because of the per-second charge. These are some uses for Azure Virtual Machines:

Development and test

Creating machines with the fundamental and specialized configurations needed to code and test the applications is quick and simple.

Applications in the cloud

When necessary, one can purchase more virtual machines and turn them off when not.

Extended datacenter

The network of the company can be quickly connected to VMs in the Azure Virtual Network.


Workloads for an Azure virtual machine

There are two methods you can go about moving to an Azure virtual machine. You will discover these two crucial approaches to transitioning to an Azure VM in this tutorial on building Azure Virtual Machines.

Suitable workloads

unsuitable workloads


Suitable Workloads

It is nothing, but highly available service workloads, such as internet shops for sale It may also be used for recurring tasks like:

Marketing campaigns which are seasonal on a website of an organization.

Annual Sales during festive holidays.

For unpredictable workloads, such as those at startups where they are oblivious to their expansion Organizations that merely want to offload their infrastructure to the cloud can also use it.

unsuitable workloads

It is not appropriate for you to shift your applications to the cloud if you cannot notice a cost difference.

There are various laws or ordinances from the authorities or the local government that forbid moving to the cloud because of their laws.


How to create an Azure Virtual Machine?

To create an Azure virtual machine, use one of the following methods:

When building an Azure VM, it all depends on the environment you are working in:

Azure Portal

A virtual machine is created through Azure Portal. Windows is used as the portal.

Templates

A Windows Virtual Machine can be established with the Resource Manager Template.



Client Disks

Azure Resources can be deployed using C#.

REST API’s


Create a virtual machine or update one.


A virtual network: what is it?

This Azure virtual network tutorial will assist you in thoroughly understanding Azure Customers can construct and administer virtual private networks in Azure thanks to virtual networks. Virtual networks' primary function is to allow instances to communicate with one another. It is possible to link various virtual networks together. You can connect to your on-premises networks using the Azure virtual network. As a result, Azure serves as a virtual extension of your on-site data center. ICMP and UDP are supported by Azure Virtual Networks.

Isolation

When building a virtual network, you can separate each of these networks so that they each function independently.

The virtual network can be set up to use your personal DNA servers.

Internet Communication

By default, any instances you start in an Azure virtual machine can connect to the Internet. As required, you can enable inbound access to resources.

Azure Resource Communication

Regardless of whether the resources are from the same subnet or separate subnets, they can communicate with each other using private IP addresses if they are part of the Azure virtual network.

They offer pre-configured routing between subnets so that users of on-premises networks OS don't have to manage and configure routes.

Virtual Network connectivity

Resources from any virtual network can communicate with resources from any other virtual network thanks to its connectivity.

Do you intend to attend an Azure interview? The most recent Azure interview questions are next.

On-premises connectivity

It is possible to connect a virtual network to an on-premises network so that resources can communicate with one another.




Traffic filtering

By source, IP address and port, network traffic from resources in a virtual network can be filtered.

Routing


By default, Azure's routing can be overridden with your own routes or by propagating BGP routes over the network gateway.


DHCP in Azure Virtual Network (Dynamic Host Configuration)

Ip addresses are assigned by Azure using Dynamic Host Configuration Protocol services from the ranges you specify for the virtual network. The length of each IP address lease is limitless. You will have a thorough understanding of Dynamic Host Configuration in Azure Virtual Network after completing this building Azure VM lesson.

You can configure a static private IP address from the range of Ipv4 addresses connected to the virtual network to prevent IP address changes regardless of the condition of the Azure virtual machine.


Microsoft Azure Virtual Network: Subnet

There are one or more Subnets in the Azure virtual network.

Subnets break your virtual network into smaller IP ranges to allow logical separation of the resources arranged within each subnet.

A portion of the virtual network space is represented by the IP address range that each subnet contains. Check out our Microsoft Azure Training course if you want to learn more about cloud architecture!

Routing in the Azure Virtual Network

It is nothing more than the default routing of your traffic.

Each subnet in the Azure virtual network had a routing table automatically constructed for it, and system default routes were also included. A few System routes can be replaced with custom routes, and you can also add more custom routes to the route database.


Groups for Network Security

The only thing limiting network traffic at the level of virtual machines is the firewall. Based on the source or destination IP addresses, ports, and protocol, it provides a list of security rules that permit or prohibit inbound or outbound network communication.

Security rules are applied to all resources in the subnet if they are applied to the subnet.





Select the appropriate VM for your workload to save money.

Improve operational efficiency by moving your mission- and business-critical workloads to Azure infrastructure. Use Azure Virtual Machines to run SQL Server, SAP, Oracle, and high-performance


computing applications. Windows Server or your preferred Linux distribution. Deploy virtual machines with 12 TB of memory and up to 416 vCPUs. Get each VM up to 3.7 million IOPS of local storage. Benefit from the first cloud deployment of 200 Gbps InfiniBand and up to 30 Gbps Ethernet. Choose the underlying processors AMD, Ampere (based on Arm), or Intel that best satisfy your needs.


Improve your system and save money.

Using Azure Reserved Virtual Machine Instances' term pricing, you can save up to 72% above pay-as- you-go charges. Utilize Azure Hybrid Benefit and reserved instances to run Windows Server VMs on Azure using your on-premises licenses while saving up to 80%. Use Azure VMs and scale sets at spot prices to run interruptible applications at significant savings over pay-as-you-go costs. Utilize Azure Cost Management to maximize your cloud expenses. When you switch to Azure, you'll receive three additional years of extended security updates for Windows Server 2012 and 2012 R2.


Discover the newest features of Azure Compute.

Scalable applications can be created by using virtual machine scale sets. With Azure Spot Virtual Machines and reserved instances, you can cut your cloud spending. Utilizing Azure Dedicated Host, create your own private cloud. To improve resilience, run mission-critical programs in Azure.


Manage, monitor, and backup the environments of your virtual machines.

With Azure Blueprints, you can quickly move apps from development to production across your whole company. With Azure Advisor, you may receive suggestions for all your VMs around high availability, security, performance, and cost. Using Azure Backup, secure your data against ransomware. Utilize Azure Monitor to proactively discover problems and receive insightful knowledge. With on-demand capacity reservations, reserve computing resources prior to VM deployments.


Adopt reliable hybrid cloud technologies

Utilize Azure virtual machines to increase the capacity of your data center and gain access to cloud- based, on-demand high-performance computing resources. Consistently create, test, deploy, and manage hybrid cloud applications across Azure and you’re on-premises environment To prevent company interruptions, use easy-to-use, affordable cloud backup and disaster recovery options. By creating in Azure and deploying on-premises with Azure Stack, you can meet the regulatory and policy requirements for your virtual machines.


Scale your system without introducing more complexity

With Virtual Machine Scale Sets, you can set up highly available, centralized-managed, and scalable services for computationally demanding, big data, and container applications. With Ephemeral OS discs, you may reimage your virtual machines for less money and faster for stateless applications. Shared picture galleries allow you to control the massive worldwide replication and sharing of photographs. To


reduce boot and installation times, use generation 2 virtual machines. With GPU-enabled VMs, you can get tremendous computational power for your artificial intelligence (AI) and remote visualization tasks.


Boost compliance and security

With a trustworthy launch, you can guard your virtual machines (VMs) against malware at the kernel and user mode. Utilize Azure secret computing to protect your VM data while it is running. With Azure Security Center, you can keep an eye on your workloads and detect and repair issues. satisfy a wide range of global and sector-specific compliance requirements, such as the General Data Protection Regulation (GDPR), ISO 27001, HIPAA, FedRAMP, and SOC 2. Install your Azure virtual machines on an exclusive to your company physical server called an Azure Dedicated Host. Benefit from a variety of VM service-level agreements (SLAs), ranging from single-instance VMs at 99.9% to VMs deployed across two or more Azure Availability Zones at 99.99 percentage.

Getting Started with Microsoft Azure Virtual Machines

Getting Started with Microsoft Azure  Virtual Machines



Introduction

You can use a Microsoft Azure Virtual Machine when you need a scalable, cloud-based server running a Windows or Linux operating system and any application of your choosing. By taking advantage of Microsoft Azure Infrastructure as a Service (IaaS), you can run a virtual machine on an ongoing basis, or you can stop and restart it later with no loss to your data or server settings.

You can quickly provision a new virtual machine from one of the images available from Microsoft Azure. On the other hand, if you are already running applications in a VMware or Hyper-V virtualized environment, you can easily migrate your virtual machine to Microsoft Azure. Once you have created your virtual machine and added it to Microsoft Azure, you can work with it much like an on-premises server by attaching more disks for data storage or by installing and running applications on it.


Virtual machines rely on Microsoft Azure Storage for high availability. When your virtual machine is provisioned, it is replicated to three separate locations within the data center to which you assign it. You have the option to enable geo-replication to have copies of your virtual machine available in a remote data center region.


Considering Scenarios for a Virtual Machine

Microsoft Azure gives you not only the flexibility to support many application platforms, but also the flexibility to scale up and scale down to suit your requirements. Furthermore, you can quickly provision a new virtual machine in a few minutes. A Microsoft Azure virtual machine is simply a fresh machine preloaded with an operating system of your choice—you can add any needed application easily. Consider the following suggested scenarios as merely a few of the possibilities.


Existing virtual environment. You can move an existing server workload into the cloud simply by copying an existing on-premises VHD to Microsoft Azure. That way, you can leverage cloud benefits such as elasticity, redundancy, and automatic platform updates, while paying only for storage and the time the virtual machine is in use.

Cloud workstation. You can create a virtual machine for use in the cloud that contains applications you commonly use and want to access from any location. Rather than set up a desktop workstation or carry a laptop to run the applications you use frequently, you can install your applications on a virtual machine that is accessible in the cloud. With this type of environment, you can travel easily from location to location with a tablet and then connect to a virtual machine using RDP or SSH to access your routinely used applications such as Matlab, R, IPython, or SQL Server.


Linux cluster. You can create a virtual machine based on a Linux operating system and then change the configuration to run multiple virtual machines as a cluster. By using a cluster, you provide a fast, high capacity, and redundant environment for any custom Big Data and Big Compute applications you choose to install on the virtual machine.


Development or test environment. Another option is to set up virtual machines for development or test purposes that you use solely on an as-needed basis. For example, you could install Visual Studio on a


virtual machine for use during the development phase of a project without the need to allocate on- premises resources to development. Likewise, rather than incur the cost of setting up and maintaining a load test environment that you use only periodically, you can set up virtual machines to run only when you need an independent and isolated environment.


Custom machine images. Perhaps you need a team of people to work with a common set of complex tools and packages. You can take advantage of community-contributed virtual machine images available at VM Depot. Another option is to create and contribute a virtual machine that you preconfigure with selected applications or packages for an online community to reuse in the cloud. See “Using and Contributing Virtual Machines to VM Depot” at http://research.microsoft.com/en- us/projects/azure/technical-papers.aspx to learn more.



Creating a Virtual Machine

There are two primary ways to create a virtual machine that runs in Microsoft Azure—mounting an existing disk or using an image.


A disk is a virtual hard disk (VHD) that already contains an operating system at minimum and optionally includes one or more applications. Any configuration changes you make are persisted on the disk and available the next time you start the VHD.


An image is a template that contains a base operating system (Windows or Linux) and perhaps one or more applications, but no user accounts. A disk for the operating system is added to Microsoft Azure Storage and assigned to the new virtual machine during the provisioning process. You can use an image to quickly reproduce the same virtual

machine multiple times.



Using the Virtual Machine Image Gallery

A simple way to get started using a virtual machine is to create virtual machine from the Image Gallery that you can access from the Microsoft Azure Management Portal. To view the available images, click the New button (which displays as a plus symbol on the bottom left side of the portal), select Virtual Machine in the Compute group, and then click From Gallery, as shown in Figure 1.




 

Figure 1: Creating a New Virtual Machine



The Create a Virtual Machine dialog box gives you the following three options:


Platform Images. Here you can find a collection of images, as shown in Figure 2, containing only an operating system, such as Windows Server 2012 R2 or OpenLogic CentOS 6.3, or images that contain both an operating system and an application, such as SharePoint Server 2013 or Visual Studio Ultimate 2013. For a list of supported operating system roles and features as well as supported software, see http://support.microsoft.com/kb/2721672⦁ .

My Images. This section of the Image Gallery displays a list of images that you create and store in Microsoft Azure. To create an image, you can capture an existing Microsoft Azure Virtual Machine, use SUSE Studio to build and migrate an image, or upload your own virtual machine, as explained later in this document.

My Disks. You can create a virtual machine simply by selecting a disk on this list.

Note: In addition to the images available in the Virtual Machine Image Gallery, there are images created and contributed by members of the online community available at VM Depot. Refer to the document “Using and Contributing Virtual Machines to VM Depot” at http://research.microsoft.com/en-us/projects/azure/technical-papers.aspx for more information.




 

Figure 2: Selecting a Virtual Machine Image from the Gallery

After you select the image you want, you assign a name to the virtual machine, specify a size, and create the administrator’s login name and password for a Windows operating system or specify the authentication method for a Linux operating system. Some platform images have minimum size recommendations noted in the image description. The number of CPU cores and the amount of available memory defines the size of a virtual machine. At one end of the spectrum, a virtual machine can share a CPU core, consume only 768 MB of memory, and support one data disk. The maximum size of a data disk is 1 TB. At the other end of the spectrum, a virtual machine can be allocated eight CPU cores, up to 56 GB of memory, and up to 16 data disks at the time of this writing, but these maximum values are likely to increase as Microsoft Azure adds more powerful hardware offerings in the future. Pricing of the virtual machine depends on the size of the virtual machine you select.


Your next step is to configure the following additional settings for your virtual machine:

Cloud Service. A cloud service is simply a container for your virtual machines. You can host a single virtual machine in a cloud service or assign multiple virtual machines to the same cloud service. When configuring the cloud service, you can request a new cloud service or select one that you created earlier.

Cloud Service DNS Name. You must provide a unique name that you later use to connect to the virtual machine.

Subscription. You must assign the virtual machine to an existing subscription.

Region/Affinity Group/Virtual Network. You must select a data center region to host your virtual machine. Alternatively, if you have created an affinity group or virtual network, you can select either of those options instead.

Storage Account. The disk for your virtual machine that gets created from the image you select must be assigned to a storage account. You can create a new one for your virtual machine or select a storage account that you created earlier.

Availability Set. An optional step is to create an availability set or assign the virtual machine to an existing availability set to ensure high availability. That way, if your physical server is taken


down for maintenance, every service included in the availability set will be accessible through other physical hosts. When multiple virtual machines belong to the same availability set, the Microsoft Azure Fabric Controller places virtual machines across multiple racks, each of which can be considered a fault domain and separate physical points of failure, as shown in Figure 3. In addition, each virtual machine is placed in a separate upgrade domain so that virtual machines in the same availability set are not taken offline at the same time during host updates.



Figure 3: Virtual Machines Assigned to Separate Availability Sets



Last, you configure endpoints for your virtual machine. The image you select has one or more preconfigured endpoints. For example, if the image runs a Windows operating system, the Remote Desktop and PowerShell endpoints are created with public and private ports to use when you or your applications connect to the virtual machine. You can add more endpoints if necessary, such as FTP, SSH, or SMTP for example, and specify whether to assign the TCP or UDP protocol to the endpoint.

Additionally, you can change the public and private port numbers from the defaults to alternate values. You can also take advantage of advanced networking features in Microsoft Azure Virtual Network to connect your virtual machine to an on-premises datacenter or a single client machine using an IPsec connection.

When you complete the configurations steps, the virtual machine is provisioned in Microsoft Azure. You can monitor this process, which typically takes only a few minutes, in the Microsoft Azure Management Portal. When provisioning is complete, the virtual machine starts. When its status changes to Running, your new virtual machine is available for you to connect to it as described in the “Using a Virtual Machine” section of this document.


If you are not ready to start working with your virtual machine, select it in the list on the Virtual Machines page in Microsoft Azure Management Portal, and then click Shut Down. That way, you can save usage costs, although there is an ongoing cost associated with the disk in your Microsoft Azure Storage account.


Note: Specific steps for creating a Windows virtual machine from the Image Gallery are available at http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-tutorial/. If you


want to create a Linux virtual machine instead, refer to the instructions at http://azure.microsoft.com/en- us/documentation/articles/virtual-machines-linux-tutorial/.


Capturing a Microsoft Azure Virtual Machine

If you have an existing Windows-server based Microsoft Azure Virtual Machine for which you want to create an image, you can use the Sysprep utility to put the virtual machine into the necessary state. To do this, open a command prompt window, navigate to the system32\sysprep directory in the Windows directory of the virtual machine, and execute sysprep.exe. In the Sysprep tool, select the Enter System Out-of-Box Experience (OOBE) action, select the Generalize check box, and select Quit as the Shutdown Option. When the sysprep succeeded.tag appears in the same folder as the Sysprep tool, log off the virtual machine and then use the Shut Down button on the command bar to stop the virtual machine.

When it has successfully stopped, click the Capture button to generate the image. You then name the image and confirm that you have run the Sysprep utility. When you are ready to use the image, you can find it on the My Images section of the Image Gallery described in the “Creating a Virtual Machine” section of this document.

For more detailed instructions, see http://azure.microsoft.com/en-us/documentation/articles/virtual- machines-capture-image-windows-server/.


Using SUSE Studio to Create a Virtual Machine Image

SUSE Studio is a web-based service that you can use to create a virtual machine (called an appliance by SUSE Studio) that you can then transfer to run in Microsoft Azure. SUSE Studio offers a wizard interface to simplify the process of creating your virtual machine. You start by selecting an open source operating system, such as SUSE Linux Enterprise 11 SP3, a 32-bit or 64-bit architecture, and a name for your virtual machine. Then you select packages to install, such as Perl or Python. Next you configure the locale, time zone, firewall, and users for the virtual machine in addition to allocating memory and other configuration tasks. You can also specify files to upload into the virtual machine.


After completing the configuration, you use a Build command to produce the virtual machine in one or more specified formats, including a Microsoft Azure-ready image. An Upload link displays for you to move the prepared image into your Microsoft Azure account after the build process completes. Instructions are available to help you download a settings file that you then upload to your SUSE account. Then you specify the Microsoft Azure storage account into which you want the image transferred, and then click the link to go to the SUSE Studio’s dashboard where you click the Upload button to send your image to Microsoft Azure. After the upload completes, you follow the instructions for creating a virtual machine from the Virtual Machine Image Gallery. Your uploaded image displays on the My Images tab of the Images Gallery wizard.


For more information about limitations of Microsoft Azure images created by using SUSE Studio, see http://susestudio.com/help/use/windows-azure.html.


Uploading a Virtual Machine to Microsoft Azure

Whether you want to permanently run one of your on-premises virtual machines in Microsoft Azure or simply want to test a configuration outside of your production environment, you can upload a copy of that virtual machine as a page blob to your Microsoft Azure Storage account, as shown in Figure 4. You can even move the virtual machine back on-premises later if necessary. The VHD can be a sysprepped fixed disk VHD or a customized Linux image based on supported distributions.




Figure 4: Mobility of a VHD between On-Premises and Microsoft Azure

Uploading an Existing Windows Virtual Machine

If you are already using a Hyper-V virtual machine, you can upload the associated VHD file to Microsoft Azure and begin using the virtual machine from the cloud. If you are using VMware virtualization, you can use the System Center Virtual Machine Manager to convert a VMDK file to a VHD file or use Microsoft Virtual Machine Converter. Much like you do with a Microsoft Azure virtual machine, you generalize the operating system of your on-premises virtual machine by using the Sysprep utility. You launch the utility from the system32\sysprep directory in the Windows directory of the virtual machine. Then you select the Enter System Out-of-Box Experience (OOBE) action, select the Generalize check box, and select Shutdown as the Shutdown Option.

Next you must create a new storage account in the Microsoft Azure Management Portal if you do not have one already available. Click New, click Storage, and then click Quick Create. You need to supply a subdomain name as well as a location or affinity group, and choose whether to use geo-replication. You then use Microsoft Azure PowerShell cmdlets, Get-AzurePublishSettingsFile, Import- AzurePublishSettingsFile, and Add-AzureVhd, to upload the VHD file for your virtual machine to your storage account.


After the VHD is uploaded, you can go to the Virtual Machines page in the Microsoft Azure Management Portal, click the Images link above the list of virtual machines, and click Create to set up a new image based on your VHD. You must provide a name for the image, an optional description, the VHD location (which you can obtain by browsing your cloud storage accounts), and the operating system family (Windows, in this case).


For a complete list of steps to perform, refer to http://azure.microsoft.com/en- us/documentation/articles/virtual-machines-create-upload-vhd-windows-server/.


Uploading a Local Linux Virtual Machine

There are several steps required to prepare and upload a local Linux virtual machine and different steps required for different Linux distributions. At the conclusion of the preparation process, regardless of Linux version, you must install the Microsoft Azure Linux Agent. In addition, you must provision a Microsoft Azure storage account. In the Microsoft Azure Management Portal, click New, click Storage, and then click Quick Create. Next, type in a subdomain name, select a location or affinity group, and specify whether to


use geo-replication. Then just as you do for a Windows VHD, you use Microsoft Azure PowerShell cmdlets, Get-AzurePublishSettingsFile, Import-AzurePublishSettingsFile, and Add-AzureVhd, to upload the VHD file for your virtual machine to your storage account.


You can review the details for uploading a Linux virtual machine at http://azure.microsoft.com/en- us/documentation/articles/virtual-machines-linux-create-upload-vhd/.


Working with a Virtual Machine

The disk for the virtual machine’s operating system is limited to 127 GB. The virtual machine also has a disk allocated to temporary storage for data, but this data does not persist if the virtual machine is relocated to other hardware for any reason. Therefore, do not store data in this location if you cannot easily recreate it. These disks are assigned to the drive letters C and D, respectively. If necessary, you can add a data disk to increase your storage capacity and to hold additional applications that you want to install. You can assign any drive letter, other than C or D, to each data disk that you add.

Connecting to a Windows Virtual Machine

If the virtual machine is not currently running, you must first select it in the virtual machines list in the Microsoft Azure Management Portal and then click Start in the command bar at the bottom of the page. After the virtual machine is running, click the Connect button to generate the remote desktop connection file, click Open to use the file, and then click Connect to establish the connection to the virtual machine. Type in the administrator login name and password to authenticate, and then click Yes to verify the virtual machine’s identity. At this point, you can interact with the virtual machine in the same way you would use a local server.


Note: If your firewall has a rule that does not allow you to connect to the RDP port of your virtual machine, you may change the public port of your virtual machine’s endpoint.


Connecting to a Linux Virtual Machine

Start the virtual machine if it is not currently running. Then use an SSH client, such as PuTTy for a Windows client or OpenSSH for a Linux client, to connect to your virtual machine. To make this connection, you must know the host name and port for the virtual machine. You can get this information by clicking the virtual machine’s name in the Microsoft Azure Management Portal, clicking the Dashboard link, and then locating the SSH Details section in the lower right corner of the page. After connecting to the virtual machine, you can use it just like any other local server.


Attaching a Data Disk

If you need additional storage for your virtual machine, you can attach an empty disk or a VHD that you have preloaded with data. Select your virtual machine in the list of instances, click Attach in the command bar, and then click Attach Empty Disk or Attach Disk as appropriate. For an existing disk, you select the disk in storage and specify a Host Cache Preference option. For a new empty disk, a storage location and a file name are automatically assigned, but you can override the file name if you prefer. You must specify a size for the disk in gigabytes, and then select from one of the following Host Cache Preference options:

None. Host caching is disabled. This is the default setting for a data disk.

Read Only. Host caching is enabled only for read operations as a performance optimization.

Read Write. Host caching is enabled for both reads and writes. This is the default setting for an operating system disk.


When the disk is attached, you must next initialize the disk by using the Disk Management utility if you are using a Windows virtual machine, and then create a new simple volume. Once the volume is created, the disk is available for use by your applications. If you are using a Linux virtual machine, you use the fdisk command to create a new device and a new partition, create a file system on the new partition, add a directory, and then mount the drive.

You can review the steps to attach a data disk for either operating system at http://azure.microsoft.com/en-us/documentation/articles/storage-windows-attach-disk/.

Managing a Virtual Machine

 You have three options for managing virtual machines—the management portal, scripting, and the Rest API.


You can use the graphical interface of the Microsoft Azure Management Portal to perform various tasks related to managing your virtual machine. You can start and stop a virtual machine, connect to it, attach and detach disks, capture the VHD as an image, or delete the VHD. In addition, you can configure a different size for the virtual

machine, assign it to an availability set, or add new endpoints.

If you prefer, you can also download and install Microsoft Azure PowerShell cmdlets to use scripts for management tasks. Instructions are available at ⦁ http://azure.microsoft.com/en-us/documentation/articles/install-configure- ⦁ powershell/⦁ . As an example, you can use the ⦁ Add-AzureDataDisk cmdlet to add a new data disk to your virtual machine.

Another similar option is the CLI available for all platforms. You can learn more about the CLI for Windows, Linux, or Mac at ⦁ http://azure.microsoft.com/en-

us/documentation/articles/xplat-cli/.

You can use various language-specific SDKs to manage Microsoft Azure. See the language-specific Developer Centers documentation at http://azure.microsoft.com/en-us/documentation/⦁ .

Although the portal, PowerShell cmdlets, CLI, and language-specific SDKs all use common REST APIs behind the scenes, you can also access ⦁ Blob Service REST APIs directly if you prefer. With this API, you can manage the containers and blobs in your

Storage account, including uploading, downloading, or deleting your VHDs.