1

In linux qemu environment, one host server runs two virtual machines. I want to let two VMs write data into the same block device on host. Thus, I run the following two commands to expose host block device to two VMs.

sudo virsh attach-disk VM1 /dev/myblockdevice vdc
sudo virsh attach-disk VM2 /dev/myblockdevice vdc

Now, two VMs could see the block device and write to it. I was wondering if this approach works well. Since two VMs write data to the same block device simultaneously, I doubt if the block device could store the correct data?

2 Answers2

0

You're correct. To share a block device like this, you have to take some sort of steps to prevent the guest VMs from overwriting each other's blocks. Use independent partitions for each guest, or consume the device with a shared-disk filesystem. See the Wikipedia page on clustered filesystems for more information: https://en.wikipedia.org/wiki/Clustered_file_system

Mike Andrews
  • 3,045
  • 18
  • 28
0

I think, the first process that opens the data for write, can do that.

I use a VM like sand-box just for browsing the Internet. I can mount temporarily its data virtual disk in the host system, but in that moment, the content of it "freezes" and even the VM can still write into it, the host could not see the changes until I umount/mount the VM-data disk again.

schweik
  • 164
  • 7