如何在 Debian 中启动时从 VirtualBox 挂载共享文件夹

如何在 Debian 中启动时从 VirtualBox 挂载共享文件夹

我知道关于这个问题已经有很多问题,但是人们提出的所有解决方案都不适合我。我个人采取了这种/etc/fstab方法。这就是文件内容的样子

david@debian:~$ sudo cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=e5de59a3-0619-47f9-9a08-858e1e4f6415 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=b9140523-9685-48c4-a870-3604a8f58788 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
GitHub-VM       /home/david/Documents   vboxsf  uid=david,gid=david,dmode=774,fmode=664     0   0

在哪里:

  • GitHub-VM:是我从主机系统 (macOS) 共享的文件夹
  • /home/david/Documents:是虚拟机上的文件夹(Debian 8)

当然我没有忘记强制vboxsf在启动时加载内核模块。

david@debian:~$ sudo cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
vboxsf

遗憾的是,登录后,我的文档文件夹未映射到主机文件夹:(。我缺少什么?

答案1

挂载必须在vboxadd-service.service启动后进行。 Systemd v220 有特殊的fstab选项为此,但除非您使用向后移植,否则对于 jessie 版本,您必须创建一个自定义安装单元。将以下内容放入/etc/systemd/system/home-david-Documents.mount

[Unit]
Requires=vboxadd-service.service
After=vboxadd-service.service

[Mount]
What=GitHub-VM
Where=/home/david/Documents
Type=vboxsf

[Install]
WantedBy = multi-user.target

从 中删除相应的行fstabsystemctl enable home-david-Documents.mount然后重新启动。

检查您的启动日志,systemctl status home-david-Documents.mount看看它是否不起作用。

答案2

/etc/fstab 中的另一种方法GitHub-VM /home/david/Documents vboxsf x-systemd.automount,uid=1000,gid=1000,dmode=774,fmode=664

update-initramfs -u -k all重启

抱歉纠正错误的机器。

相关内容