this post was submitted on 02 Sep 2024
29 points (100.0% liked)

Linux

47237 readers
3343 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I wanna share /mnt so I can download stuff to my hard drives

top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 11 points 2 weeks ago* (last edited 2 weeks ago)

You can use a local folder as storage that’s mounted in the VM. Something like this snippet I pulled.

https://libvirt.org/kbase/virtiofs.html


To create a shared folder in Virt Manager that links to a local folder on your filesystem, follow these steps:

Step 1: Open Virt Manager and Select Your Virtual Machine

  1. Open Virt Manager.
  2. Select the virtual machine you want to add the shared folder to, but do not start it.
  3. Click on the "Open" button to access the virtual machine's settings.

Step 2: Add a New Hardware Device

  1. In the virtual machine's details window, go to the "Add Hardware" button, usually located at the bottom left.
  2. In the "Add Hardware" dialog, select "Filesystem" from the list.

Step 3: Configure the Shared Folder

  1. In the "Filesystem" settings:
    • Mode: Choose virtio for best performance.
    • Driver: Leave this as default (virtiofs).
    • Source Path: Browse to the local folder you want to share with the virtual machine.
    • Target Path: Specify the mount point within the guest (for example, /mnt/shared).
  2. Click "Finish" to add the shared folder.

Step 4: Start the Virtual Machine

  1. After setting up the shared folder, start the virtual machine.

Step 5: Mount the Shared Folder in the Guest OS

  1. Linux Guest:

    • You need to mount the shared folder manually. For example:
      sudo mount -t virtiofs shared_folder /mnt/shared
      
    • Ensure that shared_folder is the name you used for the Target Path.
  2. Windows Guest:

    • Virtiofs support in Windows is not as straightforward as in Linux. If you're using a Linux-based guest, the above should work seamlessly. For Windows, you might need to install additional drivers or use alternative methods like Samba shares.

Step 6: Access the Shared Folder

Once mounted, you can access the shared folder as you would any other directory within your guest OS.

This configuration allows your virtual machine to interact with a folder on your host system, making it easier to share files between the host and guest environments.

[–] [email protected] 7 points 2 weeks ago (1 children)
[–] [email protected] 3 points 2 weeks ago

Thats the best answer. The other option is to use Spice, which will require installing the qemu guest agent on the guest OS.

[–] [email protected] 3 points 2 weeks ago

Not sure, I usually mount a network share that is accessible from both machines.

[–] [email protected] 1 points 2 weeks ago

Sharing a folder in virt-manager was a something. This is for Linux on Linux only. Didn't use a virtual manager for a while now, but I have notes how to do it. I think there are two ways, one with virtiofs and the other way with virtio-9p if the guest doesn't support virtiofs? I honestly forgot the details, so you might need to research a bit again. I'm relatively new to Virt-Manager and Qemu+Kvm, and don't understand every detail. It was a challenge to figure out all of this. My notes:

Host

First create a directory on your host system (the real machine outside of virtual machine). This folder will be shared:

mkdir /home/tuncay/Public/vm_share/
chmod 777 /home/tuncay/Public/vm_share/

In the Virt-Manager for your Linux guest, set following settings first.

either

virtiofs:


    Virt-Manager:
    Add Hardware > Filesystem
        - Driver: virtiofs
        - Source: /home/tuncay/Public/vm_share
        - Target: share

or

virtio-9p:

    Virt-Manager:
    Add Hardware > Filesystem
        - Driver: virtio-9p
        - Source: /home/tuncay/Public/vm_share
        - Target: /share

Then go and start the guest virtual machine. In the guest execute following commands, depending on which previous settings you have. Just create a folder in the virtual machine and mount it with virtiofs. Here this means "share" is the target (we set previously under - Target: /share) and "home/tuncay/Public" is the folder you want to use IN THE guest. The "share" name will then be connected to Virt-Manager, which in previous settings resolves to - Source: /home/tuncay/Public/vm_share on your real machine.

virtiofs:

Either mount the drive every time you start the guest, or you can just mount it in /etc/fstab automatically, like in bottom example.

    Guest:
    mkdir /home/tuncay/Public/
    sudo mount -t virtiofs share /home/tuncay/Public

    ... or Guest /etc/fstab:
    share   /home/tuncay/Public       virtiofs        defaults        0       0

or use virtio-9p, but this one does not work with fstab and the command is slightly more complicated. You can write a script and save it in the guest. Either autorun the script or just when you need it by demand.

virtio-9p:

    Guest:
    mkdir /home/tuncay/Public/
    sudo mount -t 9p -otrans=virtio,rw,version=9p2000.L /share /home/tuncay/Public
[–] [email protected] 1 points 2 weeks ago

When I exchange files between host and guest, I usually just go to the directory I want to share and run python3 -m http.server

[–] [email protected] 1 points 2 weeks ago

I use fedora btw