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

Jenkins

Pre-requisites 1. Install a Webserver https://gitlab.com/Azam-devops/webserver/-/blob/main/README.md Code for index.html https://gitlab.com/Azam-devops/webserver 2. Maven Code https://gitlab.com/Azam-devops/imperial-maven-project 1. Install & configure Jenkins Automation Server on Linux Vm. 2. Go through at some of the important options in Jenkins. 3. Manage Jenkins. 4. Plugins 5. Global Tools Configuration. 6. Credentials 7. Users 8. Slave Nodes 9. Configuring CI pipeline using Gitlab. 10. Configuring standalone CICD pipeline using. 11. Automating the CICD pipeline. 12. Jenkins log 13. Introduction to Jenkins file. 14. Basic groovy syntax & file formation. 15. Launching a Pipeline using Jenkins file. 3. DevOps Architecture Description of above DevOps plan. Create Maven based source code in Gitlab. Create a Jenkins job which will execute below stages. Checkout code from Gitlab Build/compile the source code using Maven as a build tool. scan the code virtually. Test...

Docker In Details

  Course Contents:- 1. Overview of Docker 2. Difference between Virtualization & Containerization 3. Installation & Configuration of Docker Runtime on Linux & Windows 4. Practice on Docker commands 5. launch a Webserver in a container 6. Launch public & official images of application like Jenkins, Nginx, DB etc.. 7. Launch a base OS Container 8. How to save changes inside the container & create a fresh image(commit) 9. How to ship image & container from one hardware to another. 10. How to remove stop/rm multiple container/images 11. Docker Registry 12. Docker Networking       Check current docker network                  Docker Network Bridge                     Docker Network Weaving                  Launch our own Docker Cluster with our defined Network             ...

Ansible

  Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks. Platform support Control machines have to be a Linux/Unix host (for example SUSE Linux Enterprise, Red Hat Enterprise Linux, Debian, CentOS, macOS, BSD, Ubuntu, and Python 2.7 or 3.5 is required. Managed nodes, if they are Unix-like, must have Python 2.4 or later. For managed nodes with Python 2.5 or earlier, the python-simplejson package is also required. Since version 1.7, Ansible can also manage Windows nodes. In this case, native PowerShell remoting supported by the WS-Managemen...

Basic Linux Commands

  Linux Command Cheat Sheet Hello All, Below are the most common commands used in a day to day life of  linux user. if you are new to linux i will recommend you to go through all of the commands.  this commands will help you to troubleshoot linux issues.   Command Description ls Lists all files and directories from present working directory ls-R Lists files in sub-directories ls-a to list down hidden files. ls-al Lists files and directories with complete details like permissions, size, owner cd or cd ~ To go back to home directory cd .. Move one level up cd To change to a particular directory cd / Move to the root directory cat > filename Creates a new file cat filename Displays the content of a file cat file...

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...