1

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.

2 Answers 2

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 \etc\fstab:

//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.

0

You need to use mode=passthrough instead of mode=mapped. This is nicely explained here: https://rabexc.org/posts/p9-setup-in-libvirt.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .