Attach Disks to VM
Add a data disk in
Windows/Linux
- Go to azure portal. In the menu on the left,
click Virtual Machines.
- Select the virtual machine from the list.
- On the virtual machine blade, click Disks.
- On the Disks blade,
click + Add data disk.
- In the drop-down for the new disk, select Create
disk.
- 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.
- In the Disks blade, click
save to save the new disk configuration for the VM.
- 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
- Connect to the VM.
- Click the start menu inside the VM and type diskmgmt.msc and
hit Enter. This will start the Disk Management
snap-in.
- Disk Management will recognize that you have a new,
un-initialized disk and the Initialize Disk window will pop up.
- Make sure the new disk is selected and click OK to
initialize it.
- 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.
- Go through the wizard, keeping all of the defaults,
when you are done select Finish.
- Close Disk Management.
- You will get a pop-up that you need to format the new
disk before you can use it. Click Format disk.
- In the Format new disk dialog,
check the settings and then click Start.
- You will get a warning that formatting the disks will
erase all of the data, click OK.
- When the format is complete, click OK.
Initialize a new
data disk in Linux
- 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.
Comments
Post a Comment