#author("2020-03-01T09:44:32+09:00","default:haikikyou","haikikyou")
#author("2020-03-14T13:10:05+09:00","default:haikikyou","haikikyou")
[[moritetuのIT関連技術メモ/VirtualBox]]
#contents

* ホストOSとGeustOS間の共有フォルダ [#v5959bb4]

Guest Additionsをインストールすることで簡単にホストとゲスト間でフォルダを共有できる。

** Host: Windows, Guest: Centos7 [#n22b9a07]

流れは以下。

+ ゲストOS上でGuest Additionsのインストール
+ ホストOS上のVirtual BoxのゲストOSの設定で共有フォルダを設定
+ ゲストOS上でマウント
++ 起動スクリプトを登録することで次回以降は自動マウント

''1. Guest Additionsのインストール''

kernel moduleが必要なためインストールする。

#geshi(bash){{{
yum -y install kernel kernel-headers kernel-devel bzip2 gcc make
}}}
&label(warn){参考}; https://www.virtualbox.org/manual/ch02.html#externalkernelmodules

&label(memo){メモ}; kernelとheaderのバージョンが一致していない場合
#geshi(bash){{{
yum update kernel
}}}

続いてGuestAdditionsをインストール。~
GuestOSのツールメニューから「Guest Additions CDイメージの挿入」を選択。~
これで、ドライブにCDが挿入された状態となるので、ゲストOSからマウントして見えるようにする。

&ref(./vbox-guest-addition.jpg,100%);

#geshi(bash){{{
mount -r /dev/cdrom /mnt/
cd /mnt
sh VBoxLinuxAdditions.run
}}}

''2. 共有フォルダを設定''

以下では、vbという名前で設定する。

&ref(./vboxshare.png,70%);


''3. ゲストOS上でマウント''

#geshi(bash){{{
mkdir /vbox
mount -t vboxsf vb /vbox
}}}

自動マウントさせる場合は、systemdのサービスでスクリプトを登録する。~

&label(sample){例}; /etc/systemd/system/rclocal.service

#geshi{{{
[Unit]
Description=/etc/rc.local

[Service]
ExecStart=/etc/rc.local
Type=simple
Restart=always

[Install]
WantedBy=multi-user.target
}}}
&label(warn){参考}; http://man7.org/linux/man-pages/man5/systemd.unit.5.html

サービスを有効にしておく。

#geshi{{{
systemctl enable rclocal.service
}}}

* Vagrantによる設定 [#o97b0d1b]

vagrantを使うともっと簡単に設定可能である。

#geshi(ruby){{{
Vagrant::Config.run do |config|
  # ...
  config.vm.share_folder "vb", "/guest/path", "/host/path"
end
}}}

&label(link){URL};
-  https://www.vagrantup.com/
- https://www.vagrantup.com/docs/synced-folders/basic_usage.html

&label(warn){参考}; ''VBoxGuestAdditionsの自動インストール''

共有フォルダをマウントするには、GeuestAdditionsのインストールが必要である。~
guest os側にインストールする必要があるが、vagrant-vbguestをインストールすることで自動でインストールしてくれる。

基本的にはインストールするだけで特別な設定は不要。

#geshi(bash){{{
vagrant plugin install vagrant-vbguest
}}}

&label(link){URL}; https://github.com/dotless-de/vagrant-vbguest
* 参考リンク [#lf7a0728]

- https://www.virtualbox.org/manual/
- https://linuxconfig.org/how-to-install-virtualbox-guest-additions-on-centos-7-linux



トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP