


What does disk hot-plugging mean on Linux?
首先获取scsi设备的信息。
[root@server2 ~]# lsscsi [2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda [4:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
有些操作系统没有lsscsi命令,则可以使用下面的方法获取scsi设备信息。
[root@server2 ~]# ll /sys/bus/scsi/drivers/sd/total 0lrwxrwxrwx 1 root root 0 Jun 22 17:29 2:0:0:0 -> ../../../../devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0--w------- 1 root root 4096 Jun 22 17:29 bind--w------- 1 root root 4096 Jun 22 2017 uevent--w------- 1 root root 4096 Jun 22 17:29 unbind
[root@server2 ~]# ll /sys/bus/scsi/drivers/sd/2\:0\:0\:0/block/total 0drwxr-xr-x 10 root root 0 Jun 22 2017 sda
然后查看/proc/scsi/scsi文件,获取对应scsi设备的详细信息。
[root@server2 ~]# 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: 02Host: scsi4 Channel: 00 Id: 00 Lun: 00 Vendor: NECVMWar Model: VMware SATA CD01 Rev: 1.00 Type: CD-ROM ANSI SCSI revision: 05Host: scsi2 Channel: 00 Id: 01 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02
在此处,有两块直连(Direct-Access)的scsi磁盘,一块通过光驱cd-rom连接的光盘。我们只考虑scsi磁盘,所以这两块磁盘在scsi中的定位符为2:0:0:0和2:0:1:0。如果继续插入一块盘,那么新盘在scsi中的定位符为2:0:2:0,这个数值串非常重要。
1.1 热插
在向计算机中插入一块磁盘后,内核因为识别不了它所以不会产生任何事件通知,因此在/sys目录中不会产生任何文件,任何工具也就读取不了它。重启系统肯定是可以解决的,但是Linux支持热插。
热插新盘的方式是向/proc/scsi/scsi中写入新scsi设备的信息。方式如下:
echo "scsi add-single-device a b c d" >/proc/scsi/scsi
其中:
a == hostadapter id (first one being 0)
b == SCSI channel on hostadapter (first one being 0)
c == ID
d == LUN (first one being 0)
例如上面的例子,应该添加如下信息:
[root@server2 ~]# echo "scsi add-single-device 2:0:2:0" >/proc/scsi/scsi
当然,重新扫描scsi总线也可以实现热插的功能。因为上面的例子中,scsi host id为2(即host2),所以扫描的是host2,这样host2这个scsi上的所有设备都会被重新扫描。
[root@server2 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
如果不知道要扫描哪个host,直接使用循环全部扫描。
[root@xuexi ~]# for i in `ls /sys/class/scsi_host/`;do echo "- - -" >/sys/class/scsi_host/$i/scan;done
热插之后,fdisk -l等命令就可以识别到该磁盘了。
1.2 热拔
热拔磁盘的方式是在/proc/scsi/scsi中移除对应scsi设备的信息。方式如下:
echo "scsi remove-single-device a b c d" >/proc/scsi/scsi
例如删除2:0:2:0这块磁盘。
[root@server2 ~]# echo "scsi remove-single-device 2 0 2 0" >/proc/scsi/scsi
因为要删除的设备已经存在,/sys中已经有它完整的信息,所以也从其自身设备上进行删除。
首先查看scsi设备信息。
[root@server2 ~]# lsscsi [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 [4:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
例如要删除/dev/sdb,即2:0:1:0。先看看它的文件信息。
[root@server2 ~]# ls /sys/bus/scsi/drivers/sd/2\:0\:1\:0/block/ evt_lun_change_reported model scsi_level bsg/ evt_media_change power/ statedelete evt_mode_parameter_change_reported queue_depth subsystem/device_blocked evt_soft_threshold_reached queue_ramp_up_period timeout device_busy generic/ queue_type type dh_state iocounterbits rescan uevent driver/ iodone_cnt rev unpriv_sgio eh_timeout ioerr_cnt scsi_device/ vendor evt_capacity_change_reported iorequest_cnt scsi_disk/ vpd_pg80 evt_inquiry_change_reported modalias scsi_generic/ vpd_pg83
在其中有3个文件:delete、rescan和state。其中state记录了该设备是否正在运行中。而delete和rescan文件则用于删除和重新扫描该设备。
例如,删除该设备,即热拔。
[root@server2 ~]# echo 1 > /sys/bus/scsi/drivers/sd/2\:0\:1\:0/delete
The above is the detailed content of What does disk hot-plugging mean on Linux?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)
