For example file names coloring will stop working, because all archives, sources etc. now looks like executable. I cannot imagine regular computer user scenario when he need to get shared windows file as executable in Linux. Here you can find how to disable this behavior and share files as normal data (not executable files).
The Virtual Box offers two ways how to get the shared folder accessible in the Linux guest OS. Both are dependent on the classical Linux mount mechanism, but are little different.
NOTE: To get the Shared Folder mechanism working, you have to install the Virtual Box Guest Additions, what have to be provided manually. The installation process may be little bit different for diferent Linux distributions (Ubuntu, Fedora, etc) and I recommend using Google to find right way how to install the Virtual Box Guest Additions.
First mount mechanism is fully managed by the Virtual Box Guest Additions, and VM options dialogue. Open the Virtual Box machine settings by click on “Machine->Settings…” in menu. You will obtain the dialogue:
Now you have to select the Shared Folders item in the list of the left side. You will obtain list of all defined shared folders. Then double-click selected folder record and you will obtain final Shared Folder settings:
If you tick the “Auto-mount” option, the Virtual Box will mount your shared folder automatically, but you cannot influence the way how the folder will be mounted. So, this way to mount the shared folder is not for us if we can disable the executable unwanted behavior.
The second way is to mount the shared folder manually, through the command line or during the guest OS boot process by /etc/fstab file. This way gives to us more freedom to influence how the shared folder will be finally mounted.
For our purposes, we will use the second way, of course – then if you are using “Auto-mount” mechanism, disable it first, please.
Now, let’s go to make the shared folder executable-less.
At first we have to know the shared folder name. This piece of information can be obtained from the Virtual Box Shared folders settings. Open these settings as described above through the “Machine->Settings…” menu.
The name of the Shared Folder is first item on the folder record line, or you can open full configuration dialogue by line double-click and then you will get name from Folder Name edit box.
In our case the Shared Folder name is vm_share.
Second prerequisite is to prepare the “mount-point” for our shared folder in the guest OS. It is classical regular folder, which can be placed everywhere on your file system – in your Home folder, in /mnt folder or in same place where the Auto-mount mechanism places the shared folders -> in /media folder.
The Virtual Box uses “mount-point” naming scheme when prepend the “sf_” prefix before the Shared Folder regular name, then name generated by Virtual Box will be sf_vm_share.
But you can select whatever folder name here; it is not restricted by any special way.
Choose the folder name and create it:
|
|
Now you are ready to mount the shared folder and make its content accessible from the Guest OS. Type this command from your terminal:
|
|
Now switch your current working directory (CWD) to the mount-point:
|
|
If everything went OK, you can see now the Shared Folder content with same list of files as from your host OS.
But when you use the simple command from above, all your files are green add have executable flag:
|
|
Additionally all users can read, write or execute the files in the folder.
Then default mounting policy is not enough for us. Unmount the folder by command:
|
|
where vm_share is name of your Shared Folder and follow next steps to get expected result.
The default Virtual Box mounting mechanism restricts the folder access only to members of the vboxsf group members. I think, that is good idea then we will restrict the folder access by same way. If you do not want to do this, skip next section.
We have to detect if the vboxsf group already exists or not. To do this, type this command:
|
|
If you get this result:
|
|
Then group already exists and has GID == 1001 -> this GID will be used later.
If you will not get any grep result, then you have to create the group itself:
|
|
Verify that group has been created successfully:
|
|
must show:
|
|
Ok, now we have to add your user to the group, to grant correct access to him:
|
|
the user_name replace by real user name on your OS.
Now verify finally, that group exists and user is member of the group:
|
|
You have to see this result:
|
|
where 1001 is Group ID (GID) and the user_name at the line end means that user is member of the group.
Now we are ready to restrict the Shared Folder access to the vboxsf group members, and modify the rights to disable the unwanted executable flag mapping. But we have add some parameters to the mount command to reach our goal.
The Virtual Box provides folder sharing by special file system with vboxsf name. This file system offers several mount options, which you can obtain by this command:
|
|
For our purposes, we have to use the fmode option, which allow modifying and overriding all file permissions, and additionally we will use general mount parameters umask, gid and uid to set appropriate access rigths to the shared folder.
Detailed help to mentioned mount common commands can be obtained on the mount man page then I can say here briefly that uid defines the OWNER user ID for the mount-point of the Shared Folder and gid makes same for the GROUP.
The umask then specifies rights to the mount-point for its owner and group, but here is used binary negation of the classic file rigths. Then, if the full access for everybody to a file is 777 in classic rights representation, we have to define umask 000 to get same result – 7 dec is 111 in binary, and negation is 000.
More important is the vboxsf file system specific parameter fmode. It overrides (in classical way) rights to all files in the Share Folder and all subfolders. Then to reach read/write rights without executable flag, we have to specify the fmode to 660.
Now, try to mount the Shared Folder with final set of parameters:
|
|
If you now dump the folder content, you will get different result:
|
|
As you can see, the files are accessible only to root (owner) and group vboxsf, and both entities have only read/write (not executable) rights to files. It has been our starting requirement on the Shared Folder.
Finally, we can make mounting of our Share Folder permanent and automatic during the guest boot process. To do that, we have to modify the /etc/fstab file content by adding this line:
|
|
Now, after reboot, your Shared Folder will be automatically mounted to the /media/sf_vm_share location.
If you can have the Shared Folder accessible more comfortable from your home folder too, you can create symbolic link to the folder:
|
|
That’s all. Enjoy your properly mounted Shared Folder in the Virtual Box.
Note: This article was originally published on my previous site polach.cc. Because I had to change the domain I have moved the article here from the previous site.