易陆发现互联网技术论坛

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

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

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

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

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

x
首先安装usb2 t: \1 ]% h4 Y! g3 ~- R
rpm -ivh usbutils-007-5.el7.x86_64.rpm   $ u# m4 F. ?4 W! {( R$ M0 b1 _7 Y
使用lsusb命令查看:
7 B: B+ V+ {8 G# B(nova-libvirt)[root@compute07 /]# lsusb -v
. T/ i) S$ B5 {1 k8 Q- G$ l. @9 q' F6 T$ b. s& F( l
Bus 002 Device 003: ID 0781:5588 SanDisk Corp. - m3 ~2 j& ^0 ]; T" {: e+ ~
Device Descriptor:4 s: U, L6 w2 A/ q' q* Q; d
  bLength                186 K8 u' o+ G1 `
  bDescriptorType         18 Y1 V2 u" d  y* k
  bcdUSB               2.107 L4 y% V1 f# w
  bDeviceClass            0 (Defined at Interface level)- x# B7 L0 i0 e, P1 ?
  bDeviceSubClass         0 4 x$ V3 p& `( e: E% Y2 Z& ?$ n. f+ x0 u
  bDeviceProtocol         0 ; P% }/ Z% y6 Z7 |' V' O2 Y- ?
  bMaxPacketSize0        64; l- o+ Y6 h1 A, C, X* j- W+ F
  idVendor           0x0781 SanDisk Corp.
& {; B6 i) O% C" {; t/ j& c2 d  idProduct          0x5588
5 v9 C1 W: g: R1 z7 W  bcdDevice            1.00
5 V+ ~/ X  `/ R" s  iManufacturer           2 SanDisk
  X# _% W" a  k4 J/ h' f( _. L0 S- H" i  iProduct                3 USB Extreme Pro8 }$ \& i! E4 V* `3 w) @; b
  iSerial                 1 00000000000000000000% P( d" ]/ m& u6 d2 S7 m# `
  bNumConfigurations      1
- l3 s9 c; h2 n/ S9 J  I  Configuration Descriptor:
! I! @* Y9 Y( R    bLength                 95 J. A0 f  j# q9 W
    bDescriptorType         2
  u* T3 ~' {' @. ~6 O    wTotalLength           32. }: |/ @- B% z8 k0 }
    bNumInterfaces          1
' N! h* O( L- c1 Z% o# Q& U& N    bConfigurationValue     1
5 i  `9 Q* G! b! Z    iConfiguration          0
9 n0 n5 Q, \  R    bmAttributes         0xc0/ j) Z- |& `; F/ @5 L
      Self Powered3 ?# N" X- B9 R. c! h% w& W8 n
    MaxPower                0mA/ H9 l7 S& R% y3 C& M2 @: W
    Interface Descriptor:
