在不重启的情况下为 VMware Linux 客户机添加新硬盘

作为一名系统管理员,我经常需要用额外的硬盘来扩充存储空间或将系统数据从用户数据中分离出来。我将告诉你在将物理块设备加到虚拟主机的这个过程中,如何将一个主机上的硬盘加到一台使用 VMWare 软件虚拟化的 Linux 客户机上。

你可以显式的添加或删除一个 SCSI 设备,或者重新扫描整个 SCSI 总线而不用重启 Linux 虚拟机。本指南在 Vmware Server 和 Vmware Workstation v6.0 中通过测试(更老版本应该也支持)。所有命令在 RHEL、Fedora、CentOS 和 Ubuntu Linux 客户机 / 主机操作系统下都经过了测试。

 

步骤 1:添加新硬盘到虚拟客户机

首先,通过 vmware 硬件设置菜单添加硬盘。点击 “VM > Settings”

在不重启的情况下为 VMware Linux 客户机添加新硬盘

Vmware Virtual Machine Settings

或者你也可以按下 CTRL + D 也能进入设置对话框。

点击 “Add” 添加新硬盘到客户机:

在不重启的情况下为 VMware Linux 客户机添加新硬盘

VMWare adding a new hardware

选择硬件类型为“Hard disk”然后点击 “Next”:

在不重启的情况下为 VMware Linux 客户机添加新硬盘

VMware Adding a new disk wizard

选择 “create a new virtual disk” 然后点击 “Next”:

在不重启的情况下为 VMware Linux 客户机添加新硬盘

Vmware Wizard Disk

设置虚拟磁盘类型为 “SCSI” ,然后点击 “Next”:

在不重启的情况下为 VMware Linux 客户机添加新硬盘

Vmware Virtual Disk

按需要设置最大磁盘大小,然后点击 “Next”

在不重启的情况下为 VMware Linux 客户机添加新硬盘

Finalizing Disk Virtual Addition

最后,选择文件存放位置然后点击 “Finish”。

 

步骤 2:重新扫描 SCSI 总线,在不重启虚拟机的情况下添加 SCSI 设备

输入下面命令重新扫描 SCSI 总线:

  1. <span class="kwd">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">host</span><span class="com">#</span><span class="pun">/</span><span class="pln">scan</span>
  2. <span class="kwd">fdisk</span><span class="pun">-</span><span class="pln">l</span>
  3. <span class="kwd">tail</span><span class="pun">-</span><span class="pln">f </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">message</span>

输出为:

在不重启的情况下为 VMware Linux 客户机添加新硬盘

Linux Vmware Rescan New Scsi Disk Without Reboot

你需要将 host# 替换成真实的值,比如 host0。你可以通过下面命令来查出这个值:

# ls /sys/class/scsi_host

输出:

  1. <span class="pln">host0</span>

然后输入下面过命令来请求重新扫描:

  1. <span class="kwd">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>
  2. <span class="kwd">fdisk</span><span class="pun">-</span><span class="pln">l</span>
  3. <span class="kwd">tail</span><span class="pun">-</span><span class="pln">f </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">message</span>

