Libvirt Ubuntu VM: files created on guest in shared folder given root-only access on host












0














I have created a Ubuntu VM on a server running Ubuntu Server 16.04.5 LTS using the following command:



sudo virt-install 
--name TEST
--memory 2048
--vcpus 2
--location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/'
--os-variant ubuntu16.04
--disk path=/pools/pool0/images/vm/test,size=150,bus=virtio,sparse=no,format=qcow2
--filesystem type=mount,source=/pools/pool0/volumes/shared,target=shared,mode=mapped
--network network=vms
--graphics none
--virt-type kvm
--hvm
--console pty,target_type=serial
--extra-args 'console=ttyS0,115200n8 serial'


Note that I have created a shared folder, called shared with mapped access in order to allow reading and writing on the guest.



I then start the VM with this command:



virsh start TEST --console


Inside the guest, I have edited /etc/fstab to auto-mount the shared folder with this line, where UID 1000 is my user and GID 1000 is the associated group which contains no other members:



shared    /mnt    9p  trans=virtio,version=9p2000.L,rw,uid=1000,gid=1000    0   0


In the /mnt directory on the guest, running ls -ln gives the following output:



$ ls -ln /mnt
total 42
drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


I get the same output when running ls -ln on the host in the /pools/pool0/volumes/shared directory:



$ ls -ln /pools/pool0/volumes/shared
total 42
drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


In the guest, I can create and modify files and folders as myself, an unprivileged user:



$ mkdir /mnt/Media/test-dir
$ touch /mnt/Media/test-file
$ ls -ln /mnt/Media
total 75
drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
drwxrwxr-x 2 1000 1000 2 Dec 29 20:30 test-dir
-rw-rw-r-- 1 1000 1000 0 Dec 29 20:31 test-file
drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


However, on the host OS, these files and folders have been given root only access:



$ ls -ln /pools/pool0/volumes/shared/Media
total 75
drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
drwx------ 2 0 0 2 Dec 29 20:30 test-dir
-rw------- 1 0 0 0 Dec 29 20:31 test-file
drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


I run automated scripts on my server, and for these to work I need these folders and directories to be created with UID 1000, GID 1000, permissions of rwxrwxr-x (775) for directories, and permissions of rw-rw-r-- (664) for files. I do not want to have to manually run chmod and chown with sudo each time I create a new file / directory.



I need to fix this issue, preferably without having to re-install the VM from scratch.










share|improve this question









New contributor




user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0














    I have created a Ubuntu VM on a server running Ubuntu Server 16.04.5 LTS using the following command:



    sudo virt-install 
    --name TEST
    --memory 2048
    --vcpus 2
    --location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/'
    --os-variant ubuntu16.04
    --disk path=/pools/pool0/images/vm/test,size=150,bus=virtio,sparse=no,format=qcow2
    --filesystem type=mount,source=/pools/pool0/volumes/shared,target=shared,mode=mapped
    --network network=vms
    --graphics none
    --virt-type kvm
    --hvm
    --console pty,target_type=serial
    --extra-args 'console=ttyS0,115200n8 serial'


    Note that I have created a shared folder, called shared with mapped access in order to allow reading and writing on the guest.



    I then start the VM with this command:



    virsh start TEST --console


    Inside the guest, I have edited /etc/fstab to auto-mount the shared folder with this line, where UID 1000 is my user and GID 1000 is the associated group which contains no other members:



    shared    /mnt    9p  trans=virtio,version=9p2000.L,rw,uid=1000,gid=1000    0   0


    In the /mnt directory on the guest, running ls -ln gives the following output:



    $ ls -ln /mnt
    total 42
    drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
    drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
    drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
    drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


    I get the same output when running ls -ln on the host in the /pools/pool0/volumes/shared directory:



    $ ls -ln /pools/pool0/volumes/shared
    total 42
    drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
    drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
    drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
    drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


    In the guest, I can create and modify files and folders as myself, an unprivileged user:



    $ mkdir /mnt/Media/test-dir
    $ touch /mnt/Media/test-file
    $ ls -ln /mnt/Media
    total 75
    drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
    drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
    drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
    drwxrwxr-x 2 1000 1000 2 Dec 29 20:30 test-dir
    -rw-rw-r-- 1 1000 1000 0 Dec 29 20:31 test-file
    drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


    However, on the host OS, these files and folders have been given root only access:



    $ ls -ln /pools/pool0/volumes/shared/Media
    total 75
    drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
    drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
    drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
    drwx------ 2 0 0 2 Dec 29 20:30 test-dir
    -rw------- 1 0 0 0 Dec 29 20:31 test-file
    drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


    I run automated scripts on my server, and for these to work I need these folders and directories to be created with UID 1000, GID 1000, permissions of rwxrwxr-x (775) for directories, and permissions of rw-rw-r-- (664) for files. I do not want to have to manually run chmod and chown with sudo each time I create a new file / directory.



    I need to fix this issue, preferably without having to re-install the VM from scratch.










    share|improve this question









    New contributor




    user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0







      I have created a Ubuntu VM on a server running Ubuntu Server 16.04.5 LTS using the following command:



      sudo virt-install 
      --name TEST
      --memory 2048
      --vcpus 2
      --location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/'
      --os-variant ubuntu16.04
      --disk path=/pools/pool0/images/vm/test,size=150,bus=virtio,sparse=no,format=qcow2
      --filesystem type=mount,source=/pools/pool0/volumes/shared,target=shared,mode=mapped
      --network network=vms
      --graphics none
      --virt-type kvm
      --hvm
      --console pty,target_type=serial
      --extra-args 'console=ttyS0,115200n8 serial'


      Note that I have created a shared folder, called shared with mapped access in order to allow reading and writing on the guest.



      I then start the VM with this command:



      virsh start TEST --console


      Inside the guest, I have edited /etc/fstab to auto-mount the shared folder with this line, where UID 1000 is my user and GID 1000 is the associated group which contains no other members:



      shared    /mnt    9p  trans=virtio,version=9p2000.L,rw,uid=1000,gid=1000    0   0


      In the /mnt directory on the guest, running ls -ln gives the following output:



      $ ls -ln /mnt
      total 42
      drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
      drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
      drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
      drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


      I get the same output when running ls -ln on the host in the /pools/pool0/volumes/shared directory:



      $ ls -ln /pools/pool0/volumes/shared
      total 42
      drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
      drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
      drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
      drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


      In the guest, I can create and modify files and folders as myself, an unprivileged user:



      $ mkdir /mnt/Media/test-dir
      $ touch /mnt/Media/test-file
      $ ls -ln /mnt/Media
      total 75
      drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
      drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
      drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
      drwxrwxr-x 2 1000 1000 2 Dec 29 20:30 test-dir
      -rw-rw-r-- 1 1000 1000 0 Dec 29 20:31 test-file
      drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


      However, on the host OS, these files and folders have been given root only access:



      $ ls -ln /pools/pool0/volumes/shared/Media
      total 75
      drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
      drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
      drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
      drwx------ 2 0 0 2 Dec 29 20:30 test-dir
      -rw------- 1 0 0 0 Dec 29 20:31 test-file
      drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


      I run automated scripts on my server, and for these to work I need these folders and directories to be created with UID 1000, GID 1000, permissions of rwxrwxr-x (775) for directories, and permissions of rw-rw-r-- (664) for files. I do not want to have to manually run chmod and chown with sudo each time I create a new file / directory.



      I need to fix this issue, preferably without having to re-install the VM from scratch.










      share|improve this question









      New contributor




      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have created a Ubuntu VM on a server running Ubuntu Server 16.04.5 LTS using the following command:



      sudo virt-install 
      --name TEST
      --memory 2048
      --vcpus 2
      --location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/'
      --os-variant ubuntu16.04
      --disk path=/pools/pool0/images/vm/test,size=150,bus=virtio,sparse=no,format=qcow2
      --filesystem type=mount,source=/pools/pool0/volumes/shared,target=shared,mode=mapped
      --network network=vms
      --graphics none
      --virt-type kvm
      --hvm
      --console pty,target_type=serial
      --extra-args 'console=ttyS0,115200n8 serial'


      Note that I have created a shared folder, called shared with mapped access in order to allow reading and writing on the guest.



      I then start the VM with this command:



      virsh start TEST --console


      Inside the guest, I have edited /etc/fstab to auto-mount the shared folder with this line, where UID 1000 is my user and GID 1000 is the associated group which contains no other members:



      shared    /mnt    9p  trans=virtio,version=9p2000.L,rw,uid=1000,gid=1000    0   0


      In the /mnt directory on the guest, running ls -ln gives the following output:



      $ ls -ln /mnt
      total 42
      drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
      drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
      drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
      drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


      I get the same output when running ls -ln on the host in the /pools/pool0/volumes/shared directory:



      $ ls -ln /pools/pool0/volumes/shared
      total 42
      drwxrwxr-x 8 1000 1000 8 Jul 28 23:52 Backups
      drwxrwxr-x 6 1000 1000 6 Dec 28 00:15 Media
      drwxrwxr-x 6 1000 1000 67 Mar 31 2018 Misc
      drwxrwxr-x 2 1000 1000 4 Mar 31 2018 Recipes


      In the guest, I can create and modify files and folders as myself, an unprivileged user:



      $ mkdir /mnt/Media/test-dir
      $ touch /mnt/Media/test-file
      $ ls -ln /mnt/Media
      total 75
      drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
      drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
      drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
      drwxrwxr-x 2 1000 1000 2 Dec 29 20:30 test-dir
      -rw-rw-r-- 1 1000 1000 0 Dec 29 20:31 test-file
      drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


      However, on the host OS, these files and folders have been given root only access:



      $ ls -ln /pools/pool0/volumes/shared/Media
      total 75
      drwxrwxr-x 199 1000 1000 199 Dec 28 22:07 Movies
      drwxrwxr-x 152 1000 1000 153 Dec 25 16:26 Music
      drwxrwxr-x 75 1000 1000 75 Jul 16 21:02 Photos
      drwx------ 2 0 0 2 Dec 29 20:30 test-dir
      -rw------- 1 0 0 0 Dec 29 20:31 test-file
      drwxrwxr-x 15 1000 1000 15 Dec 18 15:40 TV Shows


      I run automated scripts on my server, and for these to work I need these folders and directories to be created with UID 1000, GID 1000, permissions of rwxrwxr-x (775) for directories, and permissions of rw-rw-r-- (664) for files. I do not want to have to manually run chmod and chown with sudo each time I create a new file / directory.



      I need to fix this issue, preferably without having to re-install the VM from scratch.







      kvm shared-folders libvirt virsh






      share|improve this question









      New contributor




      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Dec 29 '18 at 23:37









      Rui F Ribeiro

      39.1k1479130




      39.1k1479130






      New contributor




      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Dec 29 '18 at 20:53









      user3470185

      43




      43




      New contributor




      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          For anyone curious, I did not find a solution to the issue. However, I managed to avoid the issue by hosting a samba share on the host (using the dperson/samba docker container) and then on the guest, I installed cifs-utils and then added this line to etcfstab:



          //192.168.1.7/Shared  /media/shared  cifs  guest,uid=1000,iocharset=utf8,vers=3.0 0 0


          Where 192.168.1.7 is the IP address of the host, Shared is the name of the Samba share, and /media/shared is where I mounted the share in the guest.






          share|improve this answer








          New contributor




          user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            user3470185 is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491513%2flibvirt-ubuntu-vm-files-created-on-guest-in-shared-folder-given-root-only-acces%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            For anyone curious, I did not find a solution to the issue. However, I managed to avoid the issue by hosting a samba share on the host (using the dperson/samba docker container) and then on the guest, I installed cifs-utils and then added this line to etcfstab:



            //192.168.1.7/Shared  /media/shared  cifs  guest,uid=1000,iocharset=utf8,vers=3.0 0 0


            Where 192.168.1.7 is the IP address of the host, Shared is the name of the Samba share, and /media/shared is where I mounted the share in the guest.






            share|improve this answer








            New contributor




            user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.























              0














              For anyone curious, I did not find a solution to the issue. However, I managed to avoid the issue by hosting a samba share on the host (using the dperson/samba docker container) and then on the guest, I installed cifs-utils and then added this line to etcfstab:



              //192.168.1.7/Shared  /media/shared  cifs  guest,uid=1000,iocharset=utf8,vers=3.0 0 0


              Where 192.168.1.7 is the IP address of the host, Shared is the name of the Samba share, and /media/shared is where I mounted the share in the guest.






              share|improve this answer








              New contributor




              user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                0












                0








                0






                For anyone curious, I did not find a solution to the issue. However, I managed to avoid the issue by hosting a samba share on the host (using the dperson/samba docker container) and then on the guest, I installed cifs-utils and then added this line to etcfstab:



                //192.168.1.7/Shared  /media/shared  cifs  guest,uid=1000,iocharset=utf8,vers=3.0 0 0


                Where 192.168.1.7 is the IP address of the host, Shared is the name of the Samba share, and /media/shared is where I mounted the share in the guest.






                share|improve this answer








                New contributor




                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                For anyone curious, I did not find a solution to the issue. However, I managed to avoid the issue by hosting a samba share on the host (using the dperson/samba docker container) and then on the guest, I installed cifs-utils and then added this line to etcfstab:



                //192.168.1.7/Shared  /media/shared  cifs  guest,uid=1000,iocharset=utf8,vers=3.0 0 0


                Where 192.168.1.7 is the IP address of the host, Shared is the name of the Samba share, and /media/shared is where I mounted the share in the guest.







                share|improve this answer








                New contributor




                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered yesterday









                user3470185

                43




                43




                New contributor




                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                user3470185 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                    user3470185 is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    user3470185 is a new contributor. Be nice, and check out our Code of Conduct.













                    user3470185 is a new contributor. Be nice, and check out our Code of Conduct.












                    user3470185 is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491513%2flibvirt-ubuntu-vm-files-created-on-guest-in-shared-folder-given-root-only-acces%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                    is 'sed' thread safe

                    How to make a Squid Proxy server?