View previous topic :: View next topic |
Author |
Message |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Tue Dec 19, 2023 9:29 pm Post subject: [SOLVED] qemu - passthrough internal dvd drive (virtio scsi) |
|
|
Hi,
With libvirtd / virt-manager one can achieve it like this with xml editing :
1. Adding a scsi controller :
Code: | <controller type='scsi' index='0' model='virtio-scsi'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
</controller>
|
2. Adding a hostdev device :
Code: | <hostdev mode='subsystem' type='scsi' managed='no'>
<source>
<adapter name='scsi_host2'/>
<address bus='0' target='0' unit='0'/>
</source>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</hostdev> |
Where 'scsi_host2' has the number changed to the the first digit of internal dvd drive from the lsscsi output.
This works great and allows full passthrough, no more strange error (buffer I/O etc..)
What's the correct command line switch to achieve the same thing with qemu ?
Thanks!
Last edited by sdauth on Wed Dec 20, 2023 12:24 am; edited 3 times in total |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Tue Dec 19, 2023 9:57 pm Post subject: |
|
|
for my win7 vm (snippet)
Code: | -device virtio-scsi-pci,id=scsi0 \
-drive file=/w/virtual/W7.qcow2,if=none,id=ssd1,format=qcow2,aio=native,cache=none \
-device scsi-hd,drive=ssd1 -no-reboot \ |
for win11 vm
Code: | -device virtio-scsi-pci,id=scsi0 \
-drive file=/w/virtual/W11.img,if=none,id=ssd1,format=raw,aio=native,cache=none \
-device scsi-hd,drive=ssd1 \ |
But before I created files (from dd'ing the ssd), I was passing through the whole ssd /dev/sda or whatever
I've found no need for controller/bus/target/unit, I just accept the default. _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Tue Dec 19, 2023 10:19 pm Post subject: |
|
|
Anon-E-moose, it's for a dvd drive passthrough, not hdd.
Anyway, I tried the following :
Code: | -device virtio-scsi-pci,id=scsi0 \
-drive file=/dev/sr0,if=none,id=drive-disk,format=raw,cache=none,media=cdrom,readonly=on \
-device scsi-cd,bus=scsi0.0,drive=drive-disk,id=cdrom \ |
the drive appears as "QEMU QEMU CD-ROM SCSI CdRom Device" in the win10 vm.
I tried to insert a disk and here what happens in dmesg :
Code: | [12608.619795] sr 1:0:0:0: [sr0] tag#2 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
[12608.619806] sr 1:0:0:0: [sr0] tag#2 Sense Key : Not Ready [deferred]
[12608.619811] sr 1:0:0:0: [sr0] tag#2 Add. Sense: Medium not present - tray closed
[12608.619816] sr 1:0:0:0: [sr0] tag#2 CDB: Read(10) 28 00 00 00 00 00 00 00 02 00
[12608.619819] I/O error, dev sr0, sector 0 op 0x0:(READ) flags 0x800 phys_seg 2 prio class 2
[12711.480410] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.509766] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.540803] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.572801] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.603737] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.634746] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.665720] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.712363] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.744229] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12711.775072] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x800 phys_seg 1 prio class 2
[12965.932251] sr 1:0:0:0: [sr0] tag#13 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
[12965.932262] sr 1:0:0:0: [sr0] tag#13 Sense Key : Not Ready [deferred]
[12965.932267] sr 1:0:0:0: [sr0] tag#13 Add. Sense: Medium not present - tray closed
[12965.932272] sr 1:0:0:0: [sr0] tag#13 CDB: Read(10) 28 00 00 00 00 00 00 00 02 00
[12965.932275] blk_print_req_error: 39 callbacks suppressed |
So the passthrough doesn't look good.
When I use libvirtd & virt-manager, the drive appears as "ASUS DRW-24D1ST 1.0" and produces zero error in dmesg. (buffer I/O etc as shown above) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Tue Dec 19, 2023 10:46 pm Post subject: |
|
|
Code: | -device scsi-cd,bus=scsi0.0,drive=drive-disk,id=cdrom \ |
change to
Code: | -device scsi-block,bus=scsi0.0,drive=drive-disk,id=cdrom \ |
Or just "-cdrom /dev/sr0" and ignore the scsi stuff
Edit to add: https://www.qemu.org/2021/01/19/virtio-blk-scsi-configuration/ _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Tue Dec 19, 2023 10:56 pm Post subject: |
|
|
Code: | qemu-system-x86_64: -device scsi-block,bus=scsi0.0,drive=drive-disk,id=cdrom: cannot get SG_IO version number: No medium found
Is this a SCSI device? |
-cdrom /dev/sr0
works but not full passthrough.
From your link :
Code: | CD-ROMs and in general any application that sends SCSI commands are better served by the virtio-scsi device, which has full SCSI support. SCSI passthrough was removed from the Linux virtio-blk driver in v5.6 in favor of using virtio-scsi. |
And yet, they don't provide a single working example of how to achieve that. ![Surprised :o](images/smiles/icon_surprised.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Tue Dec 19, 2023 11:06 pm Post subject: |
|
|
Code: | qemu-system-x86_64: -device scsi-block,bus=scsi0.0,drive=drive-disk,id=cdrom: cannot get SG_IO version number: No medium found
Is this a SCSI device? |
Leave out the bus=scsi0.0
And the if= might need to be specified, but I don't know what parms are allowable, documentation for qemu options sucks big time.
Edit to add:
Quote: | if=interface
This option defines on which type on interface the drive is connected. Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio, none. |
https://www.mankier.com/1/qemu# _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Tue Dec 19, 2023 11:21 pm Post subject: |
|
|
Like that ?
Code: | -device virtio-scsi-pci,id=scsi0 \
-drive file=/dev/sr0,if=scsi,id=drive-disk,format=raw,cache=none,media=cdrom,readonly=on \
-device scsi-block,drive=drive-disk,id=cdrom \ |
->
Code: | qemu-system-x86_64: -drive file=/dev/sr0,if=scsi,id=drive-disk,format=raw,cache=none,media=cdrom,readonly=on: machine type does not support if=scsi,bus=0,unit=0 |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Tue Dec 19, 2023 11:33 pm Post subject: |
|
|
If you change scsi-block back to scsi-cd leaving everything else alone, what happens? _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Tue Dec 19, 2023 11:49 pm Post subject: |
|
|
Exact same error. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Wed Dec 20, 2023 12:10 am Post subject: |
|
|
Passing through a cdrom is tricky, most of the options expect something like a hd (random access) instead of a block device.
Since it works in libvirt, it should work with cmdline args, the problem is figuring them out.
I'm curious what are you passing through by cd (I usually rip to a file and then pass that) _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Wed Dec 20, 2023 12:17 am Post subject: |
|
|
Found this bug report : https://github.com/virtio-win/kvm-guest-drivers-windows/issues/448
and shamelessly copy pasted the holy grail :
Code: | -device virtio-scsi-pci,id=scsi0,bus=pci.0 \
-drive file=/dev/sg8,if=none,media=cdrom,readonly=on,format=raw,id=drive-hostdev0 \
-device scsi-generic,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-hostdev0,id=hostdev0 \ |
the trick was to use /dev/sg8 instead of /dev/sr0 (it might be different on other setup) and -device scsi-generic.
Now the drive correctly appears as "ASUS DRW-24D1ST 1.0" on the SCSI controller in win10
Thanks for your help Anon-E-moose, otherwise I would have probably given up earlier ![Laughing :lol:](images/smiles/icon_lol.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Anon-E-moose Watchman
![Watchman Watchman](/images/ranks/rank-G-2-watchman.gif)
![](images/avatars/3064969284ad468b81342a.jpg)
Joined: 23 May 2008 Posts: 6144 Location: Dallas area
|
Posted: Wed Dec 20, 2023 12:24 am Post subject: |
|
|
I ran across the scsi-generic bit, and knew that it would have to use the /dev/sg* interface, but I didn't know how it all worked or even whether it would.
Glad it works.
Edit to add: I looked up the difference between sg/sr and it makes sense, /dev/sg* is generic scsi, /dev/sr* is cdrom,
but what you really want to pass through is the sg device and let windows figure out what it is.
It's just that the performance of scsi-generic is lower than that of scsi-hd or other variants. _________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
sdauth l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/8853292075e233da65d745.jpg)
Joined: 19 Sep 2018 Posts: 632 Location: Ásgarðr
|
Posted: Wed Dec 20, 2023 6:58 am Post subject: |
|
|
I ran some tests with Exact Audio Copy and I have an average of 7x read speed, not bad. With wine, it was around 3x.
For DVD and tools like AnyDVD HD, it is fast. Around 5 minutes for a full DVD dump.
The most important being stability during transfer so I'm very satisfied
edit : See also https://www.mail-archive.com/vfio-users@redhat.com/msg03818.html
edit2: For some reason, disk eject sometimes fail from Windows explorer. (and physical eject button doesn't respond)
I can still eject by typing "eject /dev/sr0" from a terminal. A bit ugly but it works. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|