LoginSignup
3
4

More than 5 years have passed since last update.

VagrantでFreeBSDを扱ったときにつまずいたこと

Posted at

 

前置き

さくらのスタンダードでFreeBSDのサーバーを触る機会がありました。
FreeBSDを触ること自体初めてだったため、CentOSとどう違うのか色々試したいと思いローカル環境を作ろうと思って、VagrantでFreeBSDの環境を作りました。
 
その際、いくつかつまずいた点があったのでまとめます。

 

環境

  • Macbook Air
    • mac OS Sierra v10.12.6
  • Vagrant
    • v1.9.8
  • VirtualBox
    • v5.0.40
  • FreeBSD
    • FreeBSD-10.2-RELEASE

導入手順

最初、VagrantとVirtualBoxを使うことが久々でSierraにアップデートしたということもあり、VirtualBoxのアプリを起動すると、

VirtualBox COMオブジェクトの作成に失敗しました。
呼び出し先 RC: NS_ERROR_ABORT (0x80004004)

というエラーで全く動作しなかったから、VirtualBoxは再インストールした。
※これは、今回のテーマとは違うので無視してくださいー

 
あと、vagrantコマンドで次のように操作できなくなっていました。

Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-triggers (> 0)'

 
plugin repairplugin updateもできなかったので、vagrant plugin expunge --reinstallで全部消しました...

$ vagrant plugin expunge --reinstall

This command permanently deletes all currently installed user plugins. It
should only be used when a repair command is unable to properly fix the
system.

Continue? [N]: yes

All user installed plugins have been removed from this Vagrant environment!

Vagrant will now attempt to reinstall user plugins that were removed.
Installing the 'vagrant-triggers' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Unable to resolve dependency: user requested 'vagrant-vbguest (> 0)'

$ vagrant plugin repair
Repairing currently installed plugins. This may take a few minutes...
Installed plugins successfully repaired!

$ vagrant plugin list
vagrant-share (1.1.9, system)

FreeBSDのBoxについて

なんか、久々にアクセスしたらデザインが変わっていたので別のサイトを開いてしまったのかと勘違いしてしまったが、下記リンク先のBoxをinitしてupしました。

FreeBSD-10.2-RELEASE

freebsdと検索して、一番ダウンロードされているBoxをとりあえず使いました。

つまずいた(その1): vagrant up

vagrant upすると、No base MAC address was specified.と言ってきた。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'freebsd/FreeBSD-10.2-RELEASE' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: 2015.08.13
==> default: Loading metadata for box 'freebsd/FreeBSD-10.2-RELEASE'
    default: URL: https://vagrantcloud.com/freebsd/FreeBSD-10.2-RELEASE
==> default: Adding box 'freebsd/FreeBSD-10.2-RELEASE' (v2015.08.13) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/freebsd/boxes/FreeBSD-10.2-RELEASE/versions/2015.08.13/providers/virtualbox.box
==> default: Successfully added box 'freebsd/FreeBSD-10.2-RELEASE' (v2015.08.13) for 'virtualbox'!
==> default: Importing base box 'freebsd/FreeBSD-10.2-RELEASE'...
No base MAC address was specified. This is required for the NAT networking
to work properly (and hence port forwarding, SSH, etc.). Specifying this
MAC address is typically up to the box and box maintainer. Please contact
the relevant person to solve this issue.

 
これは、下記リンク先で話されている内容を参考にしました。
Vagrant 1.9.1 - No base MAC address was specified?
Official Vagrant FreeBSD Images

 
これで解決だ!

 
 
 
...と思いきや

つまずいた(その2): vagrant reload | vagrant halt

再起動や停止でsudoコマンドができないと言ってきた。

$ vagrant reload
==> default: Attempting graceful shutdown of VM...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/shutdown -p now

Stdout from the command:



Stderr from the command:

 
これはちょっと時間がかかった。

対応その1: visudo

以下の内容を追記しても、今回は解決しなかった。

vagrant ALL=(ALL) NOPASSWD: ALL

対応その2: sudoコマンドのインストール

思いつくものはどんどん試した、次はsudoコマンドを入れていく。
めんどくさいけど、そもそもyumとか入っていなかったから、もっと面倒だと思ってこの手の方法はやめた。

vagrant@:~ % yum install sudo -y
yum: Command not found.

対応その3: VirtualBoxからVMを停止(シャットダウン)

そもそもシャットダウンの項目がなかった。
一時停止はあったが、完全な停止ではないため別を考えた。

 
ちなみに、VirtualBoxでVMを一時停止して、vagrant haltってすると状況は変わらずで、しかも一時停止してたVMが起動中になったw

対応その4: shutdown -h now

vagrant sshで入って、シャットダウンコマンドを叩こうと考えた。

vagrant@:~ % shutdown -h now
/sbin/shutdown: Permission denied.

 
 
うん、まぁそうだよねw
だから、vagrant reloadvagrant haltもダメなんだよな...

 
 
なので、su -ができるか試してみる。

vagrant@:~ % su -
Password:   ← 【vagrant】
root@:~ # shutdown -h now
Shutdown NOW!
shutdown: [pid 1067]
root@:~ #                                                                                
*** FINAL System shutdown message from vagrant@ ***                          

System going down IMMEDIATELY                                                  



System shutdown time has arrived
Connection to 127.0.0.1 closed by remote host.
Connection to 127.0.0.1 closed.

$ vagrant halt
==> default: Attempting graceful shutdown of VM...
    default: Guest communication could not be established! This is usually because
    default: SSH is not running, the authentication information was changed,
    default: or some other networking issue. Vagrant will force halt, if
    default: capable.
==> default: Forcing shutdown of VM...

 
 
あああぁぁーーーー止まったぁぁwww
これめんどくせーーー汗

まとめ

FreeBSDもそこそこめんどくさいことがわかりました。
ということで、これからどうするかはまた別の話ということで。
 

 

参考記事

 

3
4
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
3
4