易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 697|回复: 2
收起左侧

openstack 虚机添加usb磁盘驱动到虚机上

[复制链接]
发表于 2022-9-29 11:57:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
首先安装usb
& V2 K4 X' h& Q6 Orpm -ivh usbutils-007-5.el7.x86_64.rpm   
: P" k0 R. @! O+ t* t. k  ^使用lsusb命令查看:
  S! w* C5 Q8 q( z7 o8 z  |(nova-libvirt)[root@compute07 /]# lsusb -v( I1 S6 B4 z; }' \

- X7 j- f1 M( Z, W: W3 gBus 002 Device 003: ID 0781:5588 SanDisk Corp. , |4 @/ N( a# D+ O3 h. q
Device Descriptor:( P, z. V% R( R; Q  G
  bLength                189 d3 Q; Z0 A) I
  bDescriptorType         1: N, @6 L! o5 R$ j. ~/ |
  bcdUSB               2.107 y8 B8 S# G! h. B/ u' q
  bDeviceClass            0 (Defined at Interface level)8 \6 r, m4 k3 _$ V$ P9 \
  bDeviceSubClass         0 6 |  n% ?2 g% ]" H4 c, L
  bDeviceProtocol         0
% K7 v! G8 f5 V; m* f7 l: v  _0 l  bMaxPacketSize0        64( v( M% P+ [: q& P
  idVendor           0x0781 SanDisk Corp.: T1 e4 M/ E1 F$ r% o4 j
  idProduct          0x5588 ) j" N" P9 b/ z: |+ S  s0 i
  bcdDevice            1.00) m, E5 y& [6 w4 }$ Z
  iManufacturer           2 SanDisk; j1 a. E  {& y6 b+ T& y
  iProduct                3 USB Extreme Pro
& S4 E6 N3 Q/ S1 ]3 w1 g  iSerial                 1 00000000000000000000- ?$ O$ l8 H3 p1 C# `+ B/ G
  bNumConfigurations      1  v7 x- R5 t# T6 V& H! w3 [
  Configuration Descriptor:
5 f: i1 K1 G( n8 t0 W    bLength                 9
! s" O) f$ s/ ?! i, ~) K) u/ |    bDescriptorType         2# o" D. v  r% _% t5 V
    wTotalLength           32/ e/ N: L; d$ d3 M8 a
    bNumInterfaces          1
% f9 P$ o# }/ x) {    bConfigurationValue     1
, _" [" F7 N0 g; J6 I8 D( J    iConfiguration          0
4 _4 x% B/ E9 p% V$ z    bmAttributes         0xc0
1 F: C- s' K: J: d$ K' P" O( F8 F4 v      Self Powered5 a8 _! y9 L7 z" Y3 `9 V( y# g
    MaxPower                0mA
, m" N) p- b1 ~3 [    Interface Descriptor:3 K: {9 T$ R/ {7 O8 k  E
      bLength                 9
6 Q2 v, P) i, n( l. O- M0 s      bDescriptorType         46 ]9 }& p# c  T' ^. Y; v7 C
      bInterfaceNumber        0
- n: @, V( c1 Q; P+ c      bAlternateSetting       05 [$ D2 {7 a$ k/ ~- r
      bNumEndpoints           2
9 M8 b  ^, t- X3 F8 K+ A# B" O! R      bInterfaceClass         8 Mass Storage- ?$ B2 {1 O3 H, N+ L5 L, N% J1 O
      bInterfaceSubClass      6 SCSI
! A3 P% M* P" b      bInterfaceProtocol     80 Bulk-Only
; @' V4 t% x0 c, @      iInterface              0   _0 C9 ]- T' [0 b  Q; T& r# k
      Endpoint Descriptor:! j# f2 @: o0 O* p9 k
        bLength                 7# W- U; P' J% f) L8 M2 }
        bDescriptorType         5( F. t9 o# T% U8 E: Z
        bEndpointAddress     0x81  EP 1 IN
9 |+ d, N5 y. P2 O5 Q. d        bmAttributes            2
7 Q. ~+ u: y3 w6 n          Transfer Type            Bulk7 i9 |' N) Q) Z1 ^8 [
          Synch Type               None: |) j% ^% i" Z8 k% N' V% K! J
          Usage Type               Data: ~, r& O! a; l5 d
        wMaxPacketSize     0x0200  1x 512 bytes
0 X9 b: r8 H# _# s: F5 W        bInterval               0
+ w  B5 \' l! u$ b      Endpoint Descriptor:: {) h! u5 S8 v" l4 ^
        bLength                 7
; y) R5 k6 o0 h* s# M        bDescriptorType         5
( i( T8 }" I2 j0 q        bEndpointAddress     0x02  EP 2 OUT
. s# ?4 h9 d% b+ x$ R0 a        bmAttributes            2
% q; ]: l/ U8 S& k; e$ j4 r+ {          Transfer Type            Bulk2 p% x4 ?$ ]9 F( k8 A$ Q
          Synch Type               None1 f$ `$ F/ W+ j1 i  ?3 w
          Usage Type               Data
8 z5 h) ]- L9 R( j        wMaxPacketSize     0x0200  1x 512 bytes
* ]4 C* i: z# R$ R6 s4 }% r" o: _        bInterval               0
4 N1 O/ j2 |6 u. T; l1 d- y9 DBinary Object Store Descriptor:
- U4 B6 H+ f0 G  b* s* F! A0 W$ _  bLength                 59 m# P, d" Y" G* D* q8 F4 {5 n
  bDescriptorType        15: @6 g) r2 n$ V- Z. ?
  wTotalLength           22
- V+ o* J4 M1 e) \2 y  bNumDeviceCaps          2
2 y* g; O' U( T# N% b% O* M, V  USB 2.0 Extension Device Capability:
6 ?* ]' u! B6 \" n  h# P    bLength                 7! `) |: ?2 K6 c2 S6 {, s5 U* b* v, V/ ]
    bDescriptorType        161 ^4 j" D2 D7 h; r4 H& |
    bDevCapabilityType      2" s6 O$ h' S! m' J# w' C4 A2 j
    bmAttributes   0x0000f41e+ q; ~* f/ p8 g6 q7 g3 i
      Link Power Management (LPM) Supported  p% O2 o+ a$ S4 i
  SuperSpeed USB Device Capability:
1 ?# Q; U  c/ r3 Q/ |3 `    bLength                104 b9 b6 v  N! j+ g! L& y6 y4 X! _
    bDescriptorType        16) I7 l1 d6 \% u9 D' |5 |3 ~7 Z
    bDevCapabilityType      3# B# N7 t! @: u, U3 I
    bmAttributes         0x00
