Skip to main content

Attach Disks to Azure VM

 

Attach Disks to VM

Add a data disk in Windows/Linux

  1. Go to azure portal. In the menu on the left, click Virtual Machines.
  2. Select the virtual machine from the list.
  3. On the virtual machine blade, click Disks.
    1. On the Disks blade, click + Add data disk.

  4. In the drop-down for the new disk, select Create disk.

  5. In the Create managed disk blade, type in a name for the disk(Name should be similar to the name of the disk which is already present) and adjust the other settings as necessary. When you are done, click Create. We can add only 1 TB disk at a time, if we want to add more TB's we have to add more number of disks.

  6. In the Disks blade, click save to save the new disk configuration for the VM.

  7. After Azure creates the disk and attaches it to the virtual machine, the new disk is listed in the virtual machine's disk settings under Data Disks.

Initialize a new data disk in Windows

  1. Connect to the VM.
  2. Click the start menu inside the VM and type diskmgmt.msc and hit Enter. This will start the Disk Management snap-in.
  3. Disk Management will recognize that you have a new, un-initialized disk and the Initialize Disk window will pop up.
  4. Make sure the new disk is selected and click OK to initialize it.
  5. The new disk will now appear as unallocated. Right-click anywhere on the disk and select New simple volume. The New Simple Volume Wizard will start.
  6. Go through the wizard, keeping all of the defaults, when you are done select Finish.
  7. Close Disk Management.
  8. You will get a pop-up that you need to format the new disk before you can use it. Click Format disk.
  9. In the Format new disk dialog, check the settings and then click Start.
  10. You will get a warning that formatting the disks will erase all of the data, click OK.
  11. When the format is complete, click OK.

Initialize a new data disk in Linux

  1. SSH to your VM using Putty.

2.      Next you need to find the device identifier for the data disk to initialize. There are two ways to do that:

a) Grep for SCSI devices in the logs, such as in the following command:
bash

sudo grep SCSI /var/log/messages

For recent Ubuntu distributions, you may need to use sudo grep SCSI /var/log/syslog because logging to /var/log/messages might be disabled by default.

You can find the identifier of the last data disk that was added in the messages that are displayed.

OR

b) Use the lsscsi command to find out the device id. lsscsi can be installed by either yum install lsscsi (on Red Hat based distributions) or apt-get install lsscsi (on Debian based distributions). You can find the disk you are looking for by its lun or logical unit number. For example, the lun for the disks you attached can be easily seen from azure vm disk list <virtual-machine> as:
Azure CLI

azure vm disk list myVM

The output is similar to the following:
Azure CLI

info:    Executing command vm disk list
+ Fetching disk images
+ Getting virtual machines
+ Getting VM disks
data:    Lun  Size(GB)  Blob-Name                         OS
data:    ---  --------  --------------------------------  -----
data:         30        myVM-2645b8030676c8f8.vhd  Linux
data:    0    100       myVM-76f7ee1ef0f6dddc.vhd
info:    vm disk list command OK

Compare this data with the output of lsscsi for the same sample virtual machine:
bash

·         [1:0:0:0]    cd/dvd  Msft     Virtual CD/ROM   1.0   /dev/sr0
·         [2:0:0:0]    disk    Msft     Virtual Disk     1.0   /dev/sda
·         [3:0:1:0]    disk    Msft     Virtual Disk     1.0   /dev/sdb
·         [5:0:0:0]    disk    Msft     Virtual Disk     1.0   /dev/sdc

·         The last number in the tuple in each row is the lun. See man lsscsi for more information.

·         At the prompt, type the following command to create your device:
bash

·         sudo fdisk /dev/sdc (make sure you use the correct new disk name here)

·         When prompted, type n to create a partition.

 

·         When prompted, type p to make the partition the primary partition. Type 1 to make it the first partition, and then type enter to accept the default value for the cylinder. On some systems, it can show the default values of the first and the last sectors, instead of the cylinder. You can choose to accept these defaults.

 

·         Type p to see the details about the disk that is being partitioned.

 

·         Type w to write the settings for the disk.

 

·         Now you can create the file system on the new partition. Append the partition number to the device ID (in the following example /dev/sdc1). The following example creates an ext4 partition on /dev/sdc1:
bash

·         sudo mkfs -t ext4 /dev/sdc1 (make sure you use the correct new device name here)
·          

 

Note

SuSE Linux Enterprise 11 systems only support read-only access for ext4 file systems. For these systems, it is recommended to format the new file system as ext3 rather than ext4.

·         Make a directory to mount the new file system, as follows:
bash

·         sudo mkdir /datadrive (For every data disk there will be a separate mount directory to be created)
  •  

·         Finally you can mount the drive, as follows:
bash

·         sudo mount /dev/sdc1 /datadrive

·         The data disk is now ready to use as /datadrive.

 

·         Add the new drive to /etc/fstab:

To ensure the drive is remounted automatically after a reboot it must be added to the /etc/fstab file. In addition, it is highly recommended that the UUID (Universally Unique IDentifier) is used in /etc/fstab to refer to the drive rather than just the device name (i.e. /dev/sdc1). Using the UUID avoids the incorrect disk being mounted to a given location if the OS detects a disk error during boot and any remaining data disks then being assigned those device IDs. To find the UUID of the new drive, you can use the blkid utility:
bash

sudo -i blkid

The output looks similar to the following example:
bash

