如何不用重启在CentOS 7/ RHEL 7虚拟机中添加一块新硬盘
通常在你在虚拟机中添加一块新硬盘时,你可能会看到新硬盘没有自动加载。这是因为连接到硬盘的SCSI总线需要重新扫描来使得新硬盘可见。这里有一个简单的命令来重新扫描SCSI总线和SCSI设备。下面这几步在CentOS 7 和RHEL 7 中测试过。
在ESXi或者vCenter中添加一块新的20G硬盘:
显示当前磁盘分区:
<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> fdisk </span><span class="pun">-</span><span class="pln">l</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda</span><span class="pun">:</span><span class="lit">32.2</span><span class="pln"> GB</span><span class="pun">,</span><span class="lit">32212254720</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">62914560</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Disk</span><span class="pln"> label type</span><span class="pun">:</span><span class="pln"> dos</span>
<span class="typ">Disk</span><span class="pln"> identifier</span><span class="pun">:</span><span class="lit">0x0006b96a</span>
<span class="typ">Device</span><span class="typ">Boot</span><span class="typ">Start</span><span class="typ">End</span><span class="typ">Blocks</span><span class="typ">Id</span><span class="typ">System</span>
<span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda1 </span><span class="pun">*</span><span class="lit">2048</span><span class="lit">1026047</span><span class="lit">512000</span><span class="lit">83</span><span class="typ">Linux</span>
<span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda2 </span><span class="lit">1026048</span><span class="lit">62914559</span><span class="lit">30944256</span><span class="lit">8e</span><span class="typ">Linux</span><span class="pln"> LVM</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">swap</span><span class="pun">:</span><span class="lit">2147</span><span class="pln"> MB</span><span class="pun">,</span><span class="lit">2147483648</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">4194304</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">root</span><span class="pun">:</span><span class="lit">29.5</span><span class="pln"> GB</span><span class="pun">,</span><span class="lit">29536288768</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">57688064</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
确定主机总线号
<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> ls </span><span class="pun">/</span><span class="pln">sys</span><span class="pun">/</span><span class="kwd">class</span><span class="pun">/</span><span class="pln">scsi_host</span><span class="pun">/</span>
<span class="pln">host0 host1 host2</span>
重新扫描SCSI总线来添加设备
<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> echo </span><span class="str">"- - -"</span><span class="pun">></span><span class="str">/sys/</span><span class="kwd">class</span><span class="pun">/</span><span class="pln">scsi_host</span><span class="pun">/</span><span class="pln">host0</span><span class="pun">/</span><span class="pln">scan</span>
<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> echo </span><span class="str">"- - -"</span><span class="pun">></span><span class="str">/sys/</span><span class="kwd">class</span><span class="pun">/</span><span class="pln">scsi_host</span><span class="pun">/</span><span class="pln">host1</span><span class="pun">/</span><span class="pln">scan</span>
<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> echo </span><span class="str">"- - -"</span><span class="pun">></span><span class="str">/sys/</span><span class="kwd">class</span><span class="pun">/</span><span class="pln">scsi_host</span><span class="pun">/</span><span class="pln">host2</span><span class="pun">/</span><span class="pln">scan</span>
验证磁盘和分区并确保20GB硬盘已经添加了。在本例中,出现了下面这行 “
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
” 并且可以确认没有重启服务器就添加了新盘:<span class="pun">[</span><span class="pln">root@centos7 </span><span class="pun">~]#</span><span class="pln"> fdisk </span><span class="pun">-</span><span class="pln">l</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda</span><span class="pun">:</span><span class="lit">32.2</span><span class="pln"> GB</span><span class="pun">,</span><span class="lit">32212254720</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">62914560</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Disk</span><span class="pln"> label type</span><span class="pun">:</span><span class="pln"> dos</span>
<span class="typ">Disk</span><span class="pln"> identifier</span><span class="pun">:</span><span class="lit">0x0006b96a</span>
<span class="typ">Device</span><span class="typ">Boot</span><span class="typ">Start</span><span class="typ">End</span><span class="typ">Blocks</span><span class="typ">Id</span><span class="typ">System</span>
<span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda1 </span><span class="pun">*</span><span class="lit">2048</span><span class="lit">1026047</span><span class="lit">512000</span><span class="lit">83</span><span class="typ">Linux</span>
<span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sda2 </span><span class="lit">1026048</span><span class="lit">62914559</span><span class="lit">30944256</span><span class="lit">8e</span><span class="typ">Linux</span><span class="pln"> LVM</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">swap</span><span class="pun">:</span><span class="lit">2147</span><span class="pln"> MB</span><span class="pun">,</span><span class="lit">2147483648</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">4194304</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">mapper</span><span class="pun">/</span><span class="pln">centos</span><span class="pun">-</span><span class="pln">root</span><span class="pun">:</span><span class="lit">29.5</span><span class="pln"> GB</span><span class="pun">,</span><span class="lit">29536288768</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">57688064</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Disk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdb</span><span class="pun">:</span><span class="lit">21.5</span><span class="pln"> GB</span><span class="pun">,</span><span class="lit">21474836480</span><span class="pln"> bytes</span><span class="pun">,</span><span class="lit">41943040</span><span class="pln"> sectors</span>
<span class="typ">Units</span><span class="pun">=</span><span class="pln"> sectors of </span><span class="lit">1</span><span class="pun">*</span><span class="lit">512</span><span class="pun">=</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="typ">Sector</span><span class="pln"> size </span><span class="pun">(</span><span class="pln">logical</span><span class="pun">/</span><span class="pln">physical</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
<span class="pln">I</span><span class="pun">/</span><span class="pln">O size </span><span class="pun">(</span><span class="pln">minimum</span><span class="pun">/</span><span class="pln">optimal</span><span class="pun">):</span><span class="lit">512</span><span class="pln"> bytes </span><span class="pun">/</span><span class="lit">512</span><span class="pln"> bytes</span>
相关推荐
ScienceExplorer 2020-06-14
85251846 2020-09-14
rareli 2020-06-21
星愿心愿 2020-11-24
ruancw 2020-11-10
VFCSDN 2020-10-14
somyjun 2020-09-29
longjing 2020-09-18
KINGJENSEN 2020-09-14
周公周金桥 2020-09-06
lxttiger 2020-08-18
ARMOTO机器人 2020-08-18
atb 2020-08-17
SeetyST 2020-08-13
85206633 2020-08-15
yunna0 2020-08-15
young依然 2020-08-06
成长路上 2020-07-29