说明:这是很多年前的基于txt文档的操作记录,需要重新导入SR的具体原因早已不记得,下文仅涉及导入操作的技术要点。
XenServer与虚拟机相关的对象一般都存储在Storage Repository(后文简称SR)里面的,一个SR可以是用于存放VM虚拟磁盘的,也可能是用于存放ISO文件。然后,Host本机挂载的可移动存储(光驱、USB)也是以SR对象形式存在的。
先枚举当前SR和PBD列表,相关命令:xe sr-list及xe pbd-list
[[email protected] ~]# xe sr-list uuid ( RO) : 640b1256-8896-7730-b164-52e4b3671b04 name-label ( RW): Removable storage name-description ( RW): host ( RO): xenmbr type ( RO): udev content-type ( RO): disk uuid ( RO) : dba2c892-2954-486f-942b-53b30b12895e name-label ( RW): XenServer Tools name-description ( RW): XenServer Tools ISOs host ( RO): xenmbr type ( RO): iso content-type ( RO): iso uuid ( RO) : 2df9c74a-303f-6247-cd24-4b20dea67730 name-label ( RW): DVD drives name-description ( RW): Physical DVD drives host ( RO): xenmbr type ( RO): udev content-type ( RO): iso [[email protected] ~]# xe pbd-list uuid ( RO) : ebdf1144-3516-f623-122b-15895d07e24f host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 2df9c74a-303f-6247-cd24-4b20dea67730 device-config (MRO): location: /dev/xapi/cd currently-attached ( RO): true uuid ( RO) : 32a00247-3b74-94e1-666e-4f092d453edd host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): dba2c892-2954-486f-942b-53b30b12895e device-config (MRO): location: /opt/xensource/packages/iso; legacy_mode: true currently-attached ( RO): true uuid ( RO) : 4c701025-305e-b3bf-1577-643ef80cf717 host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 640b1256-8896-7730-b164-52e4b3671b04 device-config (MRO): location: /dev/xapi/block currently-attached ( RO): true
在标题中已提供的信息是本次操作是针对LVM类型的SR,故可以通过LVM相关命令来确认PV/VG/LV三类信息,其中PV需要提取提的信息是SR的UUID及实际物理设备,PV/VG则用于双重确认需要操作的存储对象是否正确,LV则可第三次确认操作对象是否正确,因为LV就是早前创建(存在)的VDI虚拟磁盘对象,若是尚有印象目标SR上有过哪些大小的虚拟磁盘不就可以用来反向确认SR么?
[[email protected] ~]# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd PV Size 387.91 GB / not usable 6.47 MB Allocatable yes PE Size (KByte) 4096 Total PE 99303 Free PE 68518 Allocated PE 30785 PV UUID Pg2OhF-F1W9-TppY-vhkA-TKyb-4viY-sPtqPe [[email protected] ~]# vgdisplay --- Volume group --- VG Name VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 10 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 387.90 GB PE Size 4.00 MB Total PE 99303 Alloc PE / Size 30785 / 120.25 GB Free PE / Size 68518 / 267.65 GB VG UUID z9AOrV-LDu2-Xz7i-ZBQJ-s3qR-DUAc-D8tTEK [[email protected] ~]# lvdisplay --- Logical volume --- LV Name /dev/VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd/VHD-ac56e8c6-c2fe-4c7f-bab7-15d0bbc9039c VG Name VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd LV UUID qLMwFl-jm0U-haXg-6e2c-5gH1-1vRO-WBnScY LV Write Access read/write LV Status NOT available LV Size 20.05 GB Current LE 5132 Segments 1 Allocation inherit Read ahead sectors auto --- Logical volume --- LV Name /dev/VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd/MGT VG Name VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd LV UUID 2UoSNK-1bNJ-XZWb-c8UE-4qNi-ZB6M-YADFCT LV Write Access read/write LV Status NOT available LV Size 4.00 MB Current LE 1 Segments 1 Allocation inherit Read ahead sectors auto --- Logical volume --- LV Name /dev/VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd/VHD-a5eb5cfa-9090-436d-bce6-de7294021c71 VG Name VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd LV UUID Iqx7L9-mcK1-21VB-ZXJ2-CbKr-c2z0-dD4Hda LV Write Access read/write LV Status NOT available LV Size 100.20 GB Current LE 25652 Segments 1 Allocation inherit Read ahead sectors auto
上面输出中
- PV Name就是物理设备(磁盘)对象(/dev/sda3)
- VG Name(VG_XenStorage-8397b362-1b90-123f-4b1a-b6f0e0e79bdd)后面的长串字符就是SR的UUID(8397b362-1b90-123f-4b1a-b6f0e0e79bdd)了
- LV Name中VHD-开头的则是VDI虚拟磁盘,类似的后面的长串字符也是VDI的UUID(ac56e8c6-c2fe-4c7f-bab7-15d0bbc9039c & a5eb5cfa-9090-436d-bce6-de7294021c71)
- LV Size就是VDI虚拟磁盘的大小了
导入过程主要步骤
- 查找设备ID
- 探测SR metadata信息
- 导入SR
- 连接SR
查找设备ID
为什么要找设备ID呢?
这个问题与DNS-IP的关系有点类似,DNS是为了方便记忆,但是实际的会话过程还是需要落到实际IP而不是DNS。那么从操作系统来讲,设备名命名只是方便阅读而已,而为了保证准确性,系统认的可是设备ID,因为设备名可能有冲突,而设备ID则一般不会重复的。而存储设备一般使用SCSI ID来标识,所以需要查找的是SCSI ID而不是Device Name。
[[email protected] ~]# ll /dev/disk/by-id/ total 0 lrwxrwxrwx 1 root root 9 May 21 12:19 scsi-3600605b002e3f320172790001a2ad4c1 -> ../../sda lrwxrwxrwx 1 root root 10 May 21 12:19 scsi-3600605b002e3f320172790001a2ad4c1-part1 -> ../../sda1 lrwxrwxrwx 1 root root 10 May 21 12:19 scsi-3600605b002e3f320172790001a2ad4c1-part2 -> ../../sda2 lrwxrwxrwx 1 root root 10 May 21 12:19 scsi-3600605b002e3f320172790001a2ad4c1-part3 -> ../../sda3 #从输出可以看到sda3的设备ID是scsi-3600605b002e3f320172790001a2ad4c1-part3,将这个记录下来,下一步需要使用到
探测SR metadata信息
使用xe sr-probe命令来探测物理设备的SR metadata,如下
[[email protected] ~]# xe sr-probe type=lvm device-config:device=/dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3 <?xml version="1.0" ?> <SRlist> <SR> <UUID> 8397b362-1b90-123f-4b1a-b6f0e0e79bdd </UUID> <Devlist> /dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3 </Devlist> </SR> </SRlist> #可以看到这个设备是XenServer的SR,UUID为8397b362-1b90-123f-4b1a-b6f0e0e79bdd,设备只有一个/dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3
导入SR
在上一步已经成功检测出SR,下一步就是导入,使用xe sr-introduce命令,下文中的uuid、content-type、type和name-label全部为必须的输入参数
[[email protected] ~]# xe sr-introduce uuid=8397b362-1b90-123f-4b1a-b6f0e0e79bdd content-type=user type=lvm name-label=intrlvm 8397b362-1b90-123f-4b1a-b6f0e0e79bdd #如果成功会回显SR的uuid #可以后续用xe sr-list及xe sr-param-list来确认新导入的SR信息 [[email protected] ~]# xe sr-list uuid ( RO) : 640b1256-8896-7730-b164-52e4b3671b04 name-label ( RW): Removable storage name-description ( RW): host ( RO): xenmbr type ( RO): udev content-type ( RO): disk uuid ( RO) : 8397b362-1b90-123f-4b1a-b6f0e0e79bdd name-label ( RW): intrlvm name-description ( RW): host ( RO): <not in database> type ( RO): lvm content-type ( RO): user #此时host字段显示not in database是正常的,plug pbd后方可显示 uuid ( RO) : dba2c892-2954-486f-942b-53b30b12895e name-label ( RW): XenServer Tools name-description ( RW): XenServer Tools ISOs host ( RO): xenmbr type ( RO): iso content-type ( RO): iso uuid ( RO) : 2df9c74a-303f-6247-cd24-4b20dea67730 name-label ( RW): DVD drives name-description ( RW): Physical DVD drives host ( RO): xenmbr type ( RO): udev content-type ( RO): iso [[email protected] ~]# xe sr-param-list uuid=8397b362-1b90-123f-4b1a-b6f0e0e79bdd uuid ( RO) : 8397b362-1b90-123f-4b1a-b6f0e0e79bdd name-label ( RW): intrlvm name-description ( RW): host ( RO): <not in database> allowed-operations (SRO): forget; VDI.create; VDI.snapshot; plug; update; destroy; VDI.destroy; scan; VDI.clone; VDI.resize; unplug current-operations (SRO): VDIs (SRO): PBDs (SRO): virtual-allocation ( RO): 0 physical-utilisation ( RO): -1 physical-size ( RO): -1 type ( RO): lvm content-type ( RO): user shared ( RW): false introduced-by ( RO): <not in database> other-config (MRW): sm-config (MRO): blobs ( RO): local-cache-enabled ( RO): false tags (SRW): #PBDs字段无值是正常的
连接SR
前面已经导入了SR,但是还不能正常使用,为何呢?
这个过程可以这样类比,假设有个移动硬盘,已经接到了电脑上,但是操作系统禁止自动挂载硬盘分区,所以需要手动将硬盘分区挂载到OS里才能使用。
还很绕么?那可以直接理解为移动硬盘的数据线还没接到电脑上。
连接SR的过程,其实就是创建PBD并Plug in PBD
使用xe pbd-create来创建pbd,使用xe pbd-plug来连接pbd
[[email protected] ~]# xe pbd-create sr-uuid=8397b362-1b90-123f-4b1a-b6f0e0e79bdd host-uuid=074ff44e-4d73-47ee-8b72-b17514180cfd device-config:device=/dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3 39712cc2-611a-1f17-b4c2-8d67c41d2456 #如果操作成功会回显PBD的uuid #接下来可以用xe pbd-list来确认新创建的pbd [[email protected] ~]# xe pbd-list uuid ( RO) : ebdf1144-3516-f623-122b-15895d07e24f host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 2df9c74a-303f-6247-cd24-4b20dea67730 device-config (MRO): location: /dev/xapi/cd currently-attached ( RO): true uuid ( RO) : 32a00247-3b74-94e1-666e-4f092d453edd host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): dba2c892-2954-486f-942b-53b30b12895e device-config (MRO): location: /opt/xensource/packages/iso; legacy_mode: true currently-attached ( RO): true uuid ( RO) : 4c701025-305e-b3bf-1577-643ef80cf717 host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 640b1256-8896-7730-b164-52e4b3671b04 device-config (MRO): location: /dev/xapi/block currently-attached ( RO): true uuid ( RO) : 39712cc2-611a-1f17-b4c2-8d67c41d2456 host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 8397b362-1b90-123f-4b1a-b6f0e0e79bdd device-config (MRO): device: /dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3 currently-attached ( RO): false #currently-attached的值为false表示未plug in该pbd #检查未plug in pbd时的SR参数 [[email protected] ~]# xe sr-param-list uuid=8397b362-1b90-123f-4b1a-b6f0e0e79bdd uuid ( RO) : 8397b362-1b90-123f-4b1a-b6f0e0e79bdd name-label ( RW): intrlvm name-description ( RW): host ( RO): xenmbr allowed-operations (SRO): forget; VDI.create; VDI.snapshot; plug; update; destroy; VDI.destroy; scan; VDI.clone; VDI.resize; unplug current-operations (SRO): VDIs (SRO): PBDs (SRO): 39712cc2-611a-1f17-b4c2-8d67c41d2456 virtual-allocation ( RO): 0 physical-utilisation ( RO): -1 physical-size ( RO): -1 type ( RO): lvm content-type ( RO): user shared ( RW): false introduced-by ( RO): <not in database> other-config (MRW): sm-config (MRO): blobs ( RO): local-cache-enabled ( RO): false tags (SRW): #注意此时sm-config字段无任何值,待plug in pbd后才会有值 [[email protected] ~]# xe pbd-plug uuid=39712cc2-611a-1f17-b4c2-8d67c41d2456 #如果成功则无回显,有异常都会显示相关信息 #使用xe pbd-param-list来检查pbd状态 [[email protected] ~]# xe pbd-param-list uuid=39712cc2-611a-1f17-b4c2-8d67c41d2456 uuid ( RO) : 39712cc2-611a-1f17-b4c2-8d67c41d2456 host ( RO) [DEPRECATED]: 074ff44e-4d73-47ee-8b72-b17514180cfd host-uuid ( RO): 074ff44e-4d73-47ee-8b72-b17514180cfd sr-uuid ( RO): 8397b362-1b90-123f-4b1a-b6f0e0e79bdd device-config (MRO): device: /dev/disk/by-id/scsi-3600605b002e3f320172790001a2ad4c1-part3 currently-attached ( RO): true other-config (MRW): #currently-attached状态为true表示已连接、挂载成功 #再次确认SR参数、状态 [[email protected] ~]# xe sr-param-list uuid=8397b362-1b90-123f-4b1a-b6f0e0e79bdd uuid ( RO) : 8397b362-1b90-123f-4b1a-b6f0e0e79bdd name-label ( RW): intrlvm name-description ( RW): host ( RO): xenmbr allowed-operations (SRO): forget; VDI.create; VDI.snapshot; plug; update; destroy; VDI.destroy; scan; VDI.clone; VDI.resize; unplug current-operations (SRO): VDIs (SRO): a5eb5cfa-9090-436d-bce6-de7294021c71; ac56e8c6-c2fe-4c7f-bab7-15d0bbc9039c PBDs (SRO): 39712cc2-611a-1f17-b4c2-8d67c41d2456 virtual-allocation ( RO): 129117454336 physical-utilisation ( RO): 129121648640 physical-size ( RO): 416506970112 type ( RO): lvm content-type ( RO): user shared ( RW): false introduced-by ( RO): <not in database> other-config (MRW): sm-config (MRO): allocation: thick; use_vhd: true; devserial: scsi-3600605b002e3f320172790001a2ad4c1 blobs ( RO): local-cache-enabled ( RO): false tags (SRW): #此时sm-config字段有值了
若是文中未提及的参数说明,请参考Citrix提供的XenServer Administrator‘s Guide中的Command Reference章节内容。