


首先获取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!

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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