Adding SCSI Controller / SCSI Disks to KVM-based Guests
http://www.tokiwinter.com/adding-scsi-controller-scsi-disks-to-kvm-based-guests/Following on from my previousarticle I wanted to add a SCSI disk to a KVM-based guest (hostname: mars). The guest was installed via kickstart withall volumes on /dev/vda. I’dseen 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 tofast-allocate the required image:
1# fallocate -l 20480M /var/lib/libvirt/images/mars-dev-sda.imgNext, I created the appropriate XML configuration for the new disk device:
123456#cat /var/tmp/mars-dev-sda.xml <disktype='file'device='disk'> <drivername='qemu'type='raw'cache='none'/> <sourcefile='/var/lib/libvirt/images/mars-dev-sda.img'/> <targetdev='sda'/></disk>Trying to attach this device via virsh yieldedthe following unpleasantness:
123# virsh attach-device --config mars /var/tmp/mars-dev-sda.xmlerror: Failed to attach device from /var/tmp/mars-dev-sda.xmlerror: internal error Unable to determine model for scsi controllerOK – 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:
12345678910# lspci00: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 544600:03.0 Ethernet controller: Red Hat, Inc Virtio network device00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device00:05.0 RAM memory: Red Hat, Inc Virtio memory balloonOK – so there is a SCSI controller available, but it’s for the virtio block devices. Looking at theRed 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.*scsiLet’s create a simple XML configuration file for our new SCSI controller:
12# 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.xmlDumping the guest domain’s XML should now show the controller added to the configuration:
12# virsh dumpxml mars | grep controller.*scsi <controller type='scsi' index='0' model='virtio-scsi'>On the guest, lspci should show the new controller added:
1234567891011#lspci00:00.0Hostbridge:IntelCorporation440FX-82441FXPMC[Natoma](rev02)00:01.0ISAbridge:IntelCorporation82371SBPIIX3ISA[Natoma/TritonII]00:01.1IDEinterface:IntelCorporation82371SBPIIX3IDE[Natoma/TritonII]00:01.2USBcontroller:IntelCorporation82371SBPIIX3USB[Natoma/TritonII](rev01)00:01.3Bridge:IntelCorporation82371AB/EB/MBPIIX4ACPI(rev03)00:02.0VGAcompatiblecontroller:CirrusLogicGD544600:03.0Ethernetcontroller:RedHat,IncVirtionetworkdevice00:04.0SCSIstoragecontroller:RedHat,IncVirtioblockdevice00:05.0RAMmemory:RedHat,IncVirtiomemoryballoon00:06.0SCSIstoragecontroller:RedHat,IncDevice1004The controller appears as “Device 1004“. I was then able to add the disk device as an appropriate SCSI drive:
12# virsh attach-device --config mars /var/tmp/mars-dev-sda.xmlDevice attached successfullyAnd on the guest, fdisk proves it’s there:
12345678#fdisk -l /dev/sda Disk/dev/sda:21.5GB,21474836480bytes64heads,32sectors/track,20480cylindersUnits=cylindersof2048*512=1048576bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDiskidentifier:0x00000000As does a quick probe with lsscsi:
12#lsscsi[2:0:0:0] disk QEMU QEMUHARDDISK 0.12/dev/sdaAs I like making things difficult for myself, I’ll be placing a btrfs filesystemon 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 showsthat 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 (atleast you will on virt-manager version0.9.0).
Related posts:
[*]AddingStorage Devices to KVM-Based Guests
[*]ReconfiguringKVM-based networking DHCP range with virsh
页:
[1]