找回密码
 注册
查看: 700|回复: 2

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

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2022-9-29 11:57:47 | 显示全部楼层 |阅读模式
首先安装usb
* }& n: z) p& q6 D# A: r; rrpm -ivh usbutils-007-5.el7.x86_64.rpm   9 }. O0 A: U) j8 J
使用lsusb命令查看:
! O: q- R/ d9 G% L5 |, n(nova-libvirt)[root@compute07 /]# lsusb -v
( ]% e9 I3 k1 Q& M1 }, W' }, ]$ [
4 H+ Y- `1 _) v8 |Bus 002 Device 003: ID 0781:5588 SanDisk Corp. ' f. z; P' ]. O( D
Device Descriptor:+ i$ N# o! P$ M" |
  bLength                18
% ^7 {3 P- V5 Y  bDescriptorType         1
$ Z+ c: m/ A1 K# s  bcdUSB               2.103 h1 X; S8 ^0 l. [
  bDeviceClass            0 (Defined at Interface level)* K0 D% n9 J: H$ L- _
  bDeviceSubClass         0 2 E& S+ u& M( c/ H8 n
  bDeviceProtocol         0 / M2 Y' y/ P1 R4 U; W
  bMaxPacketSize0        64' o) R) J/ a8 t
  idVendor           0x0781 SanDisk Corp.0 |/ ]! ~" ^; M3 `) L
  idProduct          0x5588
. V$ \$ x6 M8 s7 b# m+ H  bcdDevice            1.001 U4 Q, y0 O, w8 i/ f
  iManufacturer           2 SanDisk# C8 E, B' C% J5 \# ~) i* D
  iProduct                3 USB Extreme Pro
! [. g/ h. \* g/ h$ t5 t3 ~  iSerial                 1 00000000000000000000
+ J5 i) Z* ^: v& @4 d1 S# m0 Y  bNumConfigurations      1
" a( I- u; B$ v* i$ v1 n6 L" s" R  Configuration Descriptor:
8 q: p# S& c1 p8 |3 M2 H6 D    bLength                 9
+ J8 X2 `, R1 g1 T    bDescriptorType         2
* G! ~% H/ t* g, X6 S    wTotalLength           32
+ w, j3 X; X/ Q8 X* l    bNumInterfaces          17 I  Y9 |2 Y  r* I% j
    bConfigurationValue     1
: v' \* K6 ?; K$ u    iConfiguration          0 + ?. R7 ~! X! Q1 N& o) a
    bmAttributes         0xc0  |4 f- R3 O' R& T# A4 G/ T. _
      Self Powered# i( u3 G6 F/ f2 {5 k# ^+ s5 W) ~4 j8 o
    MaxPower                0mA4 i9 Y$ }0 g) ]% F7 V0 v2 j
    Interface Descriptor:
. C5 S( z3 O' V/ u  ~( I4 ~      bLength                 9( u  z: a% s3 t  G2 d
      bDescriptorType         41 a3 E$ s/ I2 k; |+ @
      bInterfaceNumber        0. n& r2 D- a8 @* v; a
      bAlternateSetting       0$ V; u6 d% i+ y$ X: n9 h
      bNumEndpoints           2
( c" W, U9 E) u; Q) k! o' |8 E      bInterfaceClass         8 Mass Storage
! [* m. L# \6 Q0 w- h! x3 ?5 Y5 K      bInterfaceSubClass      6 SCSI
; b$ j8 Z+ f' b: m0 H: o      bInterfaceProtocol     80 Bulk-Only
- K1 k% I( r5 ~- y      iInterface              0 ! Y  C6 Y# ?6 F5 _" |
      Endpoint Descriptor:
+ d2 F1 Z% ~' a/ z8 i        bLength                 7
4 L$ C, |  @7 }2 ~' R  q% e        bDescriptorType         5+ Q( A2 s6 S) q/ C+ j
        bEndpointAddress     0x81  EP 1 IN
" ]3 K* x& P- @# {7 z7 h/ A( k        bmAttributes            2
: k0 @* o. K8 f          Transfer Type            Bulk
  [9 s5 O- v& k3 p          Synch Type               None
9 l/ B3 o: ^$ w  z! K! J& n          Usage Type               Data2 d' V; V+ d; v9 H
        wMaxPacketSize     0x0200  1x 512 bytes
$ ^& U" l0 t0 g; v, ~  K        bInterval               0
) [: u, V% e8 ]* u5 w: T- f- I5 _0 ^      Endpoint Descriptor:7 z8 S  z, q' z* o6 D/ |7 V$ s4 R" s4 ?
        bLength                 77 U0 n& ]/ f: C# j0 K# I0 c
        bDescriptorType         5
5 S6 t9 D* ~, M& L. ^+ V        bEndpointAddress     0x02  EP 2 OUT7 v5 Y3 a0 r9 w$ R
        bmAttributes            2
  o% l+ ^( p7 o2 k' [          Transfer Type            Bulk: f; d1 y1 ~/ T, L2 d( g1 i
          Synch Type               None
% w: ]9 E# J# L4 s          Usage Type               Data
( B( B1 v, ]( m. i& V        wMaxPacketSize     0x0200  1x 512 bytes
7 n( `) |0 [  x/ k4 W# v7 Z        bInterval               0, i0 l! |& `+ ~1 J8 H
Binary Object Store Descriptor:$ b. {7 y' l9 ~4 r0 {# t( W# j+ R5 o
  bLength                 5
' f0 h* R5 s3 T/ G  u* T2 P  bDescriptorType        155 A  \4 _6 P$ J* Y3 `4 Y
  wTotalLength           22$ l; |, J6 t! \/ _
  bNumDeviceCaps          2
/ }. c# P" |4 g" {* c- x  USB 2.0 Extension Device Capability:7 W) F* l. D) R; ^* T: M
    bLength                 70 V6 C- W8 _/ d+ B! P0 l
    bDescriptorType        16
6 j# `/ D, `- B* P    bDevCapabilityType      2- X, u/ f) J' c) I6 F; r! o
    bmAttributes   0x0000f41e
. k8 ]$ @) s$ n4 L; C( {      Link Power Management (LPM) Supported
0 o! @$ k, E: l5 N' G, z6 q$ s  b  SuperSpeed USB Device Capability:
2 D2 V, K% j: Z0 h( w    bLength                10( C  G8 s+ J! O# T% X. ]- l2 K
    bDescriptorType        16" V( v7 N* x2 ]9 T# ~  |$ m
    bDevCapabilityType      3
& a# X0 D. C, A; f( }) r8 @4 m) d    bmAttributes         0x00
% M: I; ?- `. h* ^9 X  ^, I    wSpeedsSupported   0x000e1 l( \' e1 E6 j
      Device can operate at Full Speed (12Mbps); c/ l$ h/ M' t. V% C
      Device can operate at High Speed (480Mbps)
# U. g5 {! P. K9 A  {, r      Device can operate at SuperSpeed (5Gbps)6 d) O/ {; D" a7 B' M
    bFunctionalitySupport   1+ R9 W* v+ {  v" X3 r+ A7 Z
      Lowest fully-functional device speed is Full Speed (12Mbps)
; `  b  a) d& q6 \" }! A    bU1DevExitLat          10 micro seconds6 |0 v7 h+ D! k9 z
    bU2DevExitLat        2047 micro seconds& t; u# J; J/ N0 S+ z) s
Device Status:     0x0001
+ s1 d/ O5 W7 I2 e  Self Powered
. S* Z. j  d. P! T0 @1 `
# L6 H5 N/ t7 A1 k0 j" g' d编辑xml文件:3 ^' a" B- R- A7 Z6 v* R+ y
3 Z. ~/ Q& @6 W/ i' A
(nova-libvirt)[root@compute07 /]# vim usb.xml " ]; m  I) ^( S  d- S6 G9 m1 D$ s! Y
<hostdev mode='subsystem' type='usb'>
" z* P8 f& d* z" @- Z( u: T& x<source startupPolicy='optional'>6 n! H; ~! U' x5 O  @0 {/ O
<vendor id='0x0781'/>) a: H# I# q2 O% B0 A
<product id='0x5588'/>/ z" U2 ^' H% j4 G  e* q* W
</source>; H3 [9 s6 ~. H7 S
</hostdev>  Y- Q4 t- {7 c/ b# s# \0 j
2 I5 M: g5 y' \! ~4 Z) s  N. ]- \3 F
添加usb到虚机
# B" F0 J1 X: w
+ f8 T9 Y/ ^1 B  v8 \" N* v# {(nova-libvirt)[root@compute07 /]# virsh attach-device instance-00000162 usb.xml
  j' c* @: X7 {6 N$ F5 PDevice attached successfully; \; y; I( k1 V( g1 D
. @* M. U1 n- C* }. `- N
(nova-libvirt)[root@compute07 /]# virsh detach-device instance-00000162 usb.xml & O6 N( U8 ^( X& i4 y$ u
Device detached successfully
3 \' A8 T& r$ w( Y0 x
; G4 x7 g0 j+ b1 f/ n, x+ _! H1 w. Q1 {9 x: X# w; }. L
1 G+ S) S/ ?8 P
4 B2 ^) E3 R, J2 K
" T0 V- ^) Z- E6 n( w$ i9 J- ?. @

9 @8 a  L1 _7 `- o- r

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-9-29 14:42:01 | 显示全部楼层
挂载USB设备(ISO)给虚机
, l# X: m3 [" i3 `# D& y; H  W在虚机所在的节点检验是否安装必要的包4 V3 c" P  O5 @/ n, S4 V7 k, c
rpm -qa|grep usbutils
- _5 B* M' T- c0 W9 R% K如没有,则yum install usbutils进行安装' D1 J- J7 |: Z- X. P

$ [1 i9 h& R  b4 v查看节点现有usb设备
3 U3 Q+ L4 T  A% |% R# Qlsusb, s8 Q) P/ l: I0 L$ F
9 S* I0 e8 j( Z. ]3 C6 Z
. 插入usb设备,确认新增的usb设备信息(主要确认verdor id和product id). ?/ n- W2 x& {1 q' g
lsusb -v. L5 `: I" M' u  C+ O7 P
% M9 w, N5 r9 D2 y
准备usb_device.xml
4 m% H: M/ @" u: cvi usb_device.xml
4 o4 Y  g! h/ P
2 \. X$ |6 H& P# B& S# ]4 H<hostdev mode='subsystem' type='usb' managed='yes'>- j+ R3 ?* j' W" J
<source>+ {/ V. b$ D. O4 O
<vendor id='0x090c'/>+ M6 G8 ?2 y' {
<product id='0x1000'/>9 [+ A  z9 \/ C8 V  ^) Q2 q
</source>/ L5 V5 K( }9 ?) y1 A
</hostdev>
' l% y" h) X8 ~- r* c1! L" t6 w' T# C6 Q4 T; [
2% K( A! B- U, b5 w. Q% f- `
3
3 o" r! O  W5 i4
2 C2 y9 v. t  A/ R' n7 ^, F& g5) ^2 Q5 O, y; h: ~9 r
6
* T& w+ a* r( p# Y*注:verdor id和product id是由步骤3中所确认
1 s. v, h0 G1 k' m# o# m- e, `4 l5 Z& C: \' ~
确认虚机的信息(instance-name)* j0 L) U2 |! M: d$ a" Q
virsh list
1 f# E/ A6 m! b1 U+ P3 X2 t
7 K' Y! O; q/ e  M; e* L  ?, o6 d将usb设备挂载给虚机
$ @0 I- E( t4 Q6 A0 ssudo virsh attach-device instance-name use_device.xml
" [. l8 F! g: s7 K4 K
7 ]9 `+ F- P8 a: \9 ]6 C* V卸载USB设备
& \/ X: q; n% @& Asudo virsh detach-device instance-name use_device.xml0 x4 y$ z& l- |! E* J8 N

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-9-29 14:54:44 | 显示全部楼层
<hostdev mode='subsystem' type='usb' managed='yes'>
" \9 s' n3 b9 v4 C# S  ~<source>
( y, r0 ?" ]6 K  `4 n: ~<vendor id='0x0951'/># N# N/ X$ H* ~4 k; q
<product id='0x1666'/>; y( d" A- M2 ~% [
<address bus='2' device='5'/>
6 o+ W: Q" g2 t  j% K</source>$ R7 K1 @* y2 }3 J- Y( _7 W
<alias name='hostdev0'/>/ ?$ X4 u$ c; f/ {: B. w3 U
</hostdev>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:01 , Processed in 0.019363 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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