Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Mounting a raw disk image used by a VM on the host system
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
tuner23
Tux's lil' helper
Tux's lil' helper


Joined: 18 May 2006
Posts: 82

PostPosted: Wed Dec 25, 2019 9:44 am    Post subject: Mounting a raw disk image used by a VM on the host system Reply with quote

hi,


i have a virtual machine running with qemu-kvm, and a secondary disk-image mounted with
Code:
 -drive file=/data/vms/kube/kube-storage.img,format=raw,if=none,id=drive-ide0-1-1


On the VM the image is mounted under /storage/
Code:
/dev/sdb on /storage type ext4 (rw,relatime,seclabel,data=ordered)


Now, when i mount the image read-only on the host system
Code:
/data/vms/kube/kube-storage.img on /mnt/tmp type ext4 (ro,nosuid,nodev,noexec,relatime)

it works, but does not syncronize the changes made on the virtual machine.

E.g. when i do on the VM
Code:
# touch /storage/test
# ll /storage/test
-rw-r--r--. 1 root root 0 21. Dez 15:10 /storage/test


I can see the changes only when i unmount and mount the image again:
Code:
# ll /mnt/tmp/
drwxr-xr-x 4 root root 4.0K Dec 25 10:32 .
drwxr-xr-x 7 root root 4.0K Jan 22  2018 ..
drwxr-xr-x 3 root root 4.0K Dec 21 14:54 data

# umount /mnt/tmp

# mount -o loop /data/vms/kube/kube-storage.img /mnt/tmp
# mount -o remount,ro /mnt/tmp/

# ll /mnt/tmp/
drwxr-xr-x 4 root root 4.0K Dec 25 10:33 .
drwxr-xr-x 7 root root 4.0K Jan 22  2018 ..
drwxr-xr-x 3 root root 4.0K Dec 21 14:54 data
-rw-r--r-- 1 root root    0 Dec 25 10:33 test


The other thing is, that i can't mount the image read-only directly, but have to use remount..

Can someone explain me what happens here, and maybe also which options to use, to make it
work..


Thanks,
Tony.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44921
Location: 56N 3W

PostPosted: Wed Dec 25, 2019 10:59 am    Post subject: Reply with quote

tuner23,

You must not mount the same filesystem multiple times at the same time.

Each mount causes information to be cached. As each mount is unaware of any others, it assumes that it has exclusive use of the filesystem.
Therefore its cache is always correct.
Even read only second mounts are not safe with journeled filesysems as the second mount will see the filesystem as 'dirty' and replay the journal. So a read only mount actually causes writes.

There is no cache coherency across multiple mounts so you can destroy the filesystem.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
tuner23
Tux's lil' helper
Tux's lil' helper


Joined: 18 May 2006
Posts: 82

PostPosted: Thu Dec 26, 2019 12:32 pm    Post subject: Reply with quote

Ok, thanks for the information.

So i will have to use another way instead..
Back to top
View user's profile Send private message
Ionen
Guru
Guru


Joined: 06 Dec 2018
Posts: 538

PostPosted: Thu Dec 26, 2019 12:51 pm    Post subject: Reply with quote

Being lazy and not caring much for performance, I often just run sshd in the VM and use sshfs like I do with everything else. You could of course use any other kind of network mounts that both the guest and host can use.

If VM isn't granted network access or want better performance, then may want to look into virtfs/9p+virtio that allow to create a safely shared path much like what you're trying to accomplish, but I've never tried it personally. Will need support both in host and guest. Could be other/better solutions but I'm no expert.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44921
Location: 56N 3W

PostPosted: Thu Dec 26, 2019 1:22 pm    Post subject: Reply with quote

tuner23,

Sharing a directory can be made to work. NFS does locking correctly, so it all works safely.
NFS also offers a feature called local locking, you must not use that on read/write NFS mounts as you need the locks on the NFS server to that other users can see them.
Local locking is OK on a read only mount.

Share something over NFS and mount the NFS share anywhere you like, including on the local system.
You must not access the NFS shared area directly from its host as NFS won't know.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
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