输出为:

  1. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="typ">Vendor</span><span class="pun">:</span><span class="typ">VMware</span><span class="pun">,</span><span class="typ">Model</span><span class="pun">:</span><span class="typ">VMware</span><span class="typ">Virtual</span><span class="pln"> S </span><span class="typ">Rev</span><span class="pun">:</span><span class="lit">1.0</span>
  2. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="typ">Type</span><span class="pun">:</span><span class="typ">Direct</span><span class="pun">-</span><span class="typ">Access</span><span class="pln"> ANSI SCSI revision</span><span class="pun">:</span><span class="lit">02</span>
  3. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="typ">Beginning</span><span class="typ">Domain</span><span class="typ">Validation</span>
  4. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="typ">Domain</span><span class="typ">Validation</span><span class="pln"> skipping </span><span class="kwd">write</span><span class="pln"> tests</span>
  5. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="typ">Ending</span><span class="typ">Domain</span><span class="typ">Validation</span>
  6. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="pln"> FAST</span><span class="pun">-</span><span class="lit">40</span><span class="pln"> WIDE SCSI </span><span class="lit">80.0</span><span class="pln"> MB</span><span class="pun">/</span><span class="pln">s ST </span><span class="pun">(</span><span class="lit">25</span><span class="pln"> ns</span><span class="pun">,</span><span class="pln"> offset </span><span class="lit">127</span><span class="pun">)</span>
  7. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> SCSI device sdb</span><span class="pun">:</span><span class="lit">2097152</span><span class="lit">512</span><span class="pun">-</span><span class="pln">byte hdwr sectors </span><span class="pun">(</span><span class="lit">1074</span><span class="pln"> MB</span><span class="pun">)</span>
  8. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="typ">Write</span><span class="typ">Protect</span><span class="kwd">is</span><span class="pln"> off</span>
  9. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="pln"> cache data unavailable</span>
  10. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="pln"> assuming drive cache</span><span class="pun">:</span><span class="kwd">write</span><span class="pln"> through</span>
  11. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> SCSI device sdb</span><span class="pun">:</span><span class="lit">2097152</span><span class="lit">512</span><span class="pun">-</span><span class="pln">byte hdwr sectors </span><span class="pun">(</span><span class="lit">1074</span><span class="pln"> MB</span><span class="pun">)</span>
  12. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="typ">Write</span><span class="typ">Protect</span><span class="kwd">is</span><span class="pln"> off</span>
  13. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="pln"> cache data unavailable</span>
  14. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="pln"> assuming drive cache</span><span class="pun">:</span><span class="kwd">write</span><span class="pln"> through</span>
  15. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdb</span><span class="pun">:</span><span class="pln"> unknown partition table</span>
  16. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sd </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="typ">Attached</span><span class="pln"> scsi disk sdb</span>
  17. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sd </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">1</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="typ">Attached</span><span class="pln"> scsi </span><span class="kwd">generic</span><span class="pln"> sg1 type </span><span class="lit">0</span>
  18. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="typ">Vendor</span><span class="pun">:</span><span class="typ">VMware</span><span class="pun">,</span><span class="typ">Model</span><span class="pun">:</span><span class="typ">VMware</span><span class="typ">Virtual</span><span class="pln"> S </span><span class="typ">Rev</span><span class="pun">:</span><span class="lit">1.0</span>
  19. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="typ">Type</span><span class="pun">:</span><span class="typ">Direct</span><span class="pun">-</span><span class="typ">Access</span><span class="pln"> ANSI SCSI revision</span><span class="pun">:</span><span class="lit">02</span>
  20. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="typ">Beginning</span><span class="typ">Domain</span><span class="typ">Validation</span>
  21. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="typ">Domain</span><span class="typ">Validation</span><span class="pln"> skipping </span><span class="kwd">write</span><span class="pln"> tests</span>
  22. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="typ">Ending</span><span class="typ">Domain</span><span class="typ">Validation</span>
  23. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> target0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="pln"> FAST</span><span class="pun">-</span><span class="lit">40</span><span class="pln"> WIDE SCSI </span><span class="lit">80.0</span><span class="pln"> MB</span><span class="pun">/</span><span class="pln">s ST </span><span class="pun">(</span><span class="lit">25</span><span class="pln"> ns</span><span class="pun">,</span><span class="pln"> offset </span><span class="lit">127</span><span class="pun">)</span>
  24. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> SCSI device sdc</span><span class="pun">:</span><span class="lit">2097152</span><span class="lit">512</span><span class="pun">-</span><span class="pln">byte hdwr sectors </span><span class="pun">(</span><span class="lit">1074</span><span class="pln"> MB</span><span class="pun">)</span>
  25. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="typ">Write</span><span class="typ">Protect</span><span class="kwd">is</span><span class="pln"> off</span>
  26. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="pln"> cache data unavailable</span>
  27. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="pln"> assuming drive cache</span><span class="pun">:</span><span class="kwd">write</span><span class="pln"> through</span>
  28. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> SCSI device sdc</span><span class="pun">:</span><span class="lit">2097152</span><span class="lit">512</span><span class="pun">-</span><span class="pln">byte hdwr sectors </span><span class="pun">(</span><span class="lit">1074</span><span class="pln"> MB</span><span class="pun">)</span>
  29. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="typ">Write</span><span class="typ">Protect</span><span class="kwd">is</span><span class="pln"> off</span>
  30. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="pln"> cache data unavailable</span>
  31. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="pln"> assuming drive cache</span><span class="pun">:</span><span class="kwd">write</span><span class="pln"> through</span>
  32. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sdc</span><span class="pun">:</span><span class="pln"> unknown partition table</span>
  33. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sd </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="typ">Attached</span><span class="pln"> scsi disk sdc</span>
  34. <span class="typ">Jul</span><span class="lit">18</span><span class="lit">16</span><span class="pun">:</span><span class="lit">29</span><span class="pun">:</span><span class="lit">39</span><span class="pln"> localhost kernel</span><span class="pun">:</span><span class="pln"> sd </span><span class="lit">0</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="lit">2</span><span class="pun">:</span><span class="lit">0</span><span class="pun">:</span><span class="typ">Attached</span><span class="pln"> scsi </span><span class="kwd">generic</span><span class="pln"> sg2 type </span><span class="lit">0</span>

 

如何删除 /dev/sdc 这块设备?

除了重新扫描整个总线外,你也可以使用下面命令添加或删除指定磁盘:

  1. <span class="com">#</span><span class="kwd">echo</span><span class="lit">1</span><span class="pun">></span><span class="str">/sys/</span><span class="pln">block</span><span class="pun">/</span><span class="pln">devName</span><span class="pun">/</span><span class="pln">device</span><span class="pun">/</span><span class="kwd">delete</span>
  2. <span class="com">#</span><span class="kwd">echo</span><span class="lit">1</span><span class="pun">></span><span class="str">/sys/</span><span class="pln">block</span><span class="pun">/</span><span class="pln">sdc</span><span class="pun">/</span><span class="pln">device</span><span class="pun">/</span><span class="kwd">delete</span>

 

如何添加 /dev/sdc 这块设备?

使用下面语法添加指定设备:

  1. <span class="com">#</span><span class="kwd">echo</span><span class="str">"scsi add-single-device <H> <B> <T> <L>"</span><span class="pun">></span><span class="str">/proc/</span><span class="pln">scsi</span><span class="pun">/</span><span class="pln">scsi</span>

这里,

  • :主机
  • :总线(通道)
  • :目标 (Id)
  • :LUN 号

例如。使用参数 host#0bus#0target#2,以及 LUN#0 来添加 /dev/sdc,则输入:

  1. <span class="com">#</span><span class="kwd">echo</span><span class="str">"scsi add-single-device 0 0 2 0"</span><span class="pun">></span><span class="str">/proc/</span><span class="pln">scsi</span><span class="pun">/</span><span class="pln">scsi</span>
  2. <span class="com">#</span><span class="kwd">fdisk</span><span class="pun">-</span><span class="pln">l</span>
  3. <span class="com">#</span><span class="kwd">cat</span><span class="pun">/</span><span class="pln">proc</span><span class="pun">/</span><span class="pln">scsi</span><span class="pun">/</span><span class="pln">scsi</span>