+ N5 e0 B9 c6 D( B3 [# `      bLength                 9& S" A0 w' C8 |. Z2 X) e; t
      bDescriptorType         4) M& e, I( J: S% y
      bInterfaceNumber        0
- p* B6 h* o- O& ?9 c$ H; a      bAlternateSetting       0( p3 i, ?& U$ G) T  }$ [  c
      bNumEndpoints           2
1 z+ U3 H7 r" n# c0 [. v, d      bInterfaceClass         8 Mass Storage: M1 B+ @* Y" M4 [5 U
      bInterfaceSubClass      6 SCSI
0 P! p% u1 u/ c9 |9 W      bInterfaceProtocol     80 Bulk-Only
# r- c0 |3 I& ?9 U$ Q      iInterface              0 & I( A" ]8 l. T2 j  A" Z5 j
      Endpoint Descriptor:" I! v6 R& H" Z" v" v/ g' F! g
        bLength                 7' e3 w5 m2 a7 B9 z7 j6 E
        bDescriptorType         5
5 x/ y7 T" ?) M8 T7 [3 U" u7 T- u" V) V        bEndpointAddress     0x81  EP 1 IN
1 |9 E6 u, G3 V/ p0 [+ P; f- a$ T        bmAttributes            2) l5 ]0 a6 a8 d+ s. S. p% V2 w" M4 C
          Transfer Type            Bulk
# y1 O/ w5 r4 U; P# w" t& m. t% I          Synch Type               None
( G2 U  p; G, F; b          Usage Type               Data
. [7 w. x" W  n, C2 a4 d+ F        wMaxPacketSize     0x0200  1x 512 bytes. J; z7 x) _* F8 ?: y
        bInterval               0
* I/ x1 V$ c9 `2 [  V. [      Endpoint Descriptor:6 f- e! g& D9 y3 V( Q+ p2 N4 d% L
        bLength                 7. G+ F% U( S0 v  h! t+ K. A
        bDescriptorType         59 `  L; f3 N' }5 d
        bEndpointAddress     0x02  EP 2 OUT1 F! C6 e% q3 `$ I& A
        bmAttributes            2, x' l5 G) i% z2 C+ }! L! z
          Transfer Type            Bulk
( \6 u. E; k. ^8 Z0 e2 u  z          Synch Type               None
( f! z1 U$ k* m% a% f, x7 I          Usage Type               Data
; O- A5 A5 \. y- R: L& s. @3 ^        wMaxPacketSize     0x0200  1x 512 bytes% d+ B7 K/ M$ R8 z
        bInterval               0
% Y7 p8 b! Z% I, g2 D8 S0 v2 nBinary Object Store Descriptor:0 p' j3 S. B- F$ e7 K
  bLength                 5
* x# u7 S  y& ~  bDescriptorType        15/ g8 \; R/ J, B2 B9 s% f& {* ^. t' O: ~
  wTotalLength           22
- C8 [0 {: T0 Z  bNumDeviceCaps          2. e( K) K0 y* l- T
  USB 2.0 Extension Device Capability:+ C5 g# |3 [% f5 k: K
    bLength                 7
3 Z8 a4 O* \) L+ x2 i+ A8 {    bDescriptorType        16# T; A1 i9 f+ h1 G
    bDevCapabilityType      26 x; o! O5 z+ C1 d
    bmAttributes   0x0000f41e( e: M) Y8 ?; Z3 r
      Link Power Management (LPM) Supported! N% M1 Q# U3 X/ ^; r; k& ]/ X) J
  SuperSpeed USB Device Capability:/ h0 n4 P: v6 W: j* {( p
    bLength                107 j; O( K! O2 D/ p4 w. |$ P
    bDescriptorType        16
* n' Q+ ~: J8 k3 [! F/ U    bDevCapabilityType      3  U' H$ t) h0 h, o/ P& p) D. L
    bmAttributes         0x00% t5 |4 @: G2 w" m# j7 I/ y
    wSpeedsSupported   0x000e
0 U( d- [6 N' w$ h" F8 @! f      Device can operate at Full Speed (12Mbps)# M. ^) D4 ?6 s
      Device can operate at High Speed (480Mbps)8 w, _! ?5 D. d& x( ^
      Device can operate at SuperSpeed (5Gbps)
$ g8 T% P% P/ m; \    bFunctionalitySupport   1
' ~+ A# K+ Y2 [, ?% \      Lowest fully-functional device speed is Full Speed (12Mbps)
( {9 o; ^) l, L/ K9 d# l    bU1DevExitLat          10 micro seconds
9 s% U" H2 d! ], Q    bU2DevExitLat        2047 micro seconds. _3 g7 i3 K( l7 }
Device Status:     0x0001
) J, j# G: v1 M: U7 x; y# X  Self Powered6 e7 |% b& U, J; T

5 [: v2 x! r/ E0 n$ F+ s6 s编辑xml文件:
, v8 C; W/ w3 X% k
* D; b: r2 o! h8 J(nova-libvirt)[root@compute07 /]# vim usb.xml . j: Q7 |( C: ]% f' Y9 i. ?
<hostdev mode='subsystem' type='usb'>. `4 r, r4 v- k& z9 A' [
<source startupPolicy='optional'>
; r, D+ \" {8 u! m( \3 e4 P; M<vendor id='0x0781'/>2 r" P$ j$ }  d9 _* \: I
<product id='0x5588'/>
+ i- [- U5 Z; g</source>( h* l- K- H: l5 ]- Y3 H# D
</hostdev>
' a4 E% k, P! A* M+ g; `8 f, g$ M0 \- V
添加usb到虚机; c9 m% f* V8 c) A2 \2 O1 B1 W
, }8 b& ]; H; S! c) ~4 y+ c
(nova-libvirt)[root@compute07 /]# virsh attach-device instance-00000162 usb.xml
, e$ B8 L/ m' i5 [& v" lDevice attached successfully
  ^" u1 |" Y' m! ?4 S
6 u6 W* ?2 H& S(nova-libvirt)[root@compute07 /]# virsh detach-device instance-00000162 usb.xml
3 a; Q& a! O5 \5 I4 z4 L5 hDevice detached successfully
3 Y+ N& l- R1 x' d% @$ r
! F" v1 S1 d' R# [5 r2 S& c3 q% F$ m  k" B) Z5 q! C2 T
$ l. u2 P+ e) z4 y* l
2 q/ J! \5 I& F# F& s' {3 }2 ~* B

! W- o- Y% ^+ |5 A- a3 K; `4 x, P! {2 W
 楼主| 发表于 2022-9-29 14:42:01 | 显示全部楼层
挂载USB设备(ISO)给虚机
& e. |3 m& N0 u) p5 v在虚机所在的节点检验是否安装必要的包
7 y7 o) ~2 H- z4 T) srpm -qa|grep usbutils/ ^4 Q& l7 H" t' g; n
如没有,则yum install usbutils进行安装
9 Y6 l9 e: o) g$ p
: i: B4 g* {4 B; y  d) a查看节点现有usb设备
1 K; ?( P% H7 N7 rlsusb
# }; v, y& H3 j3 }7 S; w& F
1 @. E" h0 y1 ^. f( }- M: _! j1 y. 插入usb设备,确认新增的usb设备信息(主要确认verdor id和product id)
2 N+ u( d9 q/ U5 X$ Ulsusb -v
: n3 o" f  E" ~. o9 e. L6 |) `1 N3 S' g% H' T" J3 {
准备usb_device.xml3 e; N7 c) I: g& T6 ~
vi usb_device.xml2 s  V* x; W: Q, \2 ?
; E! F7 N4 H! ]
<hostdev mode='subsystem' type='usb' managed='yes'>( d' M% L7 ~9 f4 N
<source>
# e( F: o* v3 k0 U- X<vendor id='0x090c'/>
2 h, w. y, Y* x" Q$ B- d: }; I4 x<product id='0x1000'/>
# x' b( G* T7 r6 l; ]5 E2 h  j; p  c- z</source>
% P; @* k# C; g( O& q6 C0 N7 q* H</hostdev>
5 e& c. S1 `" m1
9 W: X" g& W; p3 q+ \! A/ j2
5 |: N; C% @& J39 H6 p3 i1 Z. \: W, T$ ^. I0 \# g
4) D' P# g& X. _( R; l
5  x% h/ B* R! w4 s  e/ _" V
64 n8 f" P" R6 k+ Z: S* L
*注:verdor id和product id是由步骤3中所确认
, b8 k$ x; ]3 R, e, W6 `9 K
6 p/ U" Y$ @5 z! h确认虚机的信息(instance-name)- S' _1 \* v7 x# R! H' K& z+ Z
virsh list
# f+ P; M' q1 [: r# K3 U/ ^/ G: G( o& u/ o1 v8 u8 E9 J
将usb设备挂载给虚机
$ o7 X8 D- O( T/ U5 G) C2 Xsudo virsh attach-device instance-name use_device.xml" r2 u9 u0 W' `5 k* z8 n9 O+ x+ O

* ?* _9 _% N9 l$ C卸载USB设备1 a, E- s1 f# d1 m. h
sudo virsh detach-device instance-name use_device.xml8 p3 r. I2 r, L% D; s/ j
 楼主| 发表于 2022-9-29 14:54:44 | 显示全部楼层
<hostdev mode='subsystem' type='usb' managed='yes'>
2 A/ E2 E  ^- v<source>4 v3 ]( j9 q/ w! i
<vendor id='0x0951'/>
; J$ ?: M) B; D' f<product id='0x1666'/>
2 N$ }* m, d* P4 n" K! z; b<address bus='2' device='5'/>& _! p# Q# O3 b, C
</source>- H# ^% a. U' c" e6 j! o8 `
<alias name='hostdev0'/>3 m; C1 U; y' L. X2 [# T5 l
</hostdev>
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

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

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

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 点击这里给我发消息

GMT+8, 2026-4-8 15:29 , Processed in 0.040725 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

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