Bird
Raised Fist0
Azurecloud~5 mins

VM states (running, stopped, deallocated) in Azure - Commands & Configuration

Choose your learning style10 modes available
Introduction
Virtual machines (VMs) in Azure can be in different states that affect billing and availability. Understanding these states helps you manage costs and know when your VM is ready to use.
When you want to temporarily stop a VM but keep its resources reserved for quick restart.
When you want to stop a VM and avoid charges for compute resources by fully deallocating it.
When you need to check if a VM is running before connecting to it.
When you want to save costs by stopping VMs that are not in use.
When you want to restart a VM to apply updates or fix issues.
Commands
This command starts the VM named 'example-vm' in the resource group 'example-rg'. Starting a VM changes its state to running, making it ready to use.
Terminal
az vm start --resource-group example-rg --name example-vm
Expected OutputExpected
Starting VM 'example-vm'... Succeeded
→
--resource-group - Specifies the resource group where the VM exists
→
--name - Specifies the name of the VM to start
This command stops the VM but does not deallocate it. The VM state changes to stopped, but compute resources are still reserved and billed.
Terminal
az vm stop --resource-group example-rg --name example-vm
Expected OutputExpected
Stopping VM 'example-vm'... Succeeded
→
--resource-group - Specifies the resource group where the VM exists
→
--name - Specifies the name of the VM to stop
This command stops and deallocates the VM. The VM state changes to deallocated, releasing compute resources and stopping billing for them.
Terminal
az vm deallocate --resource-group example-rg --name example-vm
Expected OutputExpected
Deallocating VM 'example-vm'... Succeeded
→
--resource-group - Specifies the resource group where the VM exists
→
--name - Specifies the name of the VM to deallocate
This command retrieves the current state of the VM. The output shows if the VM is running, stopped, or deallocated.
Terminal
az vm get-instance-view --resource-group example-rg --name example-vm --query instanceView.statuses[1]
Expected OutputExpected
{ "code": "PowerState/running", "displayStatus": "VM running", "level": "Info", "time": null }
→
--resource-group - Specifies the resource group where the VM exists
→
--name - Specifies the name of the VM
→
--query - Filters the output to show only the VM power state
Key Concept

If you remember nothing else from this pattern, remember: stopping a VM keeps billing, deallocating a VM stops billing and frees resources.

Common Mistakes
Using 'az vm stop' expecting to stop billing for the VM.
Stopping a VM does not release compute resources, so billing continues.
Use 'az vm deallocate' to stop billing by releasing compute resources.
Trying to start a VM that is deallocated without specifying the resource group or name correctly.
The command fails because Azure cannot find the VM without correct identifiers.
Always specify the correct resource group and VM name with --resource-group and --name flags.
Assuming the VM is running without checking its state before connecting.
Connecting to a stopped or deallocated VM will fail because it is not available.
Use 'az vm get-instance-view' to check the VM state before connecting.
Summary
Use 'az vm start' to power on a VM and make it ready for use.
Use 'az vm stop' to stop a VM but keep billing active by reserving resources.
Use 'az vm deallocate' to stop billing by releasing the VM's compute resources.
Check VM state with 'az vm get-instance-view' to know if it is running, stopped, or deallocated.

Practice

(1/5)
1. What does the deallocated state mean for an Azure VM?
easy
A. The VM is off and resources are freed.
B. The VM is running and using resources.
C. The VM is off but still reserving resources.
D. The VM is paused but still running.

Solution

  1. Step 1: Understand VM states

    Azure VMs can be running, stopped, or deallocated. Running means active, stopped means off but resources reserved, deallocated means off and resources freed.
  2. Step 2: Identify deallocated meaning

    Deallocated means the VM is turned off and Azure releases the compute resources, so you don't pay for them.
  3. Final Answer:

    The VM is off and resources are freed. -> Option A
  4. Quick Check:

    Deallocated = off + freed resources [OK]
Hint: Deallocated means VM off and no resources reserved [OK]
Common Mistakes:
  • Confusing stopped with deallocated
  • Thinking deallocated still uses resources
  • Assuming deallocated means paused
2. Which Azure CLI command correctly stops a VM and releases its resources?
easy
A. az vm pause --name MyVM --resource-group MyGroup
B. az vm stop --name MyVM --resource-group MyGroup
C. az vm shutdown --name MyVM --resource-group MyGroup
D. az vm deallocate --name MyVM --resource-group MyGroup

Solution

  1. Step 1: Review Azure CLI commands for VM states

    To stop a VM but keep resources, use az vm stop. To stop and free resources, use az vm deallocate.
  2. Step 2: Identify command that releases resources

    az vm deallocate stops the VM and releases compute resources, matching the question.
  3. Final Answer:

    az vm deallocate --name MyVM --resource-group MyGroup -> Option D
  4. Quick Check:

    Deallocate command frees resources [OK]
Hint: Use 'deallocate' to stop VM and free resources [OK]
Common Mistakes:
  • Using 'stop' which keeps resources reserved
  • Confusing 'shutdown' with deallocate
  • Using non-existent 'pause' command
3. If an Azure VM is in the stopped state, what happens to billing for compute resources?
medium
A. Billing doubles due to stopped state overhead.
B. Billing stops immediately as VM is off.
C. Billing continues because resources are reserved.
D. Billing pauses but storage costs continue.

Solution

  1. Step 1: Understand billing for stopped VMs

    When a VM is stopped (not deallocated), compute resources are still reserved, so billing continues for compute.
  2. Step 2: Differentiate from deallocated state

    Only when VM is deallocated are compute resources freed and billing stops for compute.
  3. Final Answer:

    Billing continues because resources are reserved. -> Option C
  4. Quick Check:

    Stopped = billing continues [OK]
Hint: Stopped VMs still reserve resources and incur charges [OK]
Common Mistakes:
  • Assuming billing stops when VM is stopped
  • Confusing storage billing with compute billing
  • Thinking stopped means deallocated
4. You tried to start a VM but got an error because it is in the deallocated state. What should you do to fix this?
medium
A. Run az vm start to allocate and start the VM.
B. Run az vm stop to release resources first.
C. Run az vm restart to reset the VM state.
D. Run az vm deallocate again to confirm.

Solution

  1. Step 1: Understand VM start from deallocated

    A VM in deallocated state has no resources allocated. To use it, you must start it which allocates resources and powers it on.
  2. Step 2: Identify correct command to allocate and start

    az vm start allocates resources and powers on the VM, fixing the error.
  3. Final Answer:

    Run az vm start to allocate and start the VM. -> Option A
  4. Quick Check:

    Start command allocates resources [OK]
Hint: Use 'start' to allocate and power on deallocated VM [OK]
Common Mistakes:
  • Trying to stop or deallocate an already deallocated VM
  • Using restart which requires VM to be running
  • Not allocating resources before starting
5. You want to save costs by stopping your VM but keep its IP address and disk data intact. Which state should you use and why?
hard
A. Use running state but reduce VM size to save costs.
B. Use stopped state because it keeps resources reserved including IP and disks.
C. Use deallocated state because it frees all resources including IP address.
D. Use stopped state because it frees compute resources but keeps IP.

Solution

  1. Step 1: Understand resource reservation in stopped state

    When a VM is stopped (not deallocated), compute resources are reserved, so the IP address and disk data remain intact.
  2. Step 2: Compare with deallocated state

    Deallocated frees compute resources and may release dynamic IP addresses, so IP might change.
  3. Final Answer:

    Use stopped state because it keeps resources reserved including IP and disks. -> Option B
  4. Quick Check:

    Stopped = keep IP and disks reserved [OK]
Hint: Stopped keeps IP and disks; deallocated frees resources [OK]
Common Mistakes:
  • Choosing deallocated and losing IP address
  • Thinking stopped frees compute resources
  • Trying to save costs by resizing while running
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard