Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

Mounting a raw disk image used by a VM on the host system

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
tuner23
Tux's lil' helper
Tux's lil' helper
Posts: 82
Joined: Thu May 18, 2006 5:42 pm

Mounting a raw disk image used by a VM on the host system

  • Quote

Post by tuner23 » Wed Dec 25, 2019 9:44 am

hi,


i have a virtual machine running with qemu-kvm, and a secondary disk-image mounted with

Code: Select all

 -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: Select all

/dev/sdb on /storage type ext4 (rw,relatime,seclabel,data=ordered)
Now, when i mount the image read-only on the host system

Code: Select all

/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: Select all

# 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: Select all

# 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.
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56087
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Wed Dec 25, 2019 10:59 am

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.
Top
tuner23
Tux's lil' helper
Tux's lil' helper
Posts: 82
Joined: Thu May 18, 2006 5:42 pm

  • Quote

Post by tuner23 » Thu Dec 26, 2019 12:32 pm

Ok, thanks for the information.

So i will have to use another way instead..
Top
Ionen
Developer
Developer
User avatar
Posts: 3013
Joined: Thu Dec 06, 2018 2:23 pm

  • Quote

Post by Ionen » Thu Dec 26, 2019 12:51 pm

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.
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56087
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Thu Dec 26, 2019 1:22 pm

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.
Top
Post Reply

5 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic