在不重啟的情況下為 Vmware Linux 客戶機添加新硬碟
你可以顯式的添加或刪除一個 SCSI 設備,或者重新掃描整個 SCSI 匯流排而不用重啟 Linux 虛擬機。本指南在 Vmware Server 和 Vmware Workstation v6.0 中通過測試(更老版本應該也支持)。所有命令在 RHEL、Fedora、CentOS 和 Ubuntu Linux 客戶機 / 主機操作系統下都經過了測試。
步驟 1:添加新硬碟到虛擬客戶機
首先,通過 vmware 硬體設置菜單添加硬碟。點擊 「VM > Settings」
![Fig.01:Vmware Virtual Machine Settings ](/data/attachment/album/201801/13/122035dmz16c9xw7zq5pop.png "Vmware Virtual Machine Settings ")
或者你也可以按下 CTRL + D
也能進入設置對話框。
點擊 「Add」 添加新硬碟到客戶機:
![Fig.02:VMWare adding a new hardware](/data/attachment/album/201801/13/122036hqxxqf7bpdzdmtlq.png "VMWare adding a new hardware")
選擇硬體類型為「Hard disk」然後點擊 「Next」:
![Fig.03 VMware Adding a new disk wizard ](/data/attachment/album/201801/13/122036syhd15qkadidm3vf.png "VMware Adding a new disk wizard ")
選擇 「create a new virtual disk」 然後點擊 「Next」:
![Fig.04:Vmware Wizard Disk ](/data/attachment/album/201801/13/122037rhmzlwp8mzh3pctp.png "Vmware Wizard Disk ")
設置虛擬磁碟類型為 「SCSI」 ,然後點擊 「Next」:
![Fig.05:Vmware Virtual Disk](/data/attachment/album/201801/13/122038vhihh9n4zxjhj7i9.png "Vmware Virtual Disk")
按需要設置最大磁碟大小,然後點擊 「Next」
![Fig.06:Finalizing Disk Virtual Addition ](/data/attachment/album/201801/13/122039rjp1pgef9mrrqxoz.png "Finalizing Disk Virtual Addition")
最後,選擇文件存放位置然後點擊 「Finish」。
步驟 2:重新掃描 SCSI 匯流排,在不重啟虛擬機的情況下添加 SCSI 設備
輸入下面命令重新掃描 SCSI 匯流排:
echo "- - -" > /sys/class/scsi_host/host# /scan
fdisk -l
tail -f /var/log/message
輸出為:
![Linux Vmware Rescan New Scsi Disk Without Reboot](/data/attachment/album/201801/13/122039n8dmdsdt341k4ba7.png "Linux Vmware Rescan New Scsi Disk Without Reboot")
你需要將 host#
替換成真實的值,比如 host0
。你可以通過下面命令來查出這個值:
# ls /sys/class/scsi_host
輸出:
host0
然後輸入下面過命令來請求重新掃描:
echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l
tail -f /var/log/message
輸出為:
Jul 18 16:29:39 localhost kernel: Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Jul 18 16:29:39 localhost kernel: Type: Direct-Access ANSI SCSI revision: 02
Jul 18 16:29:39 localhost kernel: target0:0:1: Beginning Domain Validation
Jul 18 16:29:39 localhost kernel: target0:0:1: Domain Validation skipping write tests
Jul 18 16:29:39 localhost kernel: target0:0:1: Ending Domain Validation
Jul 18 16:29:39 localhost kernel: target0:0:1: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: sdb: unknown partition table
Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi disk sdb
Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi generic sg1 type 0
Jul 18 16:29:39 localhost kernel: Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Jul 18 16:29:39 localhost kernel: Type: Direct-Access ANSI SCSI revision: 02
Jul 18 16:29:39 localhost kernel: target0:0:2: Beginning Domain Validation
Jul 18 16:29:39 localhost kernel: target0:0:2: Domain Validation skipping write tests
Jul 18 16:29:39 localhost kernel: target0:0:2: Ending Domain Validation
Jul 18 16:29:39 localhost kernel: target0:0:2: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: sdc: unknown partition table
Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi disk sdc
Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi generic sg2 type 0
如何刪除 /dev/sdc 這塊設備?
除了重新掃描整個匯流排外,你也可以使用下面命令添加或刪除指定磁碟:
# echo 1 > /sys/block/devName/device/delete
# echo 1 > /sys/block/sdc/device/delete
如何添加 /dev/sdc 這塊設備?
使用下面語法添加指定設備:
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
這裡,
- :主機
- :匯流排(通道)
- :目標 (Id)
- :LUN 號
例如。使用參數 host#0
,bus#0
,target#2
,以及 LUN#0
來添加 /dev/sdc
,則輸入:
# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
# fdisk -l
# cat /proc/scsi/scsi
結果輸出:
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
步驟 #3:格式化新磁碟
現在使用 fdisk 並通過 mkfs.ext3 命令創建分區:
# fdisk /dev/sdc
### [if you want ext3 fs] ###
# mkfs.ext3 /dev/sdc3
### [if you want ext4 fs] ###
# mkfs.ext4 /dev/sdc3
步驟 #4:創建掛載點並更新 /etc/fstab
# mkdir /disk3
打開 /etc/fstab
文件,輸入:
# vi /etc/fstab
加入下面這行:
/dev/sdc3 /disk3 ext3 defaults 1 2
若是 ext4 文件系統則加入:
/dev/sdc3 /disk3 ext4 defaults 1 2
保存並關閉文件。
可選操作:為分區加標籤
你可以使用 e2label 命令為分區加標籤 。假設,你想要為 /backupDisk
這塊新分區加標籤,則輸入:
# e2label /dev/sdc1 /backupDisk
詳情參見 "Linux 分區的重要性 。
關於作者
作者是 nixCraft 的創始人,也是一名經驗豐富的系統管理員,還是 Linux 操作系統 /Unix shell 腳本培訓師。他曾服務過全球客戶並與多個行業合作過,包括 IT,教育,國防和空間研究,以及非盈利機構。你可以在 Twitter,Facebook,Google+ 上關注他。
via: https://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-guest.html
作者:Vivek Gite 譯者:lujun9972 校對:wxy
本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive