QEMU Connect physical disk

25,452

Per the documentation: http://wiki.qemu.org/download/qemu-doc.html#host_005fdrives

You should just be able to do

  -hda /dev/sdX

But, since this is Windows, you basically just took your hard drive out of your computer and inserted it into another. So it'll go and have to find new hardware etc. You might seriously mess up your Windows disk in the process. This probably isn't a great idea... I suggest you create a snapshot of the Windows disk and use that instead.

You should also use bus=virtio for those other block devices, much faster.

Share:
25,452

Related videos on Youtube

Bas van Langevelde
Author by

Bas van Langevelde

Updated on September 18, 2022

Comments

  • Bas van Langevelde
    Bas van Langevelde over 1 year

    I made a windows virtual machine on my ubuntu pc using the following script (found online).

    #!/bin/bash
    
    configfile=/etc/vfio-pci1.cfg
    
    vfiobind() {
        dev="$1"
            vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
            device=$(cat /sys/bus/pci/devices/$dev/device)
            if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                    echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
            fi
            echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
    
    }
    
    modprobe vfio-pci
    
    cat $configfile | while read line;do
        echo $line | grep ^# >/dev/null 2>&1 && continue
            vfiobind $line
    done
    
    sudo qemu-system-x86_64 -enable-kvm -M q35 -m 6144 -cpu host \
    -smp 4,sockets=1,cores=4,threads=4 \
    -bios /usr/share/qemu/bios.bin -vga none \
    -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
    -device vfio-pci,host=02:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
    -device vfio-pci,host=02:00.1,bus=root.1,addr=00.1 \
    -device virtio-scsi-pci,id=scs \
    -drive file=/home/bas/windows7.img,id=disk,format=raw -device scsi-hd,bus=virtio.0,drive=disk \
    -drive file=/home/bas/Downloads/Windows7Pro.iso,id=isocd -device ide-cd,bus=virtio.1,drive=isocd \
    -hda /dev/sdd
    -boot menu=on
    
    exit 0
    

    The vfio-pci1.cfg file only contains the pci address for the video card and the usb devices (keyboard and mouse). The script passes one of my videocards through to a virtual machine. I will be running 2 of these vms at the same time so I can play games with a friend on the same computer so dual booting is no option.

    If you start the virtual machine it uses the actual video card for it's display.

    The virtual machine starts and runs fine I just want to add a physical drive to it so I can share a volume that has only games (no system disk) to the virtual machine, but I can't find out how to do this.

    • Panther
      Panther over 9 years
      I did not see the use of virt-manager anywhere in your link. It is a long tutorial with many details, please update your question with the command you ran and any errors you are getting. You should also understand, qemu, without KVM, is going to be very very slow, you are better off dual booting (IMHO)
    • Panther
      Panther over 9 years
      the script in yor link start the vm ;) your question is lacking sufficient details on your problem, what happens when you run the script ?
    • Bas van Langevelde
      Bas van Langevelde over 9 years
      Updated the starting post to be more detailed, if you miss any information just tell me ;)
    • Panther
      Panther over 9 years
      You have multiple disk listed in your start up script and have not told us which one you are having a problem with. You may need to specify a partition /dev/sda1 rather then /dev/sda , I am not certain on this. In general it is far better to use a virtual disk rather then a raw partition. There are may ways to access the data on a virtual disk.
  • Bas van Langevelde
    Bas van Langevelde over 9 years
    I know connecting a windows disk is dangerous. This is just the disk connecting a bunch games.
  • Bas van Langevelde
    Bas van Langevelde over 9 years
    I revised the sript in the main post. If I understood you correctly this should work. I'll test it when I'm back home in a few days. The post above was supposed to say "disk CONTAINING a bunch of games." my bad.
  • ppetraki
    ppetraki over 9 years
    I'm just echoing your concern about hurting the disk. IIRC Win7 gets fussy when the board changes requiring a license check so you'll have to reconcile that each time you switch between VM and metal. You're already creating one VM on a disk image, why not two? You can use an LVM and install to raw storage + virtio at near bare metal speed. If it were me, I would much rather reinstall Win7 on a VM as opposed to metal. But hey, experiment, see what works for you. Virtualization is fun :)
  • Bas van Langevelde
    Bas van Langevelde over 9 years
    for the 2nd time I am in stalling it on a vm I just need to connect a physical drive containing ONLY games.