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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无需重启 在Linux下热添加或移除SCSI硬盘相关的知识,希望对你有一定的参考价值。

实验环境 一台运行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 命令可以查看对应参数

[[email protected] ~]# 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

[[email protected] ~]# 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

[[email protected] ~]# ls /sys/class/scsi_host/
host0  host1  host2
#可以看到scsi硬盘使用的总线是host2
[[email protected] ~]#  echo "- - -" > /sys/class/scsi_host/host2/scan
[[email protected] ~]# 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 也可以发现设备
[[email protected] ~]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb    8:16   0   4G  0 disk 
[[email protected] ~]# 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

现在移除添加的硬盘

[[email protected] ~]# echo "scsi remove-single-device 2 0 1 0 " > /proc/scsi/scsi
[[email protected] ~]# 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 
[[email protected] ~]# 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

[[email protected] host2]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3

以上是关于无需重启 在Linux下热添加或移除SCSI硬盘的主要内容,如果未能解决你的问题,请参考以下文章

linux添加新硬盘不需要重启识盘

如何在 CentOS 7 中添加新磁盘而不用重启系统

Linux添加硬盘不重启进行识别

LINUX虚拟机磁盘在线扩容不重启

linux不重启识别新硬盘

如何在CentOS 7中添加新磁盘而不用重启系统