How to Initialize attached Data disk to Linux VM in Azure with Powershell

Bitchiko Tchelidze 1 Reputation point
2023-03-22T09:24:19.2733333+00:00

The Initialize the disk doc explains how to initialize an attached disk for Windows VM. I need to do the same for Linux VM with Powershell. Any resource available ?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,164 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
573 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,086 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 13,165 Reputation points
    2023-03-22T10:37:12.9133333+00:00

    Unfortunately, PowerShell is not the ideal tool to initialize and manage disks on a Linux VM, as PowerShell is designed primarily for managing Windows systems. Instead, you can use common Linux tools like fdisk, parted, and mkfs to perform disk operations on a Linux VM.

    However, PowerShell Core, a cross-platform version of PowerShell, is available for Linux, but it doesn't come with cmdlets specifically designed for managing Linux disks.

    Here's a general outline of the steps you need to follow to initialize an attached disk on a Linux VM using Linux commands:

      1. Identify the new disk: Use the lsblk or fdisk -l command to list all available disks and identify the new disk (e.g., /dev/sdb).
        lsblk
            
        
        or 
        
        
       
        sudo fdisk -l
            
        
        
    
    
    1. Create a partition on the new disk: Use fdisk or parted to create a new partition on the disk. For example, using fdisk:
    sudo fdisk /dev/sdb
    
    

    Follow the interactive prompts to create a new partition. Typically, you'll press 'n' for a new partition, choose the partition type, and accept the default values for the first and last sectors.

    1. Format the partition: Format the new partition with the desired filesystem (e.g., ext4).
    sudo mkfs.ext4 /dev/sdb1
    
    

    Replace /dev/sdb1 with the correct partition name.

    1. Mount the partition: Create a mount point for the new partition and mount it.
    sudo mkdir /mnt/my_new_disk
    sudo mount /dev/sdb1 /mnt/my_new_disk
    
    
    1. Update /etc/fstab: To make sure the new partition is mounted automatically after a reboot, add an entry to the /etc/fstab file.
    sudo nano /etc/fstab
    
    

    Add a line similar to the following:

    /dev/sdb1 /mnt/my_new_disk ext4 defaults 0 0
    
    

    Save the file and exit the editor.

    These steps should help you initialize and mount an attached disk on a Linux VM using Linux commands. If you want to manage Linux systems remotely, you can use tools like SSH, Ansible, or other remote management tools that are designed for Linux environments.

    0 comments No comments