Skip to contentSkip to conversation

Using the one disk image file on 2 virtual machines at the same time

Qemu-devel 한만종 2 participants 2 messages Jul 28, 2015

lore
Share & tools
lore

한만종

author
#0 lore raw

Hi,

I'm facing a weird behavior when I used the one disk image file on 2 virtual machines at the same time.

I made the instance of a virtual machine, using the below command.

$ qemu-system-x86_64 -smp 2 -m 1024 -hda 10G.qcow2 -enable-kvm

When the OS(Ubuntu 14.04 64bit) was booted up, I made an another one, using the same command.

$ qemu-system-x86_64 -smp 2 -m 1024 -hda 10G.qcow2 -enable-kvm

Then, I had 2 virtual machines using the same disk image file.

When I made a directory on first virtual machine, using the command like below.

$ mkdir test1

The "test1" directory wasn't showed on another virtual machine. And, I made a directory on second virtual machine, using the command like below.

$ mkdir test2

The "test2" directory wasn't showed on another virtual machine, either.

Then, I shut the all virtual machines down. I tried to mount the disk image file on my host machine.

$ sudo modprobe nbd
$ sudo qemu-nbd -c /dev/nbd0 ./10G.qcow2
$ sudo mount /dev/nbd0p1 /mnt/10G

Then, I checked what the file is showed. The result was that "test2" directory was only showed.

Where is the "test1" directory? This is the weird behavior on my test.

Before my test, I created a disk image file and installed the OS on the disk image, using the commands like below.

$ qemu-img create -f qcow2 -o preallocation=metadata 10G.qcow2 10G
$ qemu-system-x86_64 -smp 2 -m 2048 -hda 10G.qcow2 -cdrom ../iso/ubuntu-1404.2-desktop-x86_64.iso -enable-kvm
#1 lore raw
Quoted 11 lines · 한만종

Hi,

I'm facing a weird behavior when I used the one disk image file on 2 virtual machines at the same time.

I made the instance of a virtual machine, using the below command.

$ qemu-system-x86_64 -smp 2 -m 1024 -hda 10G.qcow2 -enable-kvm

When the OS(Ubuntu 14.04 64bit) was booted up, I made an another one, using the same command.

$ qemu-system-x86_64 -smp 2 -m 1024 -hda 10G.qcow2 -enable-kvm

Then, I had 2 virtual machines using the same disk image file.

Bad idea. You should NEVER have more than one qemu or qemu-img opening an image read-write at the same time (even having multiple read-only qemu-img visitors visiting a file opened read-write by qemu is dangerous). You are very likely to cause fatal corruption to the point that neither guest will be able to see data.

Quoted 8 lines

When I made a directory on first virtual machine, using the command like below.

$ mkdir test1

The "test1" directory wasn't showed on another virtual machine. And, I made a directory on second virtual machine, using the command like below.

$ mkdir test2

The "test2" directory wasn't showed on another virtual machine, either.

And you should NOT expect it to work. qcow2 images are NOT shared file systems. If you want a shared file system, then do something like having both your guests mount common storage via NFS or glusterfs or some other protocol designed to be used as a shared file systems.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org