/dev/sda1: UUID="11111111-1b1b-1c1c-1d1d-1e1e1e1e1e1e" TYPE="ext4"
/dev/sdb1: UUID="22222222-2b2b-2c2c-2d2d-2e2e2e2e2e2e" TYPE="ext4"
/dev/sdc1: UUID="33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e" TYPE="ext4"
Note

Improperly editing the /etc/fstab file could result in an unbootable system. If unsure, refer to the distribution's documentation for information on how to properly edit this file. It is also recommended that a backup of the /etc/fstab file is created before editing.

Next, open the /etc/fstab file in a text editor:
bash

sudo vi /etc/fstab

In this example, we use the UUID value for the new /dev/sdc1 device that was created in the previous steps, and the mountpoint /datadrive. Add the following line to the end of the /etc/fstab file:
sh

UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e   /datadrive   ext4   defaults,nofail   1   2

Or, on systems based on SuSE Linux you may need to use a slightly different format:
sh

/dev/disk/by-uuid/33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e   /datadrive   ext3   defaults,nofail   1   2
Note

The nofail option ensures that the VM starts even if the filesystem is corrupt or the disk does not exist at boot time. Without this option, you may encounter behavior as described in Cannot SSH to Linux VM due to FSTAB errors.

You can now test that the file system is mounted properly by unmounting and then remounting the file system, i.e. using the example mount point /datadrive created in the earlier steps:
bash

sudo umount /datadrive
sudo mount /datadrive

If the mount command produces an error, check the /etc/fstab file for correct syntax. If additional data drives or partitions are created, enter them into /etc/fstab separately as well.

Make the drive writable by using this command:
bash

1.  sudo chmod go+w /datadrive
2.       Note

Subsequently removing a data disk without editing fstab could cause the VM to fail to boot. If this is a common occurrence, most distributions provide either the nofail and/or nobootwait fstab options that allow a system to boot even if the disk fails to mount at boot time. Consult your distribution's documentation for more information on these parameters.


Thank you !! Example HTML page Pleaes provide your valuable feedback.

Comments

Popular posts from this blog

Script To Monitor disk Usage

Hello All, Many times we have a requirement to automate few of the tasks, and one of the important task is to delete old log files from log destination. We usually get the conditions where we have to delete the log from particular directory when it reaches to some thresh hold value. Now a day the requirement of automation is highly increased where we are seeing most of the day to day tasks are getting automated using different scripting languages. Its always a good idea to automate your daily tasks which will save your working hours and will increase your productivity. Most of the time log destination gets full and due to which we face other issues like application down or particular service stop working. And manual deleting of log is hectic process so below script will help you to delete your log data when it meets your condition, and also it will trigger mail to recipient after deletion of logs. You can schedule this script in your crontab according to your feasible ti...

Connect SparkThriftServer with Tableau/PowerBI

  Connect SparkThriftServer with Tableau/PowerBI REFERENCE : https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-apache-spark-use-bi-tools Use Power BI for Spark data visualization Note This section is applicable only for Spark 1.6 on HDInsight 3.4 and Spark 2.0 on HDInsight 3.5.   Once you have saved the data as a table, you can use Power BI to connect to the data and visualize it to create reports, dashboards, etc.   1.       Make sure you have access to Power BI. You can get a free preview subscription of Power BI from http://www.powerbi.com/ . 2.       Sign in to Power BI . 3.       From the bottom of the left pane, click Get Data . 4.       On the Get Data page, under Import or Connect to Data , for Databases , click Get . 5.       On the next screen, click Spark on Azure HDInsight and then click Connect . When prompted, enter th...

Azure Storage

Azure Storage is Microsoft's cloud storage solution for modern data storage scenarios.    Why Azure Storage: Durable and Highly Available: ·        Data is safe during hardware failure. ·        Replicate data across data centres. ·        In local catastrophe or natural disaster data replicated to other data centres remains highly available. Secure: ·        Data encrypted by Azure service Storage Service encryption (SSE) for data at rest. ·        Completed control over who access your data. Scalable: ·        Designed to massive scale. Managed: ·        Azure handles maintenance, updates and critical issues. Accessible: ·        Accessible from anywhere in the world. ·        You can access using http, https,...

Azure Active Directory

  What is Azure Active Directory? Azure Active Directory is Microsoft’s multi-tenant, cloud-based directory and identity management service. For an organization, Azure AD helps employees sign up to multiple services and access them anywhere over the cloud with a single set of login credentials. Azure Active Directory Concept: It is important to understand these Azure AD concepts. Identity . An object that can get authenticated. An identity can be a user with a username and password. Account . An identity that has data associated with it. You can't have an account without an identity. Azure subscription . Used to pay for Azure cloud services. You can have many subscriptions and they're linked to a credit card. Azure tenant/directory . A dedicated and trusted instance of Azure AD, a Tenant is automatically created when your organization signs up for a Microsoft cloud service subscription. More instances of Azure AD can be created. Azure AD is the underlying product ...

Kubernetes-Update

                                                    https://kubernetes.io/ Kubernetes (K8s)  is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon  15 years of experience of running production workloads at Google , combined with best-of-breed ideas and practices from the community. Latest Verion:-  1.19 Kubernetes Objects Kubernetes defines a set of building blocks ("primitives"), which collectively provide mechanisms that deploy, maintain, and scale applications based on CPU, memory or custom metrics. Kubernetes is loosely coupled and extensible to meet different workloads. This extensibility is provided in large part by the Kubernetes API, which is used by int...