设为首页 收藏本站
查看: 1019|回复: 0

[经验分享] Adding SCSI Controller / SCSI Disks to KVM-based Guests

[复制链接]

尚未签到

发表于 2015-10-10 09:57:49 | 显示全部楼层 |阅读模式
  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[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 DSC0000.gif
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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-124970-1-1.html 上篇帖子: 使用KVM/QEMU命令安装虚拟机 下篇帖子: CentOS 5.4安装KVM
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表