Azure's Linux virtual machine will default to a temporary disk, the normal device name is/DEV/SDB, but because the device recognition order is random, so when the reboot, the temporary disk device name may not be/dev/sdb, then waagent is how to/dev/ SDB hung under the/mnt/resource.
Waagent related code is in the/usr/lib/python2.7/site-packages/azurelinuxagent directory (detailed analysis of the process will not repeat here). We go into the Resourcedisk subdirectory, find the default.py file, look at the Activate_resource_disk method, and we see a temporary disk mount by calling the Mount_resource_disk method:
def activate_resource_disk (self):
Logger.info ("Activate resource Disk")
Try
Mount_point = Conf.get_resourcedisk_mountpoint ()
Mount_point = Self.mount_resource_disk (mount_point)
Warning_file = Os.path.join (Mount_point,
Dataloss_warning_file_name)
Try
Fileutil.write_file (Warning_file, data_loss_warning)
Except IOError as E:
Logger.warn ("Failed to write data loss warning:{0}", E)
Return Mount_point
Except Resourcediskerror as E:
Logger.error ("Failed to mount resource disk {0}", e)
Add_event (Name=agent_name, Is_success=false, Message=ustr (e),
Op=walaeventoperation.activateresourcedisk)
We continue to view the Mount_resource_disk method in this file, and we can see that the device name is obtained in the Device_for_ide_port method:
def mount_resource_disk (self, mount_point):
device = Self.osutil.device_for_ide_port (1)
If device is None:
Raise Resourcediskerror ("Unable to detect disk topology")
device = "/dev/{0}". Format (Device)
Partition = device + "1"
Mount_list = Shellutil.run_get_output ("mount") [1]
existing = Self.osutil.get_mount_point (mount_list, device)
If existing:
Logger.info ("Resource disk [{0}] is already mounted [{1}]",
Partition
Existing
Return existing
The method in the Osutil namespace is referenced at the beginning of the file:
From Azurelinuxagent.common.osutil import Get_osutil
And the Self.osutil attribute is established in the constructor:
def __init__ (self):
Self.osutil = Get_osutil ()
Self.fs = Conf.get_resourcedisk_filesystem ()
Then we go to/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil to view the corresponding source code default.py file, find Device_for_ide_ Port This method:
def device_for_ide_port (self, port_id):
"""
Return device name attached to IDE port ' n '.
"""
If port_id > 3:
Return None
G0 = "00000000"
If port_id > 1:
G0 = "00000001"
port_id = Port_id-2
device = None
Path = "/sys/bus/vmbus/devices/"
If Os.path.exists (path):
For VMBus in Os.listdir (path):
DeviceID = Fileutil.read_file (os.path.join (Path, VMBus, "device_id"))
GUID = Deviceid.lstrip (' {'). Split ('-')
If guid[0] = = G0 and guid[1] = = "+ USTR (port_id):
For Root, dirs, the files in Os.walk (path + vmbus):
If Root.endswith ("/block"):
device = Dirs[0]
Break
else: #older distros
For D in dirs:
If ': ' in D and ' blocks ' = = D.split (': ') [0]:
device = D.split (': ') [1]
Break
Break
return device
It looks messy, and we see in the logic that the GUID starts with 00000000, and the second part of the GUID is 0001 (note that port_id in the front parameter is 1, so according to guid[1] = = "+ ustr" (port_id) Judging by the condition of 0001) a blockid, let's look at the following qualifying Blockid under/sys/bus/vmbus/devices/:
Navigate to this ID:
00000000-0001-8899-0000-000000000000
Based on this, we simplified the Device_for_ide_port method to run the following script on this machine: import OS
Path = "/sys/bus/vmbus/devices/"
VMBus = "00000000-0001-8899-0000-000000000000"
For Root, dirs, the files in Os.walk (path + vmbus):
If Root.endswith ("/block"):
Root
Dirs
Break
Run out of the results:
Can see that is from the/sys/bus/vmbus/devices/00000000-0001-8899-0000-000000000000/host5/target5:0:1/5:0:1:0/ Block this directory read the directory SDB, this directory is the temporary disk of the device name.