0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VMでマウントする時のメモ

Posted at

概要

結構前にvirtualhostとローカルのマウント設定をまとめたメモがあったので転載。

VMを構築したのちに実際の開発をするのがサーバ上だと大変なので、ローカルとマウントを行いたい時にこの設定をすると楽になる(今だとDockerやVagrantがあるから参考程度に)

環境

CentOS6.9

Virtual Box側の設定

Guest Additionsの挿入

対象ホストのウィンドウを選択

左上の「デバイス」 -> 「Guest Additions のCDイメージを挿入… 」を選択
スクリーンショット_2020-12-01_6_00_10.png

共有フォルダの設定

対象のVMを選択→「設定」を押下します。

「共有フォルダ」の項目から以下のように設定します。

スクリーンショット 2020-12-01 6.32.30.png

対象フォルダはマウントしたいローカルのフォルダを指定してください。
フォルダ名は自由に設定してください(あとで使います)
「自動マウント」と「永続化する」にチェックを入れます。

スクリーンショット 2020-12-01 6.28.41.png

上記のようになるので「OK」をクリックします。

centos-linux側

上記で設定したVBoxLinuxAdditionsを実行します。

mkdir /media/cdrom

mount -r /dev/cdrom /media/cdrom
cd /media/cdrom
./VBoxLinuxAdditions.run

./VBoxLinuxAdditions.run実行時エラー対策

上記実行時にいくつかエラーが出たので対処方法をまとめる

エラー1:Building the main Guest Additions module

以下のようにログ確認を確認、カーネルがなかったのでインストールする。

tail -f /var/log/vboxadd-install.log 
yum -y update kernel
yum -y install kernel-devel kernel-headers dkms gcc gcc-c++
//カーネルをインストールしたら再起動
reboot

//再起動したら再度実行
mount -r /dev/cdrom /media/cdrom
cd /media/cdrom
./VBoxLinuxAdditions.run

カーネルのアップデート後はrebootが必要というか、isoの再設定が必要のようです。

エラー2:bzip2がないと言われる

Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.38 Guest Additions for Linux........
bzip2 not found.  Please install: bzip2 tar; and try again.
[root@soichost cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.38 Guest Additions for Linux........
bzip2 not found.  Please install: bzip2 tar; and try again.

のでbzip2をインストールする

[root@soichost cdrom]# yum install bzip2

マウントを実行

mount -t vboxsf [vboxshare] [directory]

以下の項目に沿って実行してください。

項目 説明
vboxshare VMの「共有フォルダ」設定時につけたディレクトリ名
directory マウントしたいcentos側のパス

そうすると指定したdirectoryにローカル情報がマウントされていると思います。

これでローカルからファイル操作をしてVMに反映させることが可能になります。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?