6 a+ y( t( v4 v' k1 D    wSpeedsSupported   0x000e7 j3 U4 c0 r' u, o* F3 N* C( O8 J
      Device can operate at Full Speed (12Mbps)$ R4 g; t9 v( x" g- N* V3 ^+ P! M" g
      Device can operate at High Speed (480Mbps)7 J: W. H: z% |% J5 |% W
      Device can operate at SuperSpeed (5Gbps)6 U& @& ]' r- f# P# \
    bFunctionalitySupport   1
2 _, F+ T. _$ R* e      Lowest fully-functional device speed is Full Speed (12Mbps)
, W0 q5 S, n$ W% c4 s3 v4 `6 T    bU1DevExitLat          10 micro seconds
) k# O1 f6 S" n2 r- V5 T! ]5 X+ X    bU2DevExitLat        2047 micro seconds) M; t+ e+ w5 t; ]% Q# K# b" @7 b
Device Status:     0x0001
5 a5 |  S  O5 q4 B7 [  Self Powered# l! r* M. J" H6 ~

/ P4 i& B/ N& j6 V( \# q编辑xml文件:
2 F. V  J& m, P5 K" ^4 U, U) `+ f' f' @9 w( q  M% i
(nova-libvirt)[root@compute07 /]# vim usb.xml 1 F# i8 V! w  d) L
<hostdev mode='subsystem' type='usb'>
% E1 L# E) ~# z# j5 a5 x1 [<source startupPolicy='optional'>
& e9 A; C4 y3 Q5 v2 P<vendor id='0x0781'/>/ @6 U/ Q# M& k6 ~
<product id='0x5588'/>
; P/ }2 T( n4 D. k! f, @8 O- T</source>
* K4 u2 o$ }6 G& t; R; H2 W+ n</hostdev>" m4 M( e7 V6 C7 M8 T
8 g/ {, H4 r6 l+ ?
添加usb到虚机  ~& C+ M. X  U2 l1 H
+ F1 D- V% K1 m2 x
(nova-libvirt)[root@compute07 /]# virsh attach-device instance-00000162 usb.xml" w% Q( D0 C  w: c
Device attached successfully
- }* M- N; T, l
0 i$ E- W6 X) D/ p: o) f) h(nova-libvirt)[root@compute07 /]# virsh detach-device instance-00000162 usb.xml 7 m/ P: V! f; h: T5 E1 c
Device detached successfully" j$ l  t( \8 T7 y

