码迷,mamicode.com
首页 > 系统相关 > 详细

无需重启 在Linux下热添加或移除SCSI硬盘

时间:2019-03-08 23:50:08      阅读:518      评论:0      收藏:0      [点我收藏+]

标签:虚拟机   解释   centos   通过   end   现在   lun   查看   vendor   

实验环境 一台运行Centos 7的虚拟机在线添加一块4G硬盘

[关键命令]
添加:
echo "scsi add-single-device 1 2 3 4" >/proc/scsi/scsi

移除:
echo "scsi remove-single-device 1 2 3 4" > /proc/scsi/scsi

命令行解释:
命令行中的 1 2 3 4 需要自行修改成相应的参数:

1 : SCSI HBA ID
2 : SCSI Channel
3 : SCSI ID
4 : LUN ID

添加也可以使用 echo "- - -" > /sys/class/scsi_host/host2/scan
‘- - -‘代表channel,target和LUN编号。以上命令会导致host2下所有channel,target以及可见LUN被扫描

通过 lsscsi 命令可以查看对应参数

[root@localhost ~]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda

[root@localhost ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05

[root@localhost ~]# ls /sys/class/scsi_host/
host0  host1  host2
#可以看到scsi硬盘使用的总线是host2
[root@localhost ~]#  echo "- - -" > /sys/class/scsi_host/host2/scan
[root@localhost ~]# lsscsi 
[1:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 
[2:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[2:0:1:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sdb 
#或者使用 echo "scsi add-single-device 2 0 1 0" >/proc/scsi/scsi 也可以发现设备
[root@localhost ~]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb    8:16   0   4G  0 disk 
[root@localhost ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 01 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02

现在移除添加的硬盘

[root@localhost ~]# echo "scsi remove-single-device 2 0 1 0 " > /proc/scsi/scsi
[root@localhost ~]# lsscsi
[1:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 
[2:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[root@localhost ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05

[root@localhost host2]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3

无需重启 在Linux下热添加或移除SCSI硬盘

标签:虚拟机   解释   centos   通过   end   现在   lun   查看   vendor   

原文地址:https://blog.51cto.com/1012682/2360215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!