Following on from my previous article I wanted to add a SCSI disk to a KVM-based guest (hostname: mars). The guest was installed via kickstart with all volumes on /dev/vda. I’d seen conflicting reports of SCSI support (the fact you can’t add the SCSI controller/disks through virt-manager, for example) so I wanted to create a SCSI disk and attach it to the host at /dev/sda.
I first used my new best friend fallocate to fast-allocate the required image:
|
1 |
# fallocate -l 20480M /var/lib/libvirt/images/mars-dev-sda.img |
Next, I created the appropriate XML configuration for the new disk device:
|
1 2 3 4 5 6 |
# cat /var/tmp/mars-dev-sda.xml <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/var/lib/libvirt/images/mars-dev-sda.img'/> <target dev='sda'/> </disk> |
Trying to attach this device via virsh yielded the following unpleasantness:
|
1 2 3 |
# virsh attach-device --config mars /var/tmp/mars-dev-sda.xml error: Failed to attach device from /var/tmp/mars-dev-sda.xml error: internal error Unable to determine model for scsi controller |
OK - let’s jump onto the guest and see what’s going on. First, I installed lspci and lsscsi so that I could diagnose the issue …
|
1 |
# yum install pciutils lsscsi |
… and ran lspci:
|
1 2 3 4 5 6 7 8 9 10 |
# lspci 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 00:03.0 Ethernet controller: Red Hat, Inc Virtio network device 00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device 00:05.0 RAM memory: Red Hat, Inc Virtio memory balloon |
OK - so there is a SCSI controller available, but it’s for the virtio block devices. Looking at the Red Hat Documentation we need to add a SCSI controller of type virtio-scsi. This can also be confirmed by the lack of output from the following command:
|
1 |
# virsh dumpxml mars | grep controller.*scsi |
Let’s create a simple XML configuration file for our new SCSI controller:
|
1 2 |
# cat /var/tmp/mars-scsi-controller.xml <controller type='scsi' model='virtio-scsi'/> |
And add it to our guest configuration:
|
1 |
# virsh attach-device --config mars /var/tmp/mars-scsi-controller.xml |
Dumping the guest domain’s XML should now show the controller added to the configuration:
|
1 2 |
# virsh dumpxml mars | grep controller.*scsi <controller type='scsi' index='0' model='virtio-scsi'> |
On the guest, lspci should show the new controller added:
|
1 2 3 4 5 6 7 8 9 10 11 |
# lspci 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 00:03.0 Ethernet controller: Red Hat, Inc Virtio network device 00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device 00:05.0 RAM memory: Red Hat, Inc Virtio memory balloon 00:06.0 SCSI storage controller: Red Hat, Inc Device 1004 |
The controller appears as “Device 1004“. I was then able to add the disk device as an appropriate SCSI drive:
|
1 2 |
# virsh attach-device --config mars /var/tmp/mars-dev-sda.xml Device attached successfully |
And on the guest, fdisk proves it’s there:
|
1 2 3 4 5 6 7 8 |
# fdisk -l /dev/sda Disk /dev/sda: 21.5 GB, 21474836480 bytes 64 heads, 32 sectors/track, 20480 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 |
As does a quick probe with lsscsi:
|
1 2 |
# lsscsi [2:0:0:0] disk QEMU QEMU HARDDISK 0.12 /dev/sda |
As I like making things difficult for myself, I’ll be placing a btrfs filesystem on this and playing around with volumes - but that’s something for another article
It’s worth noting that whilst the VM configuration within virt-manager shows that there is now a SCSI controller associated with the guest, it still will not allow the creation of SCSI disks - you’ll need to use virsh (at least you will on virt-manager version 0.9.0).