结果输出:

  1. <span class="typ">Attached</span><span class="pln"> devices</span><span class="pun">:</span>
  2. <span class="typ">Host</span><span class="pun">:</span><span class="pln"> scsi0 </span><span class="typ">Channel</span><span class="pun">:</span><span class="lit">00</span><span class="typ">Id</span><span class="pun">:</span><span class="lit">00</span><span class="typ">Lun</span><span class="pun">:</span><span class="lit">00</span>
  3. <span class="typ">Vendor</span><span class="pun">:</span><span class="typ">VMware</span><span class="pun">,</span><span class="typ">Model</span><span class="pun">:</span><span class="typ">VMware</span><span class="typ">Virtual</span><span class="pln"> S </span><span class="typ">Rev</span><span class="pun">:</span><span class="lit">1.0</span>
  4. <span class="typ">Type</span><span class="pun">:</span><span class="typ">Direct</span><span class="pun">-</span><span class="typ">Access</span><span class="pln"> ANSI SCSI revision</span><span class="pun">:</span><span class="lit">02</span>
  5. <span class="typ">Host</span><span class="pun">:</span><span class="pln"> scsi0 </span><span class="typ">Channel</span><span class="pun">:</span><span class="lit">00</span><span class="typ">Id</span><span class="pun">:</span><span class="lit">01</span><span class="typ">Lun</span><span class="pun">:</span><span class="lit">00</span>
  6. <span class="typ">Vendor</span><span class="pun">:</span><span class="typ">VMware</span><span class="pun">,</span><span class="typ">Model</span><span class="pun">:</span><span class="typ">VMware</span><span class="typ">Virtual</span><span class="pln"> S </span><span class="typ">Rev</span><span class="pun">:</span><span class="lit">1.0</span>
  7. <span class="typ">Type</span><span class="pun">:</span><span class="typ">Direct</span><span class="pun">-</span><span class="typ">Access</span><span class="pln"> ANSI SCSI revision</span><span class="pun">:</span><span class="lit">02</span>
  8. <span class="typ">Host</span><span class="pun">:</span><span class="pln"> scsi0 </span><span class="typ">Channel</span><span class="pun">:</span><span class="lit">00</span><span class="typ">Id</span><span class="pun">:</span><span class="lit">02</span><span class="typ">Lun</span><span class="pun">:</span><span class="lit">00</span>
  9. <span class="typ">Vendor</span><span class="pun">:</span><span class="typ">VMware</span><span class="pun">,</span><span class="typ">Model</span><span class="pun">:</span><span class="typ">VMware</span><span class="typ">Virtual</span><span class="pln"> S </span><span class="typ">Rev</span><span class="pun">:</span><span class="lit">1.0</span>
  10. <span class="typ">Type</span><span class="pun">:</span><span class="typ">Direct</span><span class="pun">-</span><span class="typ">Access</span><span class="pln"> ANSI SCSI revision</span><span class="pun">:</span><span class="lit">02</span>

 

步骤 #3:格式化新磁盘

现在使用 fdisk 并通过 mkfs.ext3 命令创建分区:

  1. <span class="com">#</span><span class="kwd">fdisk</span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdc</span>
  2. <span class="com">### [if you want ext3 fs] ###</span>
  3. <span class="com">#</span><span class="kwd">mkfs</span><span class="pun">.</span><span class="pln">ext3 </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdc3</span>
  4. <span class="com">### [if you want ext4 fs] ###</span>
  5. <span class="com">#</span><span class="kwd">mkfs</span><span class="pun">.</span><span class="pln">ext4 </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdc3</span>

 

步骤 #4:创建挂载点并更新 /etc/fstab

  1. <span class="com">#</span><span class="kwd">mkdir</span><span class="pun">/</span><span class="pln">disk3</span>

打开 /etc/fstab 文件,输入:

  1. <span class="com">#</span><span class="kwd">vi</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">fstab</span>

加入下面这行:

  1. <span class="str">/dev/</span><span class="pln">sdc3 </span><span class="pun">/</span><span class="pln">disk3 ext3 defaults </span><span class="lit">1</span><span class="lit">2</span>

若是 ext4 文件系统则加入:

  1. <span class="str">/dev/</span><span class="pln">sdc3 </span><span class="pun">/</span><span class="pln">disk3 ext4 defaults </span><span class="lit">1</span><span class="lit">2</span>

保存并关闭文件。

 

可选操作:为分区加标签

你可以使用 e2label 命令为分区加标签 。假设,你想要为 /backupDisk 这块新分区加标签,则输入:

  1. <span class="com">#</span><span class="pln"> e2label </span><span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">sdc1 </span><span class="pun">/</span><span class="pln">backupDisk</span>

详情参见 "Linux 分区的重要性

 

关于作者

作者是 nixCraft 的创始人,也是一名经验丰富的系统管理员,还是 Linux 操作系统 /Unix shell 脚本培训师。他曾服务过全球客户并与多个行业合作过,包括 IT,教育,国防和空间研究,以及非盈利机构。你可以在 TwitterFacebookGoogle+ 上关注他。


via: https://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-guest.html

作者:Vivek Gite 译者:lujun9972 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关推荐