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[color=#228B22 !important]# fallocate -l 20480M /var/lib/libvirt/images/mars-dev-sda.imgNext, I created the appropriate XML configuration for the new disk device:
123456[color=#228B22!important]#cat /var/tmp/mars-dev-sda.xml [color=#228B22!important]<[color=#228B22!important]disk[color=#228B22!important]type[color=#228B22!important]=[color=#228B22!important]'file'[color=#228B22!important][color=#228B22!important]device[color=#228B22!important]=[color=#228B22!important]'disk'[color=#228B22!important]>[color=#228B22!important] [color=#228B22!important]<[color=#228B22!important]driver[color=#228B22!important]name[color=#228B22!important]=[color=#228B22!important]'qemu'[color=#228B22!important][color=#228B22!important]type[color=#228B22!important]=[color=#228B22!important]'raw'[color=#228B22!important][color=#228B22!important]cache[color=#228B22!important]=[color=#228B22!important]'none'[color=#228B22!important]/[color=#228B22!important]>[color=#228B22!important] [color=#228B22!important]<[color=#228B22!important]source[color=#228B22!important]file[color=#228B22!important]=[color=#228B22!important]'/var/lib/libvirt/images/mars-dev-sda.img'[color=#228B22!important]/[color=#228B22!important]>[color=#228B22!important] [color=#228B22!important]<[color=#228B22!important]target[color=#228B22!important]dev[color=#228B22!important]=[color=#228B22!important]'sda'[color=#228B22!important]/[color=#228B22!important]>[color=#228B22!important]<[color=#228B22!important]/[color=#228B22!important]disk[color=#228B22!important]>Trying to attach this device via virsh yieldedthe following unpleasantness:
123[color=#228B22 !important]# virsh attach-device --config mars /var/tmp/mars-dev-sda.xml[color=#228B22 !important]error[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Failed [color=#228B22 !important]to[color=#228B22 !important] [color=#228B22 !important]attach [color=#228B22 !important]device [color=#228B22 !important]from[color=#228B22 !important] [color=#228B22 !important]/[color=#228B22 !important]var[color=#228B22 !important]/[color=#228B22 !important]tmp[color=#228B22 !important]/[color=#228B22 !important]mars[color=#228B22 !important]-[color=#228B22 !important]dev[color=#228B22 !important]-[color=#228B22 !important]sda[color=#228B22 !important].xml[color=#228B22 !important]error[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]internal [color=#228B22 !important]error [color=#228B22 !important]Unable [color=#228B22 !important]to[color=#228B22 !important] [color=#228B22 !important]determine [color=#228B22 !important]model [color=#228B22 !important]for[color=#228B22 !important] [color=#228B22 !important]scsi [color=#228B22 !important]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[color=#228B22!important]#yum install pciutils lsscsi… and ran lspci:
12345678910[color=#228B22 !important]# lspci[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]00.0[color=#228B22 !important] [color=#228B22 !important]Host [color=#228B22 !important]bridge[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Intel [color=#228B22 !important]Corporation[color=#228B22 !important] [color=#228B22 !important]440FX[color=#228B22 !important] [color=#228B22 !important]-[color=#228B22 !important] [color=#228B22 !important]82441FX[color=#228B22 !important] [color=#228B22 !important]PMC[color=#228B22 !important] [color=#228B22 !important][[color=#228B22 !important]Natoma[color=#228B22 !important]][color=#228B22 !important] [color=#228B22 !important]([color=#228B22 !important]rev[color=#228B22 !important] [color=#228B22 !important]02[color=#228B22 !important])[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]01.0[color=#228B22 !important] [color=#228B22 !important]ISA [color=#228B22 !important]bridge[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Intel [color=#228B22 !important]Corporation[color=#228B22 !important] [color=#228B22 !important]82371SB[color=#228B22 !important] [color=#228B22 !important]PIIX3 [color=#228B22 !important]ISA[color=#228B22 !important] [color=#228B22 !important][[color=#228B22 !important]Natoma[color=#228B22 !important]/[color=#228B22 !important]Triton [color=#228B22 !important]II[color=#228B22 !important]][color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]01.1[color=#228B22 !important] [color=#228B22 !important]IDE [color=#228B22 !important]interface[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Intel [color=#228B22 !important]Corporation[color=#228B22 !important] [color=#228B22 !important]82371SB[color=#228B22 !important] [color=#228B22 !important]PIIX3 [color=#228B22 !important]IDE[color=#228B22 !important] [color=#228B22 !important][[color=#228B22 !important]Natoma[color=#228B22 !important]/[color=#228B22 !important]Triton [color=#228B22 !important]II[color=#228B22 !important]][color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]01.2[color=#228B22 !important] [color=#228B22 !important]USB [color=#228B22 !important]controller[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Intel [color=#228B22 !important]Corporation[color=#228B22 !important] [color=#228B22 !important]82371SB[color=#228B22 !important] [color=#228B22 !important]PIIX3 [color=#228B22 !important]USB[color=#228B22 !important] [color=#228B22 !important][[color=#228B22 !important]Natoma[color=#228B22 !important]/[color=#228B22 !important]Triton [color=#228B22 !important]II[color=#228B22 !important]][color=#228B22 !important] [color=#228B22 !important]([color=#228B22 !important]rev[color=#228B22 !important] [color=#228B22 !important]01[color=#228B22 !important])[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]01.3[color=#228B22 !important] [color=#228B22 !important]Bridge[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Intel [color=#228B22 !important]Corporation[color=#228B22 !important] [color=#228B22 !important]82371AB[color=#228B22 !important]/[color=#228B22 !important]EB[color=#228B22 !important]/[color=#228B22 !important]MB [color=#228B22 !important]PIIX4 [color=#228B22 !important]ACPI[color=#228B22 !important] [color=#228B22 !important]([color=#228B22 !important]rev[color=#228B22 !important] [color=#228B22 !important]03[color=#228B22 !important])[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]02.0[color=#228B22 !important] [color=#228B22 !important]VGA [color=#228B22 !important]compatible [color=#228B22 !important]controller[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Cirrus [color=#228B22 !important]Logic [color=#228B22 !important]GD[color=#228B22 !important] [color=#228B22 !important]5446[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]03.0[color=#228B22 !important] [color=#228B22 !important]Ethernet [color=#228B22 !important]controller[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Red [color=#228B22 !important]Hat[color=#228B22 !important],[color=#228B22 !important] [color=#228B22 !important]Inc [color=#228B22 !important]Virtio [color=#228B22 !important]network [color=#228B22 !important]device[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]04.0[color=#228B22 !important] [color=#228B22 !important]SCSI [color=#228B22 !important]storage [color=#228B22 !important]controller[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Red [color=#228B22 !important]Hat[color=#228B22 !important],[color=#228B22 !important] [color=#228B22 !important]Inc [color=#228B22 !important]Virtio [color=#228B22 !important]block [color=#228B22 !important]device[color=#228B22 !important]00[color=#228B22 !important]:[color=#228B22 !important]05.0[color=#228B22 !important] [color=#228B22 !important]RAM [color=#228B22 !important]memory[color=#228B22 !important]:[color=#228B22 !important] [color=#228B22 !important]Red [color=#228B22 !important]Hat[color=#228B22 !important],[color=#228B22 !important] [color=#228B22 !important]Inc [color=#228B22 !important]Virtio [color=#228B22 !important]memory [color=#228B22 !important]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[color=#228B22!important]#virsh dumpxml mars | grep controller.*scsiLet’s create a simple XML configuration file for our new SCSI controller:
12[color=#228B22 !important]# cat /var/tmp/mars-scsi-controller.xml[color=#228B22 !important]<[color=#228B22 !important]controller [color=#228B22 !important]type[color=#228B22 !important]=[color=#228B22 !important]'scsi'[color=#228B22 !important] [color=#228B22 !important]model[color=#228B22 !important]=[color=#228B22 !important]'virtio-scsi'[color=#228B22 !important]/[color=#228B22 !important]>And add it to our guest configuration:
1[color=#228B22!important]#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[color=#228B22 !important]# virsh dumpxml mars | grep controller.*scsi[color=#228B22 !important] [color=#228B22 !important]<[color=#228B22 !important]controller [color=#228B22 !important]type[color=#228B22 !important]=[color=#228B22 !important]'scsi'[color=#228B22 !important] [color=#228B22 !important]index[color=#228B22 !important]=[color=#228B22 !important]'0'[color=#228B22 !important] [color=#228B22 !important]model[color=#228B22 !important]=[color=#228B22 !important]'virtio-scsi'[color=#228B22 !important]>On the guest, lspci should show the new controller added:
1234567891011[color=#228B22!important]#lspci[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]00.0[color=#228B22!important][color=#228B22!important]Host[color=#228B22!important]bridge[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Intel[color=#228B22!important]Corporation[color=#228B22!important][color=#228B22!important]440FX[color=#228B22!important][color=#228B22!important]-[color=#228B22!important][color=#228B22!important]82441FX[color=#228B22!important][color=#228B22!important]PMC[color=#228B22!important][color=#228B22!important][[color=#228B22!important]Natoma[color=#228B22!important]][color=#228B22!important][color=#228B22!important]([color=#228B22!important]rev[color=#228B22!important][color=#228B22!important]02[color=#228B22!important])[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]01.0[color=#228B22!important][color=#228B22!important]ISA[color=#228B22!important]bridge[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Intel[color=#228B22!important]Corporation[color=#228B22!important][color=#228B22!important]82371SB[color=#228B22!important][color=#228B22!important]PIIX3[color=#228B22!important]ISA[color=#228B22!important][color=#228B22!important][[color=#228B22!important]Natoma[color=#228B22!important]/[color=#228B22!important]Triton[color=#228B22!important]II[color=#228B22!important]][color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]01.1[color=#228B22!important][color=#228B22!important]IDE[color=#228B22!important]interface[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Intel[color=#228B22!important]Corporation[color=#228B22!important][color=#228B22!important]82371SB[color=#228B22!important][color=#228B22!important]PIIX3[color=#228B22!important]IDE[color=#228B22!important][color=#228B22!important][[color=#228B22!important]Natoma[color=#228B22!important]/[color=#228B22!important]Triton[color=#228B22!important]II[color=#228B22!important]][color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]01.2[color=#228B22!important][color=#228B22!important]USB[color=#228B22!important]controller[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Intel[color=#228B22!important]Corporation[color=#228B22!important][color=#228B22!important]82371SB[color=#228B22!important][color=#228B22!important]PIIX3[color=#228B22!important]USB[color=#228B22!important][color=#228B22!important][[color=#228B22!important]Natoma[color=#228B22!important]/[color=#228B22!important]Triton[color=#228B22!important]II[color=#228B22!important]][color=#228B22!important][color=#228B22!important]([color=#228B22!important]rev[color=#228B22!important][color=#228B22!important]01[color=#228B22!important])[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]01.3[color=#228B22!important][color=#228B22!important]Bridge[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Intel[color=#228B22!important]Corporation[color=#228B22!important][color=#228B22!important]82371AB[color=#228B22!important]/[color=#228B22!important]EB[color=#228B22!important]/[color=#228B22!important]MB[color=#228B22!important]PIIX4[color=#228B22!important]ACPI[color=#228B22!important][color=#228B22!important]([color=#228B22!important]rev[color=#228B22!important][color=#228B22!important]03[color=#228B22!important])[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]02.0[color=#228B22!important][color=#228B22!important]VGA[color=#228B22!important]compatible[color=#228B22!important]controller[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Cirrus[color=#228B22!important]Logic[color=#228B22!important]GD[color=#228B22!important][color=#228B22!important]5446[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]03.0[color=#228B22!important][color=#228B22!important]Ethernet[color=#228B22!important]controller[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Red[color=#228B22!important]Hat[color=#228B22!important],[color=#228B22!important][color=#228B22!important]Inc[color=#228B22!important]Virtio[color=#228B22!important]network[color=#228B22!important]device[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]04.0[color=#228B22!important][color=#228B22!important]SCSI[color=#228B22!important]storage[color=#228B22!important]controller[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Red[color=#228B22!important]Hat[color=#228B22!important],[color=#228B22!important][color=#228B22!important]Inc[color=#228B22!important]Virtio[color=#228B22!important]block[color=#228B22!important]device[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]05.0[color=#228B22!important][color=#228B22!important]RAM[color=#228B22!important]memory[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Red[color=#228B22!important]Hat[color=#228B22!important],[color=#228B22!important][color=#228B22!important]Inc[color=#228B22!important]Virtio[color=#228B22!important]memory[color=#228B22!important]balloon[color=#228B22!important]00[color=#228B22!important]:[color=#228B22!important]06.0[color=#228B22!important][color=#228B22!important]SCSI[color=#228B22!important]storage[color=#228B22!important]controller[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]Red[color=#228B22!important]Hat[color=#228B22!important],[color=#228B22!important][color=#228B22!important]Inc[color=#228B22!important]Device[color=#228B22!important][color=#228B22!important]1004The controller appears as “Device 1004“. I was then able to add the disk device as an appropriate SCSI drive:
12[color=#228B22 !important]# virsh attach-device --config mars /var/tmp/mars-dev-sda.xml[color=#228B22 !important]Device [color=#228B22 !important]attached [color=#228B22 !important]successfullyAnd on the guest, fdisk proves it’s there:
12345678[color=#228B22!important]#fdisk -l /dev/sda [color=#228B22!important]Disk[color=#228B22!important][color=#228B22!important]/[color=#228B22!important]dev[color=#228B22!important]/[color=#228B22!important]sda[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]21.5[color=#228B22!important][color=#228B22!important]GB[color=#228B22!important],[color=#228B22!important][color=#228B22!important]21474836480[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important]64[color=#228B22!important][color=#228B22!important]heads[color=#228B22!important],[color=#228B22!important][color=#228B22!important]32[color=#228B22!important][color=#228B22!important]sectors[color=#228B22!important]/[color=#228B22!important]track[color=#228B22!important],[color=#228B22!important][color=#228B22!important]20480[color=#228B22!important][color=#228B22!important]cylinders[color=#228B22!important]Units[color=#228B22!important][color=#228B22!important]=[color=#228B22!important][color=#228B22!important]cylinders[color=#228B22!important]of[color=#228B22!important][color=#228B22!important]2048[color=#228B22!important][color=#228B22!important]*[color=#228B22!important][color=#228B22!important]512[color=#228B22!important][color=#228B22!important]=[color=#228B22!important][color=#228B22!important]1048576[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important]Sector[color=#228B22!important]size[color=#228B22!important][color=#228B22!important]([color=#228B22!important]logical[color=#228B22!important]/[color=#228B22!important]physical[color=#228B22!important])[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]512[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important][color=#228B22!important]/[color=#228B22!important][color=#228B22!important]512[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important]I[color=#228B22!important]/[color=#228B22!important]O[color=#228B22!important][color=#228B22!important]size[color=#228B22!important][color=#228B22!important]([color=#228B22!important]minimum[color=#228B22!important]/[color=#228B22!important]optimal[color=#228B22!important])[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]512[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important][color=#228B22!important]/[color=#228B22!important][color=#228B22!important]512[color=#228B22!important][color=#228B22!important]bytes[color=#228B22!important]Disk[color=#228B22!important]identifier[color=#228B22!important]:[color=#228B22!important][color=#228B22!important]0x00000000As does a quick probe with lsscsi:
12[color=#228B22!important]#lsscsi[color=#228B22!important][[color=#228B22!important]2[color=#228B22!important]:[color=#228B22!important]0[color=#228B22!important]:[color=#228B22!important]0[color=#228B22!important]:[color=#228B22!important]0[color=#228B22!important]][color=#228B22!important] [color=#228B22!important]disk [color=#228B22!important]QEMU [color=#228B22!important]QEMU[color=#228B22!important]HARDDISK[color=#228B22!important] [color=#228B22!important]0.12[color=#228B22!important] [color=#228B22!important]/[color=#228B22!important]dev[color=#228B22!important]/[color=#228B22!important]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