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

  • zelifcam@lemmy.world
    link
    fedilink
    English
    arrow-up
    11
    ·
    edit-2
    2 months 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.

    • wildbus8979@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      2 months ago

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

  • thingsiplay@beehaw.org
    link
    fedilink
    arrow-up
    1
    ·
    2 months 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