ファイルを共有する
前回までに仮想マシンを構築してターミナルソフトから接続し操作できることを確認しました。
作業のしやすさを考えると、ホストマシンのエディタでプログラムソースを編集して、Vagrantで構築した仮想マシンで実行する方法が良さそうです。
その場合のファイルの転送はどうしたら良いでしょうか。ファイルを共有できれば転送作業などを行う必要がなくなり便利です。
今回は、ファイル共有の方法を模索したいと思います。
ファイルの共有には、vbguest
というプラグインが必要らしいので、インストールされているか確認します。
> vagrant plugin list ↵ No plugins installed. >
インストールされていないことが確認できました。
早速インストールします。
> vagrant plugin install vagrant-vbguest ↵ Installing the 'vagrant-vbguest' plugin. This can take a few minutes... Fetching: micromachine-3.0.0.gem (100%) Fetching: vagrant-vbguest-0.19.0.gem (100%) Installed the plugin 'vagrant-vbguest (0.19.0)'! >
インストールできたようです。もう一度確認してみましょう。
> vagrant plugin list ↵ vagrant-vbguest (0.19.0, global) >
仮想マシンを起動します。
> vagrant up ↵ Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'ubuntu/disco64' version '20190816.0.0' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Remote connection disconnect. Retrying... ==> default: Machine booted and ready! [default] GuestAdditions versions on your host (6.0.10) and guest (6.0.6) do not match. Reading package lists... Building dependency tree... Reading state information... Package 'virtualbox-guest-dkms' is not installed, so not removed Package 'virtualbox-guest-x11' is not installed, so not removed The following packages will be REMOVED: virtualbox-guest-utils* 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 5726 kB disk space will be freed. (Reading database ... 59835 files and directories currently installed.) Removing virtualbox-guest-utils (6.0.6-dfsg-1) ... Processing triggers for man-db (2.8.5-2) ... (Reading database ... 59822 files and directories currently installed.) Purging configuration files for virtualbox-guest-utils (6.0.6-dfsg-1) ... Processing triggers for systemd (240-6ubuntu5.3) ... Reading package lists... Building dependency tree... Reading state information... linux-headers-5.0.0-25-generic is already the newest version (5.0.0-25.26). linux-headers-5.0.0-25-generic set to manually installed. The following additional packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-8 dpkg-dev fakeroot g++ g++-8 gcc gcc-8 gcc-8-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-8-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0 libstdc++-8-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev Suggested packages: binutils-doc cpp-doc gcc-8-locales menu debian-keyring g++-multilib g++-8-multilib gcc-8-doc libstdc++6-8-dbg gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-8-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan5-dbg liblsan0-dbg libtsan0-dbg libubsan1-dbg libmpx2-dbg libquadmath0-dbg glibc-doc bzr libstdc++-8-doc make-doc The following NEW packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-8 dkms dpkg-dev fakeroot g++ g++-8 gcc gcc-8 gcc-8-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-8-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0 libstdc++-8-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev 0 upgraded, 40 newly installed, 0 to remove and 0 not upgraded. Need to get 44.4 MB of archives. After this operation, 172 MB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu disco/main amd64 binutils-common amd64 2.32-7ubuntu4 [200 kB] Get:2 http://archive.ubuntu.com/ubuntu disco/main amd64 libbinutils amd64 2.32-7ubuntu4 [468 kB] Get:3 http://archive.ubuntu.com/ubuntu disco/main amd64 binutils-x86-64-linux-gnu amd64 2.32-7ubuntu4 [1852 kB] Get:4 http://archive.ubuntu.com/ubuntu disco/main amd64 binutils amd64 2.32-7ubuntu4 [3384 B] Get:5 http://archive.ubuntu.com/ubuntu disco/main amd64 libc-dev-bin amd64 2.29-0ubuntu2 [71.2 kB] Get:6 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 linux-libc-dev amd64 5.0.0-25.26 [1067 kB] Get:7 http://archive.ubuntu.com/ubuntu disco/main amd64 libc6-dev amd64 2.29-0ubuntu2 [2541 kB] Get:8 http://archive.ubuntu.com/ubuntu disco/main amd64 gcc-8-base amd64 8.3.0-6ubuntu1 [18.6 kB] Get:9 http://archive.ubuntu.com/ubuntu disco/main amd64 libisl19 amd64 0.20-2 [565 kB] Get:10 http://archive.ubuntu.com/ubuntu disco/main amd64 libmpc3 amd64 1.1.0-1 [40.8 kB] Get:11 http://archive.ubuntu.com/ubuntu disco/main amd64 cpp-8 amd64 8.3.0-6ubuntu1 [8935 kB] Get:12 http://archive.ubuntu.com/ubuntu disco/main amd64 cpp amd64 4:8.3.0-1ubuntu3 [27.6 kB] Get:13 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libcc1-0 amd64 9.1.0-2ubuntu2~19.04 [48.5 kB] Get:14 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libgomp1 amd64 9.1.0-2ubuntu2~19.04 [89.0 kB] Get:15 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libitm1 amd64 9.1.0-2ubuntu2~19.04 [28.0 kB] Get:16 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libatomic1 amd64 9.1.0-2ubuntu2~19.04 [9168 B] Get:17 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libasan5 amd64 9.1.0-2ubuntu2~19.04 [393 kB] Get:18 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 liblsan0 amd64 9.1.0-2ubuntu2~19.04 [139 kB] Get:19 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libtsan0 amd64 9.1.0-2ubuntu2~19.04 [300 kB] Get:20 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libubsan1 amd64 9.1.0-2ubuntu2~19.04 [130 kB] Get:21 http://archive.ubuntu.com/ubuntu disco/main amd64 libmpx2 amd64 8.3.0-6ubuntu1 [11.6 kB] Get:22 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libquadmath0 amd64 9.1.0-2ubuntu2~19.04 [145 kB] Get:23 http://archive.ubuntu.com/ubuntu disco/main amd64 libgcc-8-dev amd64 8.3.0-6ubuntu1 [2305 kB] Get:24 http://archive.ubuntu.com/ubuntu disco/main amd64 gcc-8 amd64 8.3.0-6ubuntu1 [9802 kB] Get:25 http://archive.ubuntu.com/ubuntu disco/main amd64 gcc amd64 4:8.3.0-1ubuntu3 [5212 B] Get:26 http://archive.ubuntu.com/ubuntu disco/main amd64 libstdc++-8-dev amd64 8.3.0-6ubuntu1 [1542 kB] Get:27 http://archive.ubuntu.com/ubuntu disco/main amd64 g++-8 amd64 8.3.0-6ubuntu1 [10.1 MB] Get:28 http://archive.ubuntu.com/ubuntu disco/main amd64 g++ amd64 4:8.3.0-1ubuntu3 [1600 B] Get:29 http://archive.ubuntu.com/ubuntu disco/main amd64 make amd64 4.2.1-1.2 [162 kB] Get:30 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 libdpkg-perl all 1.19.6ubuntu1.1 [230 kB] Get:31 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 dpkg-dev all 1.19.6ubuntu1.1 [675 kB] Get:32 http://archive.ubuntu.com/ubuntu disco/main amd64 build-essential amd64 12.6ubuntu1 [4664 B] Get:33 http://archive.ubuntu.com/ubuntu disco-updates/main amd64 dkms all 2.6.1-4ubuntu2.2 [67.0 kB] Get:34 http://archive.ubuntu.com/ubuntu disco/main amd64 libfakeroot amd64 1.23-1 [25.3 kB] Get:35 http://archive.ubuntu.com/ubuntu disco/main amd64 fakeroot amd64 1.23-1 [62.4 kB] Get:36 http://archive.ubuntu.com/ubuntu disco/main amd64 libalgorithm-diff-perl all 1.19.03-2 [46.6 kB] Get:37 http://archive.ubuntu.com/ubuntu disco/main amd64 libalgorithm-diff-xs-perl amd64 0.04-5build1 [11.2 kB] Get:38 http://archive.ubuntu.com/ubuntu disco/main amd64 libalgorithm-merge-perl all 0.08-3 [12.0 kB] Get:39 http://archive.ubuntu.com/ubuntu disco/main amd64 libfile-fcntllock-perl amd64 0.22-3build3 [33.1 kB] Get:40 http://archive.ubuntu.com/ubuntu disco/main amd64 manpages-dev all 4.16-1 [2222 kB] dpkg-preconfigure: unable to re-open stdin: No such file or directory Fetched 44.4 MB in 4min 7s (180 kB/s) Selecting previously unselected package binutils-common:amd64. (Reading database ... 59821 files and directories currently installed.) Preparing to unpack .../00-binutils-common_2.32-7ubuntu4_amd64.deb ... Unpacking binutils-common:amd64 (2.32-7ubuntu4) ... Selecting previously unselected package libbinutils:amd64. Preparing to unpack .../01-libbinutils_2.32-7ubuntu4_amd64.deb ... Unpacking libbinutils:amd64 (2.32-7ubuntu4) ... Selecting previously unselected package binutils-x86-64-linux-gnu. Preparing to unpack .../02-binutils-x86-64-linux-gnu_2.32-7ubuntu4_amd64.deb ... Unpacking binutils-x86-64-linux-gnu (2.32-7ubuntu4) ... Selecting previously unselected package binutils. Preparing to unpack .../03-binutils_2.32-7ubuntu4_amd64.deb ... Unpacking binutils (2.32-7ubuntu4) ... Selecting previously unselected package libc-dev-bin. Preparing to unpack .../04-libc-dev-bin_2.29-0ubuntu2_amd64.deb ... Unpacking libc-dev-bin (2.29-0ubuntu2) ... Selecting previously unselected package linux-libc-dev:amd64. Preparing to unpack .../05-linux-libc-dev_5.0.0-25.26_amd64.deb ... Unpacking linux-libc-dev:amd64 (5.0.0-25.26) ... Selecting previously unselected package libc6-dev:amd64. Preparing to unpack .../06-libc6-dev_2.29-0ubuntu2_amd64.deb ... Unpacking libc6-dev:amd64 (2.29-0ubuntu2) ... Selecting previously unselected package gcc-8-base:amd64. Preparing to unpack .../07-gcc-8-base_8.3.0-6ubuntu1_amd64.deb ... Unpacking gcc-8-base:amd64 (8.3.0-6ubuntu1) ... Selecting previously unselected package libisl19:amd64. Preparing to unpack .../08-libisl19_0.20-2_amd64.deb ... Unpacking libisl19:amd64 (0.20-2) ... Selecting previously unselected package libmpc3:amd64. Preparing to unpack .../09-libmpc3_1.1.0-1_amd64.deb ... Unpacking libmpc3:amd64 (1.1.0-1) ... Selecting previously unselected package cpp-8. Preparing to unpack .../10-cpp-8_8.3.0-6ubuntu1_amd64.deb ... Unpacking cpp-8 (8.3.0-6ubuntu1) ... Selecting previously unselected package cpp. Preparing to unpack .../11-cpp_4%3a8.3.0-1ubuntu3_amd64.deb ... Unpacking cpp (4:8.3.0-1ubuntu3) ... Selecting previously unselected package libcc1-0:amd64. Preparing to unpack .../12-libcc1-0_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libcc1-0:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libgomp1:amd64. Preparing to unpack .../13-libgomp1_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libgomp1:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libitm1:amd64. Preparing to unpack .../14-libitm1_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libitm1:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libatomic1:amd64. Preparing to unpack .../15-libatomic1_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libatomic1:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libasan5:amd64. Preparing to unpack .../16-libasan5_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libasan5:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package liblsan0:amd64. Preparing to unpack .../17-liblsan0_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking liblsan0:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libtsan0:amd64. Preparing to unpack .../18-libtsan0_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libtsan0:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libubsan1:amd64. Preparing to unpack .../19-libubsan1_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libubsan1:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libmpx2:amd64. Preparing to unpack .../20-libmpx2_8.3.0-6ubuntu1_amd64.deb ... Unpacking libmpx2:amd64 (8.3.0-6ubuntu1) ... Selecting previously unselected package libquadmath0:amd64. Preparing to unpack .../21-libquadmath0_9.1.0-2ubuntu2~19.04_amd64.deb ... Unpacking libquadmath0:amd64 (9.1.0-2ubuntu2~19.04) ... Selecting previously unselected package libgcc-8-dev:amd64. Preparing to unpack .../22-libgcc-8-dev_8.3.0-6ubuntu1_amd64.deb ... Unpacking libgcc-8-dev:amd64 (8.3.0-6ubuntu1) ... Selecting previously unselected package gcc-8. Preparing to unpack .../23-gcc-8_8.3.0-6ubuntu1_amd64.deb ... Unpacking gcc-8 (8.3.0-6ubuntu1) ... Selecting previously unselected package gcc. Preparing to unpack .../24-gcc_4%3a8.3.0-1ubuntu3_amd64.deb ... Unpacking gcc (4:8.3.0-1ubuntu3) ... Selecting previously unselected package libstdc++-8-dev:amd64. Preparing to unpack .../25-libstdc++-8-dev_8.3.0-6ubuntu1_amd64.deb ... Unpacking libstdc++-8-dev:amd64 (8.3.0-6ubuntu1) ... Selecting previously unselected package g++-8. Preparing to unpack .../26-g++-8_8.3.0-6ubuntu1_amd64.deb ... Unpacking g++-8 (8.3.0-6ubuntu1) ... Selecting previously unselected package g++. Preparing to unpack .../27-g++_4%3a8.3.0-1ubuntu3_amd64.deb ... Unpacking g++ (4:8.3.0-1ubuntu3) ... Selecting previously unselected package make. Preparing to unpack .../28-make_4.2.1-1.2_amd64.deb ... Unpacking make (4.2.1-1.2) ... Selecting previously unselected package libdpkg-perl. Preparing to unpack .../29-libdpkg-perl_1.19.6ubuntu1.1_all.deb ... Unpacking libdpkg-perl (1.19.6ubuntu1.1) ... Selecting previously unselected package dpkg-dev. Preparing to unpack .../30-dpkg-dev_1.19.6ubuntu1.1_all.deb ... Unpacking dpkg-dev (1.19.6ubuntu1.1) ... Selecting previously unselected package build-essential. Preparing to unpack .../31-build-essential_12.6ubuntu1_amd64.deb ... Unpacking build-essential (12.6ubuntu1) ... Selecting previously unselected package dkms. Preparing to unpack .../32-dkms_2.6.1-4ubuntu2.2_all.deb ... Unpacking dkms (2.6.1-4ubuntu2.2) ... Selecting previously unselected package libfakeroot:amd64. Preparing to unpack .../33-libfakeroot_1.23-1_amd64.deb ... Unpacking libfakeroot:amd64 (1.23-1) ... Selecting previously unselected package fakeroot. Preparing to unpack .../34-fakeroot_1.23-1_amd64.deb ... Unpacking fakeroot (1.23-1) ... Selecting previously unselected package libalgorithm-diff-perl. Preparing to unpack .../35-libalgorithm-diff-perl_1.19.03-2_all.deb ... Unpacking libalgorithm-diff-perl (1.19.03-2) ... Selecting previously unselected package libalgorithm-diff-xs-perl. Preparing to unpack .../36-libalgorithm-diff-xs-perl_0.04-5build1_amd64.deb ... Unpacking libalgorithm-diff-xs-perl (0.04-5build1) ... Selecting previously unselected package libalgorithm-merge-perl. Preparing to unpack .../37-libalgorithm-merge-perl_0.08-3_all.deb ... Unpacking libalgorithm-merge-perl (0.08-3) ... Selecting previously unselected package libfile-fcntllock-perl. Preparing to unpack .../38-libfile-fcntllock-perl_0.22-3build3_amd64.deb ... Unpacking libfile-fcntllock-perl (0.22-3build3) ... Selecting previously unselected package manpages-dev. Preparing to unpack .../39-manpages-dev_4.16-1_all.deb ... Unpacking manpages-dev (4.16-1) ... Setting up manpages-dev (4.16-1) ... Setting up libfile-fcntllock-perl (0.22-3build3) ... Setting up libalgorithm-diff-perl (1.19.03-2) ... Setting up binutils-common:amd64 (2.32-7ubuntu4) ... Setting up linux-libc-dev:amd64 (5.0.0-25.26) ... Setting up libgomp1:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up libfakeroot:amd64 (1.23-1) ... Setting up fakeroot (1.23-1) ... update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode Setting up libasan5:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up make (4.2.1-1.2) ... Setting up libquadmath0:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up libmpc3:amd64 (1.1.0-1) ... Setting up libatomic1:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up gcc-8-base:amd64 (8.3.0-6ubuntu1) ... Setting up libdpkg-perl (1.19.6ubuntu1.1) ... Setting up libmpx2:amd64 (8.3.0-6ubuntu1) ... Setting up libubsan1:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up libisl19:amd64 (0.20-2) ... Setting up libbinutils:amd64 (2.32-7ubuntu4) ... Setting up cpp-8 (8.3.0-6ubuntu1) ... Setting up libc-dev-bin (2.29-0ubuntu2) ... Setting up libalgorithm-diff-xs-perl (0.04-5build1) ... Setting up libcc1-0:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up liblsan0:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up libitm1:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up libalgorithm-merge-perl (0.08-3) ... Setting up binutils-x86-64-linux-gnu (2.32-7ubuntu4) ... Setting up libtsan0:amd64 (9.1.0-2ubuntu2~19.04) ... Setting up binutils (2.32-7ubuntu4) ... Setting up dpkg-dev (1.19.6ubuntu1.1) ... Setting up libgcc-8-dev:amd64 (8.3.0-6ubuntu1) ... Setting up cpp (4:8.3.0-1ubuntu3) ... Setting up libc6-dev:amd64 (2.29-0ubuntu2) ... Setting up libstdc++-8-dev:amd64 (8.3.0-6ubuntu1) ... Setting up gcc-8 (8.3.0-6ubuntu1) ... Setting up gcc (4:8.3.0-1ubuntu3) ... Setting up dkms (2.6.1-4ubuntu2.2) ... Setting up g++-8 (8.3.0-6ubuntu1) ... Setting up g++ (4:8.3.0-1ubuntu3) ... update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode Setting up build-essential (12.6ubuntu1) ... Processing triggers for man-db (2.8.5-2) ... Processing triggers for libc-bin (2.29-0ubuntu2) ... Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso Mounting Virtualbox Guest Additions ISO to: /mnt mount: /mnt: WARNING: device write-protected, mounted read-only. Installing Virtualbox Guest Additions 6.0.10 - guest version is 6.0.6 Verifying archive integrity... All good. Uncompressing VirtualBox 6.0.10 Guest Additions for Linux........ VirtualBox Guest Additions installer Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 5.0.0-25-generic. update-initramfs: Generating /boot/initrd.img-5.0.0-25-generic cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries nor crypto modules. If that's on purpose, you may want to uninstall the 'cryptsetup-initramfs' package in order to disable the cryptsetup initramfs integration and avoid this warning. Unmounting Virtualbox Guest Additions ISO from: /mnt ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => E:/MyDocuments/Project/Python/vagrant_test ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run. >
インストールしたvbguest
プラグインがうまく動作しているか確認します。
> vagrant vbguest --status ↵ [default] GuestAdditions 6.0.10 running --- OK. >
正常に動作しているようです。
続いて、Vagrantfile
に次の内容を追加して、ファイル共有の設定を行います。
Vagrantfile
# ローカルマシンの Vagrantfile があるディレクトリ内の data フォルダと # 仮想マシン内の /vagrant_data ディレクトリを共有する # config.vm.synced_folder {host_path}, {guest_path}, option... config.vm.synced_folder "./source", "/vagrant_data", owner: "vagrant", group: "vagrant", type: "virtualbox"
仮想マシンを再起動します。
> vagrant reload ↵ ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'ubuntu/disco64' version '20190816.0.0' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... ==> default: Machine booted and ready! [default] GuestAdditions 6.0.10 running --- OK. ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => E:/MyDocuments/Project/Python/vagrant_test default: /vagrant_data => E:/MyDocuments/Project/Python/vagrant_test/source ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run. >
確認用のファイルを作成し共有できたのか、確認しましょう。
$ ls -la / ↵ total 72 drwxr-xr-x 21 root root 4096 Aug 21 13:41 . drwxr-xr-x 21 root root 4096 Aug 21 13:41 .. lrwxrwxrwx 1 root root 7 Aug 16 03:04 bin -> usr/bin drwxr-xr-x 3 root root 4096 Aug 21 13:21 boot drwxr-xr-x 17 root root 3860 Aug 21 13:41 dev drwxr-xr-x 89 root root 4096 Aug 21 13:21 etc drwxr-xr-x 4 root root 4096 Aug 20 12:53 home lrwxrwxrwx 1 root root 32 Aug 16 03:05 initrd.img -> boot/initrd.img-5.0.0-25-generic lrwxrwxrwx 1 root root 32 Aug 16 03:05 initrd.img.old -> boot/initrd.img-5.0.0-25-generic lrwxrwxrwx 1 root root 7 Aug 16 03:04 lib -> usr/lib lrwxrwxrwx 1 root root 9 Aug 16 03:04 lib32 -> usr/lib32 lrwxrwxrwx 1 root root 9 Aug 16 03:04 lib64 -> usr/lib64 lrwxrwxrwx 1 root root 10 Aug 16 03:04 libx32 -> usr/libx32 drwx------ 2 root root 16384 Aug 16 03:06 lost+found drwxr-xr-x 2 root root 4096 Aug 16 03:04 media drwxr-xr-x 2 root root 4096 Aug 16 03:04 mnt drwxr-xr-x 3 root root 4096 Aug 21 13:21 opt dr-xr-xr-x 122 root root 0 Aug 21 13:41 proc drwx------ 4 root root 4096 Aug 20 12:53 root drwxr-xr-x 25 root root 860 Aug 21 13:41 run lrwxrwxrwx 1 root root 8 Aug 16 03:04 sbin -> usr/sbin drwxr-xr-x 5 root root 4096 Aug 20 12:53 snap drwxr-xr-x 2 root root 4096 Aug 16 03:04 srv dr-xr-xr-x 13 root root 0 Aug 21 13:41 sys drwxrwxrwt 9 root root 4096 Aug 21 13:41 tmp drwxr-xr-x 13 root root 4096 Aug 16 03:04 usr drwxrwxrwx 1 vagrant vagrant 0 Aug 21 13:30 vagrant drwxrwxrwx 1 vagrant vagrant 0 Aug 21 13:30 vagrant_data drwxr-xr-x 13 root root 4096 Aug 16 03:06 var lrwxrwxrwx 1 root root 29 Aug 16 03:05 vmlinuz -> boot/vmlinuz-5.0.0-25-generic lrwxrwxrwx 1 root root 29 Aug 16 03:05 vmlinuz.old -> boot/vmlinuz-5.0.0-25-generic $ ls -la /vagrant_data/ ↵ total 5 drwxrwxrwx 1 vagrant vagrant 0 Aug 21 13:30 . drwxr-xr-x 21 root root 4096 Aug 21 13:41 .. -rwxrwxrwx 1 vagrant vagrant 5 Aug 21 13:30 test.txt $ cat /vagrant_data/test.txt ↵ test
無事ファイルが共有できました。