身為系統管理員,我經常需要用額外的硬碟來擴充儲存空間或將系統資料從使用者資料中分離出來。我將告訴你在將實體區塊裝置加入虛擬主機的這個過程中,如何將一個主機上的硬碟加到一台使用 VMWare 軟體虛擬化的 Linux 用戶端。
#你可以明確的新增或刪除一個 SCSI 設備,或是重新掃描整個 SCSI 匯流排而不用重新啟動 Linux 虛擬機器。本指南在 Vmware Server 和 Vmware Workstation v6.0 中通過測試(更舊版本也應該支援)。所有命令在 RHEL、Fedora、CentOS 和 Ubuntu Linux 用戶端 / 主機作業系統下都經過了測試。
#首先,透過 vmware 硬體設定選單新增硬碟。點選 “VM > Settings”
#或你也可以按下 CTRL D 也能進入設定對話框。
點選 “Add” 新增硬碟到客戶機:
#選擇硬體類型為「Hard disk」然後點選 “Next”:
#選擇 “create a new virtual disk” 然後點選 “Next”:
#設定虛擬磁碟類型為 “SCSI” ,然後點選 “Next”:
# 依需求設定最大磁碟大小,然後點選 “Next”
#最後,選擇檔案存放位置然後點選 「Finish」。
輸入下方指令重新掃描 SCSI 匯流排:
echo "- - -" > /sys/class/scsi_host/host# /scan fdisk -l tail -f /var/log/message
輸出為:
#你需要將 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
#除了重新掃描整個總線外,你也可以使用下方指令新增或刪除指定磁碟:
# echo 1 > /sys/block/devName/device/delete # echo 1 > /sys/block/sdc/device/delete
使用下面语法添加指定设备:
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
这里,
例如。使用参数 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
现在使用 fdisk 并通过 mkfs.ext3[1] 命令创建分区:
# fdisk /dev/sdc ### [if you want ext3 fs] ### # mkfs.ext3 /dev/sdc3 ### [if you want ext4 fs] ### # mkfs.ext4 /dev/sdc3
# mkdir /disk3
打开 /etc/fstab 文件,输入:
# vi /etc/fstab
加入下面这行:
/dev/sdc3 /disk3 ext3 defaults 1 2
若是 ext4 文件系统则加入:
/dev/sdc3 /disk3 ext4 defaults 1 2
保存并关闭文件。
你可以使用 e2label 命令为分区加标签 [2]。假设,你想要为 /backupDisk 这块新分区加标签,则输入:
# e2label /dev/sdc1 /backupDisk
详情参见 "Linux 分区的重要性 [3]。
以上是在不重新啟動虛擬機器的情況下為 Linux 用戶端新增硬碟的詳細內容。更多資訊請關注PHP中文網其他相關文章!