9P Sharing files between host and guest


Recommended Posts

Just thought I'd see if anyone else has tried this.  It's similar to sharing in dockers. In my xml file under devices I put a line like this

    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/mnt'/>
      <target dir='shares'/>
    </filesystem>

and then within the vm in fstab

shares   /mnt    9p  trans=virtio,version=9p2000.L,noauto,nobootwait,rw    0   0

I noauto because sometimes it errors out at vm startup.  So I just put "mount /mnt" in /etc/rc.local  I run this in an apps vm and I had to modify rc.local to start before the apps so unraid user shares are mounted before any apps. Been working well for a couple weeks with everything located in /mnt on unraid available in my apps vm under the same /mnt. No network problems, rocket rides or cifs mounting needed like in xen.

Link to comment

Yes , I am using it  for a long time! And this is very cool way to pass trough file system :-) and for me KVM is the preferred and is stable.

Why didn't you tell us? :) For me kvm hasn't been as stable.  I think it has to do with my motherboard/cpu. In Xen it was very stable as long as I didn't pin cores in sysconfig and xenvm.cfg.  If I did it would eventually freeze the system.  I've had kvm freeze in a similar way. Nothing in the console just frozen. Had to hard reboot. So far I've been up for several days no cachedirs and 2 vms with 2 cores and 2 GB.

Link to comment

Yes , I am using it  for a long time! And this is very cool way to pass trough file system :-) and for me KVM is the preferred and is stable.

Why didn't you tell us? :) For me kvm hasn't been as stable.  I think it has to do with my motherboard/cpu. In Xen it was very stable as long as I didn't pin cores in sysconfig and xenvm.cfg.  If I did it would eventually freeze the system.  I've had kvm freeze in a similar way. Nothing in the console just frozen. Had to hard reboot. So far I've been up for several days no cachedirs and 2 vms with 2 cores and 2 GB.

Some info earlier about p9 file system... I'm using this appliance for my VM:s

http://lime-technology.com/forum/index.php?topic=31623.msg311001#msg311001

Link to comment

Yes , I am using it  for a long time! And this is very cool way to pass trough file system :-) and for me KVM is the preferred and is stable.

Why didn't you tell us? :) For me kvm hasn't been as stable.  I think it has to do with my motherboard/cpu. In Xen it was very stable as long as I didn't pin cores in sysconfig and xenvm.cfg.  If I did it would eventually freeze the system.  I've had kvm freeze in a similar way. Nothing in the console just frozen. Had to hard reboot. So far I've been up for several days no cachedirs and 2 vms with 2 cores and 2 GB.

Some info earlier about p9 file system... I'm using this appliance for my VM:s

http://lime-technology.com/forum/index.php?topic=31623.msg311001#msg311001

I see you tried to tell me 2 months ago but I wasn't listening since I never liked arch I never read that thread.  :)

Link to comment

So instead of adding the following to the VM and editing fstab as shown below. You are sharing files directly from the .xml? Is there an advantage to doing it one way vs the other?

 

Edit fstab so we can connect the mounts on boot
sudo nano /etc/fstab

Edit and paste the following
//Tower/Movies /media/Movies cifs noauto,credentials=/home/ubuntuUser/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0
//Tower/TV /media/TV cifs noauto,credentials=/home/ubuntuUser/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0

Link to comment

Speed and I think it's more benefit than SMB

 

With editing fstab (like I did above) a few of my apps (sickbeard) loaded before the shares were mounted. To fix this I created a crontab task that delayed the startup of sickbeard for 10 seconds after boot. Does the 9P sharing mount the shares before the apps are loaded in rc.local?

Link to comment

Speed and I think it's more benefit than SMB

 

With editing fstab (like I did above) a few of my apps (sickbeard) loaded before the shares were mounted. To fix this I created a crontab task that delayed the startup of sickbeard for 10 seconds after boot. Does the 9P sharing mount the shares before the apps are loaded in rc.local?

The advantage is not using your virtual network especially for intensive operations like, par, rar, usnet and torrents.

 

I had a problem with sickrage and nzbget.  I renamed the init symlinks in /etc/rc2.d of my apps from 20 to 99 so they start last.  Then changed rc.local from 99 to 98. Check this page it explains the different rc.x runlevels. You'll have to check which level your vm runs or just change them all, rc0.d, rc1.d...rc6.d

http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts

 

By doing this you could also make it so one app starts before the other.

 

Link to comment

My current /etc/fstab is as follows:

 

//pithos.private/media/MOVIES\040-\040HD /home/archedraft/media/movies cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0
//pithos.private/media/TV\040SERIES /home/archedraft/media/tv cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0
//pithos.private/downloads /home/archedraft/media/downloads cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0

 

1. I am assuming if I wanted to add this to my .xml it should read like this below?

 

    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/media/MOVIES\040-\040HD'/>
      <target dir='/home/archedraft/media/movies'/>
    </filesystem>

 

2. /etc/fstab should read is as follows:

 

shares   /media/MOVIES\040-\040HD    9p  trans=virtio,version=9p2000.L,noauto,nobootwait,rw    0   0

 

3. Do I need to make 3 separate filesystem codes in my .xml for each share or can you add multiple shares to one filesystem code?

 

<filesystem type='mount' accessmode='passthrough'>

      <source dir='/mnt'/>

      <target dir='shares'/>

    </filesystem>

 

4. I am assuming I do not need to install a 9P program in my ubuntu server?

5. Due to the shares being passthrough, I should not have to have a .smbcredentials file correct?

  • Like 1
Link to comment

My current /etc/fstab is as follows:

 

//pithos.private/media/MOVIES\040-\040HD /home/archedraft/media/movies cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0
//pithos.private/media/TV\040SERIES /home/archedraft/media/tv cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0
//pithos.private/downloads /home/archedraft/media/downloads cifs noauto,credentials=/home/archedraft/.smbcredentials,noperm,noserverino,uid=nobody,gid=users 0 0

 

1. I am assuming if I wanted to add this to my .xml it should read like this below?

 

    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/media/MOVIES\040-\040HD'/>
      <target dir='/home/archedraft/media/movies'/>
    </filesystem>

 

2. /etc/fstab should read is as follows:

 

shares   /media/MOVIES\040-\040HD    9p  trans=virtio,version=9p2000.L,noauto,nobootwait,rw    0   0

 

3. Do I need to make 3 separate filesystem codes in my .xml for each share or can you add multiple shares to one filesystem code?

 

<filesystem type='mount' accessmode='passthrough'>

      <source dir='/mnt'/>

      <target dir='shares'/>

    </filesystem>

 

4. I am assuming I do not need to install a 9P program in my ubuntu server?

5. Due to the shares being passthrough, I should not have to have a .smbcredentials file correct?

 

For target dir, that's the share name you add first in the fstab, give it name like cache,user......source dir is the file system you like to pass trough.

 

And you give one for each pass trough , like you have above.

 

To get this to work, the VM kernel needs this 9p modules, Ubuntu I think is OK.

 

Number 1 and 2 I think is wrong, look here...

http://lime-technology.com/forum/index.php?topic=31623.msg311001#msg311001

 

Link to comment

Example.....

 

Below folders are created in my VM

 

  /mnt/cache

  /mnt/user

 

 

My VM fstab

cache  /mnt/cache      9p      trans=virtio,version=9p2000.L,rw        0 0

user    /mnt/user      9p      trans=virtio,version=9p2000.L,rw        0 0

 

 

Part of My XML file

 

<filesystem type='mount' accessmode='passthrough'>   

  <source dir='/mnt/cache/'/>                       

  <target dir='cache'/>                                                   

</filesystem>                                       

                                                     

<filesystem type='mount' accessmode='passthrough'>   

  <source dir='/mnt/user/'/>                         

  <target dir='user'/>                                                         

</filesystem>                                       

  • Like 1
Link to comment

Yes, like this

 

<filesystem type='mount' accessmode='passthrough'>     
   <source dir='/mnt/media/'/>                          
   <target dir='anynameyouliketouse'/>                                                           
</filesystem>                

 

in VM

 

mkdir /mnt/folderyouhavecreated     

 

fstab

anynameyouliketouse /mnt/folderyouhavecreated      9p      trans=virtio,version=9p2000.L,rw        0 0

 

:-)

//Peter

Link to comment

I got the following error when I tried.

 

qemu-system-x86_64: -device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=media,bus=pci.2,addr=0x1: Device initialization failed.
qemu-system-x86_64: -device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=media,bus=pci.2,addr=0x1: Device 'virtio-9p-pci' could not be initialized

 

That is what I added to my .xml file

    
    <filesystem type='mount' accessmode='passthrough'>
          <source dir='/mnt/media'/>
          <target dir='media'/>
    </filesystem>

 

Do I need to add the following to syslinux.cfg before passthrough will work?

label KVM unRAID OS
  menu default
  kernel /bzimage
  append intel_iommu=on quiet vfio_iommu_type1.allow_unsafe_interrupts=1 initrd=/bzroot acpi_sleep=s3_bios

Link to comment

Something that may be of interest too. Because I moved from xen vm to dockers to kvm vm I just left my paths from docker intact in each app. Then in the vm I mount /mnt from unraid to /mnt in vm. Then I symlinked say /mnt/user/movies to a symlink /movies same with/mnt/cache/downloads to /downloads etc. I put all my configs in /opt/appdata and created a symlink /configs

Link to comment

So here is a quick write up for anyone who needs a little more guidance (like myself  :P):

 

1. First edit your .xml file (source dir = unraid mount) (traget dir = label)

 

    <filesystem type='mount' accessmode='passthrough'>
          <source dir='/mnt/user/MEDIA/MOVIES - HD'/>
          <target dir='movies'/>
    </filesystem>
    
    <filesystem type='mount' accessmode='passthrough'>
              <source dir='/mnt/user/MEDIA/TV SERIES'/>
              <target dir='tv'/>
    </filesystem>
    
    <filesystem type='mount' accessmode='passthrough'>
              <source dir='/mnt/user/downloads'/>
              <target dir='downloads'/>
    </filesystem>
    

 

2. Then startup the VM

 

3. edit fstab

sudo nano /etc/fstab

movies	/home/archedraft/media/movies    9p  trans=virtio,version=9p2000.L,_netdev,rw   0 0
tv	/home/archedraft/media/tv	  9p trans=virtio,version=9p2000.L,_netdev,rw   0 0
downloads	/home/archedraft/media/downloads    9p  trans=virtio,version=9p2000.L,_netdev,rw   0 0

 

4. Create the mount directories in your VM

Sudo mkdir /home/archedraft/media/movies

 

 

5. edit nano [EDIT: You don't need to do this step unless you use this in fstab "trans=virtio,version=9p2000.L,noauto,nobootwait,rw"]

sudo nano /etc/rc.local

mount /home/archedraft/media/movies
mount /home/archedraft/media/tv
mount /home/archedraft/media/downloads

 

6. reboot

Link to comment

Hi archedraft,

Any  reason to use the  /etc/rc.local ?

 

If you skip that, and  do

mount -a

after you have edit the fstab and created the mount directories in your VM, what do you see? are the share mounted ? thats the way I used it. no extra mount command in other files.

 

//Peter

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.