[fedora-virt] How to use virtio-scsi on F17 host and F17 guest
Gianluca Cecchi
gianluca.cecchi at gmail.com
Fri Jun 15 09:51:33 UTC 2012
On Fri, Jun 15, 2012 at 10:20 AM, Kevin Wolf wrote:
> A quick search on the net suggests indeed that you can't modify a
> partition that is mounted/in use by LVM. So I'm afraid a new partition
> that is added to the VG must be good enough.
>
> Kevin
Actually the trick is to create PV on plain disks and not on partitions.
(thanks to the link
http://v-reality.info/2010/06/working-with-linux-volumes-n-vsphere/ I
found)
So a flexible strategy could be to make a system with
- first disk of 500Mb containing only one primary partition for /boot
(or evenually bigger to accomdate another partition for swap if one
prefers it over lvm based swap)
- second disk configured as PV for all other file systems
Successfully tested (actually on second disk)
On host
- create 4Gb disk
qemu-img create -f qcow2 /var/lib/libvirt/images/f17_sdb.img 4G
Formatting '/var/lib/libvirt/images/f17_sdb.img', fmt=qcow2
size=4294967296 encryption=off cluster_size=65536
- setup xml snippet for new disk (/tmp/sdb.xml)
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/f17_sdb.img'/>
<target dev='sdb' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
BTW: any easier method right now? Any planning for virt-manager aware
of virtio_scsi?
- attach the disk to the running domain
# virsh attach-device f17 /tmp/sdb.xml
Device attached successfully
In guest
- rescan
# echo "- - -" > /sys/class/scsi_host/host2/scan
- verify in dmesg
[ 2540.390420] scsi 2:0:0:1: Direct-Access QEMU QEMU HARDDISK
1.0 PQ: 0 ANSI: 5
[ 2540.391195] sd 2:0:0:1: [sdb] 8388608 512-byte logical blocks:
(4.29 GB/4.00 GiB)
[ 2540.391558] sd 2:0:0:1: [sdb] Write Protect is off
[ 2540.391570] sd 2:0:0:1: [sdb] Mode Sense: 63 00 00 08
[ 2540.391787] sd 2:0:0:1: [sdb] Write cache: disabled, read cache:
enabled, doesn't support DPO or FUA
[ 2540.393869] sd 2:0:0:1: Attached scsi generic sg2 type 0
[ 2540.395822] sdb: unknown partition table
[ 2540.396833] sd 2:0:0:1: [sdb] Attached SCSI disk
- create PV
# pvcreate /dev/sdb
# vgextend vg_f17 /dev/sdb
- vg, lv and fs layout
# vgs
VG #PV #LV #SN Attr VSize VFree
vg_f17 2 2 0 wz--n- 12.47g 3.97g
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv_root vg_f17 -wi-ao-- 8.00g
lv_swap vg_f17 -wi-ao-- 512.00m
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_f17-lv_root 8.0G 4.6G 3.0G 61% /
- extend lv
# lvextend -l +100%FREE /dev/vg_f17/lv_root
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv_root vg_f17 -wi-ao-- 11.97g
lv_swap vg_f17 -wi-ao-- 512.00m
- resize fs
# resize2fs /dev/vg_f17/lv_root
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/vg_f17/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg_f17/lv_root is now 3137536 blocks long.
- layout of fs is now 4Gb more than before
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_f17-lv_root 12G 4.7G 6.8G 41% /
In host while domain running
- resize the disk to 5Gb
# virsh blockresize f17 /var/lib/libvirt/images/f17_sdb.img 5G
Block device '/var/lib/libvirt/images/f17_sdb.img' is resized
In guest
- rescan
# echo 1 > /sys/block/sdb/device/rescan
In dmesg
[ 3248.889379] sd 2:0:0:1: [sdb] 10485760 512-byte logical blocks:
(5.36 GB/5.00 GiB)
[ 3248.889691] sdb: detected capacity change from 4294967296 to 5368709120
- resize PV
# pvresize /dev/sdb
Physical volume "/dev/sdb" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
- Layout for pv and vg
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_f17 lvm2 a-- 8.50g 0
/dev/sdb vg_f17 lvm2 a-- 4.97g 1.00g
# vgs
VG #PV #LV #SN Attr VSize VFree
vg_f17 2 2 0 wz--n- 13.47g 1.00g
- extend root lv
# lvextend -l +100%FREE /dev/vg_f17/lv_root
Extending logical volume lv_root to 12.97 GiB
Logical volume lv_root successfully resized
-resize filesystem
# resize2fs /dev/vg_f17/lv_root
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/vg_f17/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg_f17/lv_root is now 3399680 blocks long.
- show / filesystem now of 13Gb
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_f17-lv_root 13G 4.7G 7.7G 38% /
I successfully added another disk, but placed on another controller
and not as the third disk of the same controller,
Is there any preference to use more disks on the same controller or
creating different controllers, from a qemu/kvm performance point of
view and virtio_scsi?
My steps were
- be sure pci hot plug is enabled in guest (added in /etc/rc.local)
# modprobe shpchp
- add the controller and the disk in one step doesn't work. I got
error: Failed to attach device from /tmp/sdc.xml
error: (device_definition):2: Extra content at the end of the document
<disk type='file' device='disk'>
^
So I create a controller.xml
<controller type='scsi' index='1' model='virtio-scsi'/>
and add it
virsh attach-device f17 /tmp/controller.xml
and then a sdc.xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/f17_sdc.img'/>
<target dev='sdc' bus='scsi'/>
<address type='drive' controller='1' bus='0' target='0' unit='0'/>
</disk>
and add it
virsh attach-device f17 /tmp/sdc.xml
in dmesg of guest when adding the controller
...
[ 4614.355511] scsi3 : Virtio SCSI HBA
In lspci now:
00:06.0 SCSI storage controller: Red Hat, Inc Device 1004
...
00:08.0 SCSI storage controller: Red Hat, Inc Device 1004
- rescan of bus in guest
# echo "- - -" > /sys/class/scsi_host/host3/scan
[ 4751.298514] scsi 3:0:0:0: Direct-Access QEMU QEMU HARDDISK
1.0 PQ: 0 ANSI: 5
[ 4751.299921] sd 3:0:0:0: [sdc] 2097152 512-byte logical blocks:
(1.07 GB/1.00 GiB)
[ 4751.300290] sd 3:0:0:0: [sdc] Write Protect is off
[ 4751.300298] sd 3:0:0:0: [sdc] Mode Sense: 63 00 00 08
[ 4751.300411] sd 3:0:0:0: [sdc] Write cache: disabled, read cache:
enabled, doesn't support DPO or FUA
[ 4751.301304] sd 3:0:0:0: Attached scsi generic sg3 type 0
[ 4751.303264] sdc: unknown partition table
[ 4751.303930] sd 3:0:0:0: [sdc] Attached SCSI disk
And I'm able to work
Well done! And thanks for your suggestions
More information about the virt
mailing list