* w# v  M  N* h# S1 J, y1 h) r1 ]2 S# E6 ~6 Q
( ^+ I: `' _: G, l/ J" a" h$ p
5 Q7 D- y9 |8 _1 b0 B0 s
9 c3 q6 S: K- ~- r8 s' i

, g, F, {* E! A
 楼主| 发表于 2022-9-29 14:42:01 | 显示全部楼层
挂载USB设备(ISO)给虚机' T# }+ U& N7 ^/ b# X
在虚机所在的节点检验是否安装必要的包' e- |& R/ [) j' X  `! S
rpm -qa|grep usbutils
1 [: C2 t  N" X0 @% r7 o如没有,则yum install usbutils进行安装
( f6 j2 H8 E: g( Z3 H! T. G, p9 z/ v- ~
查看节点现有usb设备
, o- ^* s& \+ Y, e: E! Elsusb
# K( @* |, C- {/ F) W1 v. m: b6 t/ C6 a
. 插入usb设备,确认新增的usb设备信息(主要确认verdor id和product id)
; J2 x! G; X  K  p9 Y* Alsusb -v
% b; [8 ^1 M5 x8 A% \% B
. A$ W& A1 M0 z1 [- |% x准备usb_device.xml
% c  |6 D2 p1 j. Nvi usb_device.xml1 V- [! n8 `# d" H
/ I2 v, b% Y  r4 M
<hostdev mode='subsystem' type='usb' managed='yes'>
; U  a" {( Z% b9 s! a& v# C<source>
( ]' A4 X6 _; C* s; p<vendor id='0x090c'/>
4 C, \' K3 m: N  _<product id='0x1000'/>3 s9 y/ t2 h) ]6 I' v
</source>4 |) @" k' }# C+ l4 {7 J
</hostdev># r/ h; K* s1 V0 g5 ]# r( M
1
# V# P. u" k( }0 J; `1 P. C2
0 P9 O3 G, f0 L8 N( w7 T3+ v. V" M! P' b6 `
44 s& @- v& @  M, P  _
5
/ Z! x# _% r4 X$ r1 Q' x62 F! g, K% S& M2 u
*注:verdor id和product id是由步骤3中所确认5 Y; i' T1 V$ t0 o7 L% Z! @
( Z! j/ w" b2 T- n1 e
确认虚机的信息(instance-name)
) s2 g, i" u4 R  p1 Dvirsh list2 N! i9 V! H! Q' m

, x' L# Z" y- I0 K+ x将usb设备挂载给虚机. N7 c9 r1 q( l8 O3 r8 n, Q
sudo virsh attach-device instance-name use_device.xml
2 \$ O% U( F5 F3 q$ U# b6 R# j6 x6 w( [- r: e
卸载USB设备
0 f; H5 L- n2 I6 `9 ~% vsudo virsh detach-device instance-name use_device.xml- d% x) N/ t9 |$ }1 p( M
 楼主| 发表于 2022-9-29 14:54:44 | 显示全部楼层
<hostdev mode='subsystem' type='usb' managed='yes'>3 w& ?2 Z6 i: J+ h
<source>
. ]4 G; p- w: G" z<vendor id='0x0951'/>
% O8 i3 E  `( O6 U2 j! |<product id='0x1666'/>
( p: F6 Z  Y7 ?3 q& \1 _<address bus='2' device='5'/>
$ r/ Q5 z- a& ~9 \</source>9 C* d2 a& D) j: M" h
<alias name='hostdev0'/>
& k) `0 B2 f$ d, x</hostdev>
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-9 00:04 , Processed in 0.050132 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表