如何使用VBoxManage为VirtualBox中的磁盘设置SCSI主机编号?
Nice question! Let’s walk through exactly how to set the SCSI host number for your disks in VirtualBox using VBoxManage—I’ve done this a few times with multi-disk VMs, so I’ll break it down step by step.
1. First, Set Up a SCSI Controller (If You Haven’t Already)
Since you were using SATA for your existing 30 disks, you’ll need to add a SCSI controller to your CentOS 7.4 VM first. Pick a controller type compatible with CentOS 7.4—LsiLogic is a reliable default, but LsiLogicSAS or BusLogic also work:
VBoxManage storagectl "YourCentOSVMName" --name "SCSI Controller" --add scsi --controller LsiLogic --hostiocache on
--hostiocacheenables host-side IO caching (optional but recommended for better performance with some workloads).
2. Assign a Custom SCSI Host Number to the Controller
The SCSI host number is tied to the controller itself. To set a custom host number (e.g., 5), use the setextradata command:
VBoxManage setextradata "YourCentOSVMName" "VBoxInternal/Devices/lsi/0/Config/HostNumber" "5"
- Note the
lsisegment: this matches the controller type you chose. Swap it forbuslogicif you used BusLogic, orlsisasfor LsiLogicSAS. - The
0is the controller instance number—if you add multiple SCSI controllers, increment this to1,2, etc.
3. (Optional) Assign Custom Target IDs to Individual Disks
If you want to specify exact target IDs for each SCSI disk (instead of letting VirtualBox auto-assign them), you have two options:
Option A: Assign During Disk Attachment
When creating and attaching a disk, use --port to set the target ID and --device for the LUN (usually 0 for standard disks):
# Create a fixed-size VDI (matching your existing SATA disk configuration) VBoxManage createmedium disk --filename "scsi-disk-0.vdi" --size 100 --format VDI --variant fixed # Attach it to SCSI controller port 3 (target ID 3), LUN 0 VBoxManage storageattach "YourCentOSVMName" --storagectl "SCSI Controller" --port 3 --device 0 --type hdd --medium "scsi-disk-0.vdi"
Option B: Override Existing Assignments with setextradata
If you already attached disks and want to tweak their target IDs later:
VBoxManage setextradata "YourCentOSVMName" "VBoxInternal/Devices/lsi/0/Config/Target3/LUN0/PortNumber" "0"
This maps the disk on SCSI port 0 to target ID 3.
4. Verify Your Configuration
Before starting the VM, double-check your extra data settings to confirm everything is correct:
VBoxManage getextradata "YourCentOSVMName" enumerate
Once the VM is running, install lsscsi in CentOS to see the host number and target IDs in action:
yum install -y lsscsi lsscsi
You’ll see output like this, where 5 is your custom host number and 3 is the target ID:
[5:3:0:0] disk ATA VBOX HARDDISK 1.0 /dev/sdb
内容的提问来源于stack exchange,提问作者Will Johnson

