简体   繁体   English

在Ubuntu Server 16.04的fstab中自动挂载VirtualBox共享文件夹

[英]Auto-mount VirtualBox shared folder in fstab on Ubuntu Server 16.04

I have Ubuntu Server 16.04 running in VirtualBox on a Windows 10 host. 我在Windows 10主机上的VirtualBox中运行Ubuntu Server 16.04。 I have VirtualBox guest additions installed and correctly set up shared folders which I am successfully mounting using the "mount" command. 我已经安装了VirtualBox guest虚拟机,并正确设置了共享文件夹,使用“ mount”命令可以成功安装该共享文件夹。 I'd like the shared folder to be mounted on system startup, so I added a record to /etc/fstab like: 我希望在系统启动时挂载共享文件夹,所以我在/ etc / fstab中添加了一条记录,如下所示:

Projects /home/development/projects vboxsf rw,uid=1000,gid=1000 0 0

However, whenever I add a record to fstab the next reboot I get the emergency mode. 但是,每当我将记录添加到fstab时,下次重启时,我都会进入紧急模式。 Please help 请帮忙

As ugly as it is, this post on the Ubuntu site worked for me. 尽管很丑陋,但Ubuntu网站上的这篇帖子对我有用。 It's not the approved answer, but it worked when others didn't. 这不是批准的答案,但是在其他人没有的情况下有效。 The problem seems to be the timing--the vbox shares aren't ready when fstab is running, so instead we mount at user login. 问题似乎是时机问题-运行fstab时vbox共享尚未准备好,因此我们在用户登录时挂载。 I'm sure someone will post a better solution for Ubuntu 16 at some point. 我确定有人会在某个时候发布针对Ubuntu 16的更好的解决方案。

Created share point in host: 在主机中创建共享点:

host$ sudo mkdir -p /path/to/myshare
host$ sudo chown user:user /path/to/myshare

(... added a "myshare" share through VBox UI) (...通过VBox UI添加了“ myshare”共享)

Created mount point in guest: 在来宾中创建挂载点:

guest$ sudo mkdir -p /path/to/myshare
guest$ sudo visudo 

Added passwordless sudo permission to mounting in guest: 添加了无密码sudo权限以在客户机中挂载:

guest$ sudo visudo

... adding to end: ...添加到结尾:

# Allow mounting without password 
# (hack to allow vbox share mounting to be delayed until user login)
ALL ALL=NOPASSWD: /bin/mount

Added mount action to user ".profile": 向用户“ .profile”添加了挂载操作:

guest$ vi ~/.profile

... adding to the end: ...添加到最后:

sudo /bin/mount -t vboxsf -o uid=$UID,gid=$(id -g) myshare /path/to/myshare

Actually, it is not compulsory to edit the fstab file. 实际上,并非必须编辑fstab文件。 Instead, to mount a shared folder using the vboxsf filesystem provided with Guest Additions, we first need to make sure some prerequisites are met as follows: 相反,要使用Guest Additions随附的vboxsf文件系统挂载共享文件夹,我们首先需要确保满足一些先决条件,如下所示:

  • Make sure that Guest Additions is properly installed on the guest OS. 确保在来宾操作系统上正确安装了来宾添加。
  • Users in a guest Ubuntu must be in the group vboxsf to be able to access shares. 来宾Ubuntu中的用户必须位于vboxsf组中才能访问共享。

In recent releases of Virtual Box, we can also automatically mount shared folders on creation (See the image in the answer provided by @the_ousek) 在最新版本的Virtual Box中,我们还可以在创建时自动挂载共享文件夹(请参阅@the_ousek提供的答案中的图像)

After a reboot of the guest this shared folder will be mounted to the guest directory /media//sf_ accessible to all users who had been made member of the group vboxsf. 来宾重新启动后,此共享文件夹将被安装到来宾目录/ media // sf_,该用户目录已成为组vboxsf的所有用户访问。

More details at https://askubuntu.com/questions/252853/how-to-mount-a-virtualbox-shared-folder-at-startup 有关更多详细信息, 访问https://askubuntu.com/questions/252853/how-to-mount-a-virtualbox-shared-folder-at-startup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是什么导致了Linaro Linux中的自动挂载许可 - what causes permission of auto-mount in linaro linux 挂载 Virtualbox 共享文件夹作为来宾操作系统上运行的 Docker 的卷 - Mount a Virtualbox shared folder as a volume for Docker running on the guest OS Vagrant - 如何安装virtualbox共享文件夹? (“vboxsf”不可用) - Vagrant - How can I mount the virtualbox shared folder? (“vboxsf” not available) 登录 Linux Mint 后,如何使用 systemd 自动挂载 veracrypt 设备托管卷? - How to auto-mount veracrypt device-hosted volume with systemd after login on Linux Mint? virtualbox + perl +共享文件夹==失败 - virtualbox + perl + shared folder == fail 如何在VM Virtualbox Ubuntu 16.04中启动时运行Shell脚本 - How to Run Shell Script at start in VM Virtualbox Ubuntu 16.04 Linux:带有附加安装选项的“ fstab”? - Linux: “fstab” with additional mount options? 如何在fstab的外部硬盘驱动器中装载特定文件夹? - How do I mount a specific folder within my external harddrive in fstab? Ubuntu 12.04 fstab损坏 - Ubuntu 12.04 fstab corrupted 在VirtualBox的共享文件夹中构建符号链接共享库 - Building symbolic link shared library in a shared folder of VirtualBox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM