How to attach a block device to qemu VM through qemu command line?
Asked Answered
R

1

5

I want to configure the qemu to attach a specific block device to the VM?

Following is the command I am using now:

qemu-system-x86_64 -enable-kvm -machine type=pc,accel=kvm 
                   -cpu host -nographic  -k de -usb -m 2048 
                   -net nic -net user,hostfwd=tcp::3388-:22
                    ubuntu16.04.qcow2

I know that following is the virsh command to do this:

virsh attach-disk ubuntuVM /dev/vdb

But I want to specify this in the above command line (Don't want to use virsh). Does anyone know how to do this?

Kind Regards

Reive answered 3/10, 2017 at 9:51 Comment(0)
E
9

Simply add the following option to your command:

-drive file=/dev/sdd,format=raw,if=virtio

This will add a drive, the file parameter can also point to block devices, be sure to set the format parameter to "raw".

Additionally you can set the if parameter to "virtio" if the guest supports it (via module or driver) for better performance.

Etiology answered 14/2, 2018 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.