KVM maps scsi disks to virtual machines

Source: Internet
Author: User

KVM maps scsi disks to virtual machines. Note: physical machine redhat6.4, but a redhat 5.5 is installed on the Virtual machine. lsscsi cannot be used on the vm. Therefore, the vm Version 5.5 is too low, the kernel cannot be identified. Therefore, we installed a kernel version higher than redhat6.4 to confirm this problem. We found that we can see the disk and share the process we studied with you. 1. Modify the xml file of the System Configuration. 1. The specific path is in:/etc/libvirt/qemu/guest_ OS .xml (do not modify this file manually, after modification, you will find that the xml file seen by the virsh dumpxml guest_ OS is still modified.) There are two ways to modify the file: a: Add a controller, find a directory, and touch tmp. xml, edit the file, and add the following content: <? Xml version = "1.0"?> <Controller index = "bruce" model = "virtio-scsi" type = "scsi"/> then write a small script to add the controller: # for I in {0 .. 3}> do> sed "s/bruce/$ I/g"/controller. xml>/con. xml> virsh attach-device johnny_zeng/con. xml -- config> echo "Begin to attach device $ I... "> doneDevice attached successfully Begin to attach device 0... device attached successfully Begin to attach device 1... device attached successfully Begin to attach devic E 2... device attached successfully Begin to attach device 3... b: Add a scsi disk and find a directory, touch tmp. edit the file and add the following content: <disk type = "block" device = "lun" sgio = "unfiltered"> <driver name = "qemu" type = "raw" cache = "none"/> <source dev = "/dev/disk/by-path/pci-0000: 08: 00.0-fc-0x500009780800a124-lun-20 "/> <target dev =" sda "bus =" scsi "/> <shareable/> <alias name =" scsi0-0-0-4 "/> <address type =" drive" controller =" 0 "bus =" 0 "target =" 0 "unit =" 5 "/> </disk> the preceding content is modified as follows: ls-l/dev/disk/by-path/| grep-v part | grep-I fc search, you will find many san disks. The content in the second part has been tested and found that as long as the content starts with vdx, sdx, hdx, and x can contain letters and numbers, but the dev attribute values must be different each time. The content of the third red line, as the name suggests, is an alias. Therefore, it is best to use the scsi + controller-0-0-id method. The red part at the fourth part indicates that the first is the Controller id (required when ing the multi-path disk) and the second is the disk id, however, the Controller id + disk id cannot overlap with other disks. For example, if controller 1 and disk id are added to this disk, the disk id is, you cannot add the same controller as 1 and disk id as 1 next time. After modification, add the device to virsh attach-device guest_ OS/tmp. xml -- config. You can also modify and save virsh edit guest_ OS, and then save it to the system through save guest_ OS/etc/libvirt/qemu/guest_ OS .xml. If you want to add hundreds of disks, this method is obviously not feasible. Therefore, you need to write a script: It is really easy to share my script. A new template file bruce is created under the root directory. xml: <disk type = "block" device = "lun" sgio = "unfiltered"> <driver name = "qemu" type = "raw" cache = "none"/> <source dev = "/dev/disk/by-path/kenny"/> <target dev = "sdyang" bus = "scsi"/> <retriable/> <alias name = "scsicontrollers-0-0-number" /> <address type = "drive" controller = "controllers" bus = "0" target = "0" unit = "number"/> </disk> and then add: #! /Bin/sh controler = 0 count = 0 ls/dev/disk/by-path/| grep-v part | grep fc | while read line do number = 'echo $ line | cut-d--f 6 'sed "s/kenny/$ line/g" bruce. xml | sed "s/yang/$ number $ controler/g" | sed "s/controllers/$ controler/g" | sed "s/number/$ number/g"> /yang. xml echo "begin to attach device $ number to xml file, controler is $ controler... "virsh attach-device bruce_yang/yang. xml -- config if test $? -Eq 1 then echo "Failed to attach device to xml file... "exit 1 fi count = 'expr $ count + 1' if test $ count-eq 10 then count = 0 controler = 'expr $ controler + 1' fi done ~ ~ I know that there are ten disks, so I think it is equal to 10. The calculation method is very simple. ls/dev/disk/by-path/| grep-v part | grep fc | wc-l, divide the calculated result by the paths, that is, the number of paths. 2. log on to the vm and check the scsi disk # lsscsi [2: 0: 0: 1] disk emc symmetrix 5874/dev/sdd [2: 0: 0: 0: 4] disk emc symmetrix 5874/dev/sde [2: 0: 0: 5] disk emc symmetrix 5874/dev/sdf [3: 0: 0: 0: 15] disk emc symmetrix 5874/dev/sda [4: 0: 0: 3] disk emc symmetrix 5874/dev/sdb [5: 0: 0: 0: 1] disk emc symmetrix 5874/dev/sdc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.