Attaching a disk in Azure VM for offline repair is a straightforward process that can be completed in a few steps.
First, you need to ensure that the disk you want to attach is a managed disk, which can be created in the Azure portal or through the Azure CLI.
To initiate the repair process, you'll need to boot your VM from a rescue image, which can be done by attaching the managed disk to a new VM, then booting from the rescue image.
You can use the Azure CLI command `az vm boot-diagnostics set` to set the boot diagnostics for your VM, allowing you to access the console output and repair the disk.
Prerequisites
Before you start attaching disks to your Azure VM, it's essential to consider a few prerequisites.
The size of your virtual machine is a crucial factor in determining how many data disks you can attach. For accurate information, check out the Sizes for virtual machines section.
Make sure you're aware of these limitations to avoid any issues during the disk attachment process.
Existing VM Options
To attach an existing disk to your Azure VM, you can use the Disks pane in the Azure portal. Select Attach existing disks under Data disks to get started.
You can also use the az vm disk attach command to attach an existing disk. To do this, you'll need to find the disk ID and pass it to the command.
The disk ID can be found by querying for a disk named myDataDisk in myResourceGroup, for example. Once you have the ID, you can attach the disk to the VM named myVM using the az vm disk attach command.
New
When creating a new data disk for a VM, you can choose between attaching a new disk or attaching an existing one.
To attach a new disk, you can use the az vm disk attach command with the --new parameter. This will create a new, empty data disk on your VM.
You can also create a new disk through the Azure portal. On the Disks pane, under Data disks, select Create and attach a new disk. Then, enter a name for your managed disk and review the default settings. Update the Storage type, Size (GiB), Encryption, and Host caching as necessary. When you're done, select Save to create the managed disk and update the VM configuration.
If your VM is in an Availability Zone, the disk is automatically created in the same zone as the VM.
You can also add a new disk directly from the virtual machine's overview page. Locate the “Disks” section and click on “Attach new” to add a new disk.
Create Repair VM
Creating a repair VM is an essential step in maintaining the health of your virtual machines. To create a repair VM with an unmanaged OS disk, you'll need to begin the process of creating a new VM in the Azure portal.
Select Windows Server 2019 as the base image for your repair VM, and ensure that the OS disk is unmanaged. You can do this by expanding the Advanced options on the Disks page and clearing the Use managed disks checkbox.
A storage account will be required for the unmanaged OS disk. Make sure to select a storage account and do not attach an existing disk. If the Use managed disks option is grayed out, you can try creating the VM using Azure CLI commands.
Here are the steps to create a VM with an unmanaged disk using Azure CLI:
Complete the "Create a Virtual Machine" wizard by specifying configuration details that are appropriate for your organization.
A Copy of the Unmanaged
A copy of the unmanaged disk can be attached to a repair VM in the Azure portal.
To do this, you'll need to open the Disks blade for the new repair VM.
You'll select + Add data disk, and then choose Existing blob as the Source type.
Next, you'll select Browse to locate the OS disk copy that you created earlier.
Accept the default storage blob name, and then select OK.
Finally, save the changes on the Disks blade of the new repair VM.
Access Linux VM
To access your Linux VM, you'll need to connect to it via SSH. This can be done with the public IP address of your VM, such as 10.123.123.25, and the username azureuser.
If you're using an existing disk that contains data, you should skip to mounting the disk. The instructions for partitioning and formatting the disk will delete data on the disk.
File Metadata
File metadata is a crucial aspect to consider when working with virtual machines. It's essentially a set of data that provides information about a file, such as its name, size, and creation date.
VMware Fusion, for instance, allows you to view and edit file metadata, including the file's attributes and permissions. This can be especially useful when troubleshooting or managing large collections of files.
When it comes to file metadata, it's essential to understand that it can be used to identify and track changes to files over time. This can be particularly useful for auditing and compliance purposes.
VMware Fusion, for example, stores file metadata in a hidden folder within the virtual machine's file system. This allows you to access and manage file metadata even when the virtual machine is powered off.
Find the
To find the disk in your VM, you can use the command lsblk to list the disks. This will show you a list of available disks, including their sizes.
If you're not sure which disk is the one you want, you can check the LUN number on the VM page in the portal. This will match the last number of the HTCL portion of the lsblk output.
You can also list the contents of the /dev/disk/azure/scsi1 directory to see the available disks. This will show you the disk you want, based on its size or LUN number.
Accessing the VM
To access your Linux VM, you'll need to SSH into it. SSH into your VM using the public IP address, such as 10.123.123.25, and the username azureuser.
The username azureuser is the one you'll use to connect. For more information on using SSH with Linux on Azure, see the relevant documentation.
You can use the public IP address of your VM to connect. This will allow you to access the VM's command line interface.
Frequently Asked Questions
How to add disk space in Azure VM?
To add disk space in Azure VM, navigate to the Azure portal, select the disk you want to expand, and then choose a larger size under Size + performance. This simple process allows you to increase storage capacity for your virtual machine.
Sources
- https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/windows/unmanaged-disk-offline-repair
- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/attach-disk-portal
- https://medium.com/@subhampradhan966/efficiently-attach-and-permanently-mount-additional-disks-in-azure-virtual-machines-b5f40110f372
- https://github.com/Huachao/azure-content/blob/master/articles/virtual-machines/virtual-machines-linux-how-to-attach-disk.md
- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/add-disk
Featured Images: pexels.com