Linux VM上不重启系统扫描添加新的硬盘

HP-UX、Linux、Tru64 UNIX、NonStop、OpenVMS、Windows Server等,数据中心、虚拟化方案等

版主: xyevolve

版面规则
1. 本版是定位于惠普软件系统及解决方案的技术讨论区。
2. 本版鼓励发帖共同讨论技术问题,不鼓励站内信件私下交流,独知知不如众知知。
3. 本版允许转贴或引用他人的作品,但必须声明原作者信息。
4. 本版禁止发表出售、求购、或其他非技术讨论等帖子。
5. 本版禁止灌水,包括但不限于任何与所讨论主题无关的回复,无意义字符,直接复制其他回复等。
6. 本站附件禁止用于商业目的,请在下载后24小时内删除,本站不对其造成的结果负任何责任。
回复
头像
MUDBOY
创始人
帖子: 3877
注册时间: 2010年 12月 28日 21:17 星期二

Linux VM上不重启系统扫描添加新的硬盘

帖子 MUDBOY » 2015年 3月 19日 14:02 星期四

Rescan the SCSI Bus to Add a SCSI Device Without rebooting the VM

A rescan can be issued by typing the following command:

#echo "- - -" > /sys/class/scsi_host/host#/scan
#fdisk -l
#tail -f /var/log/message

Replace host# with actual value such as host0. You can find scsi_host value using the following command:

# ls -la /sys/class/scsi_host

MUDBOY 写了:可能有很多host#,它们其实都是连接到各种总线设备上的。
要确定硬盘是连接的那个host#,可以用lspci命令查询连接硬盘的HBA卡pci#
然后和上面ls出来的结果对照就知道了

# lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)

# ll -a
total 0
drwxr-xr-x. 2 root root 0 Apr 26 17:13 .
drwxr-xr-x. 44 root root 0 Apr 26 14:56 ..
lrwxrwxrwx. 1 root root 0 Apr 26 17:13 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host10 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host10/scsi_host/host10
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host11 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host11/scsi_host/host11
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host12 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host12/scsi_host/host12
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host13 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host13/scsi_host/host13
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host14 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host14/scsi_host/host14
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host15 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host15/scsi_host/host15
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host16 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host16/scsi_host/host16
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host17 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host17/scsi_host/host17
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host18 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host18/scsi_host/host18
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host19 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host19/scsi_host/host19
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host20 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host20/scsi_host/host20
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host21 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host21/scsi_host/host21
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host22 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host22/scsi_host/host22
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host23 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host23/scsi_host/host23
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host24 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host24/scsi_host/host24
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host25 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host25/scsi_host/host25
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host26 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host26/scsi_host/host26
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host27 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host27/scsi_host/host27
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host28 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host28/scsi_host/host28
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host29 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host29/scsi_host/host29
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host3 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host3/scsi_host/host3
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host30 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host30/scsi_host/host30
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host31 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host31/scsi_host/host31
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host32 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host32/scsi_host/host32
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host4 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host4/scsi_host/host4
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host5 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host5/scsi_host/host5
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host6 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host6/scsi_host/host6
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host7 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host7/scsi_host/host7
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host8 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host8/scsi_host/host8
lrwxrwxrwx. 1 root root 0 Apr 26 18:07 host9 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:04.0/host9/scsi_host/host9

How Do I Delete a Single Device Called /dev/sdc?
In addition to re-scanning the entire bus, a specific device can be added or existing device deleted using the following command:
# echo 1 > /sys/block/devName/device/delete

# echo 1 > /sys/block/sdc/device/delete

How Do I Add a Single Device Called /dev/sdc?
To add a single device explicitly, use the following syntax:
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
Where,
<H> : Host
<B> : Bus (Channel)
<T> : Target (Id)
<L> : LUN numbers

For e.g. add /dev/sdc with host # 0, bus # 0, target # 2, and LUN # 0, enter:

# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
# fdisk -l
# cat /proc/scsi/scsi

Sample Outputs:

Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

Step #3: Format a New Disk

Now, you can create partition using fdisk and format it using mkfs.ext3 command:

# fdisk /dev/sdc
# mkfs.ext3 /dev/sdc3

Step #4: Create a Mount Point And Update /etc/fstab

# mkdir /disk3

Open /etc/fstab file, enter:

# vi /etc/fstab

Append as follows:

/dev/sdc3 /disk3 ext3 defaults 1 2

Save and close the file.
Optional Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backupDisk, enter

# e2label /dev/sdc1 /backupDisk

Quoted from http://www.cyberciti.biz/tips/vmware-ad ... guest.html
提倡分享之精神, 技术问题请在相关版面直接发帖, 站内短信恕不答复.
I don't answer private messages on topics of public interest, because it defeats the whole purpose of a message board.

头像
MUDBOY
创始人
帖子: 3877
注册时间: 2010年 12月 28日 21:17 星期二

Re: Linux VM上不重启系统扫描添加新的硬盘

帖子 MUDBOY » 2015年 3月 19日 14:10 星期四

Linux, when adding a new disc

First find your host bus number

#grep mpt /sys/class/scsi_host/host?/proc_name

Which should return a line like

/sys/class/scsi_host/host0/proc_name:mptspi

where host0 is the relevant field.

use this to rescan the bus with the following command

#echo "- - -" > /sys/class/scsi_host/host0/scan

In the above command the the hyphens represent controller,channel,lun, so – - – indicates all controllers, all channels and all luns should be scanned.
Linux, when expanding an existing disc

Assuming you know the device name of the disc you have expanded (eg /dev/sda) then you can simply issue the following command to force the rereading of the disk geometry. NOte that this is not 100% reliable with LVM on older kernels but should work with current kernels

#echo 1 > /sys/class/scsi_device/device/rescan

Quoted from https://blogs.it.ox.ac.uk/oxcloud/2013/ ... w-storage/
提倡分享之精神, 技术问题请在相关版面直接发帖, 站内短信恕不答复.
I don't answer private messages on topics of public interest, because it defeats the whole purpose of a message board.

头像
MUDBOY
创始人
帖子: 3877
注册时间: 2010年 12月 28日 21:17 星期二

Re: Linux VM上不重启系统扫描添加新的硬盘

帖子 MUDBOY » 2015年 3月 19日 14:11 星期四

https://www.suse.com/documentation/sles ... andev.html

Use rescan-scsi-bus.sh command in Suse Linux.
提倡分享之精神, 技术问题请在相关版面直接发帖, 站内短信恕不答复.
I don't answer private messages on topics of public interest, because it defeats the whole purpose of a message board.

回复