5
2

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.

Windows + VirtualBox(Ubuntu18.04)でNervesの環境構築(Yes, we can!)

Last updated at Posted at 2020-01-04

2020/05/06 追記

はじめに

Windows 10スペック

  • Microsoft Windows 10 Home
  • 10.0.18362 ビルド 18362
  • Dell Inc.
  • Inspiron 5767
  • x64-ベース PC
  • プロセッサ: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz、2901 Mhz、2 個のコア、4 個のロジカル プロセッサ
  • インストール済の物理メモリ: 16.0 GB

他につかうモノ

  • Raspberry Pi 2
    • このページにあるものでしたら他のものでも大丈夫です
    • 私はRaspberry Pi 2しかもっていません:santa_tone2:
  • microSD
  • microSDカードアダプタ(USBでWindowsに挿せるもの)

VirtualBoxのインストール

  • VirtualBox 6.0
  • をインストールします
  • 2020/1/4現在、このあとインストールする「Vagrant 2.2.6」がVirtualBox 6.0まで対応しています
  • インストーラをダウンロードして、.exeをダブルクリックしてNext、Nextです

Vagrantのインストール

Ubuntuのセットアップ

Vagrantfile

Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"

  config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
    vb.memory = "4096"
  end

  config.vm.provision "shell", inline: <<-SHELL
    apt-get update
    apt install -y build-essential automake autoconf git squashfs-tools ssh-askpass libssl-dev libncurses5-dev fop xsltproc libxml2-utils openjdk-8-jdk unixodbc-dev libwxgtk3.0-dev unzip
    wget https://github.com/fhunleth/fwup/releases/download/v1.5.1/fwup_1.5.1_amd64.deb
    dpkg -i fwup_1.5.1_amd64.deb
  SHELL
end
  • 適当なフォルダーにVagrantfileを置いてください
  • vb.cpusvb.memoryの値はお使いのマシンにあわせて調整してください
  • 公式ドキュメントに書いてあることをしています
  • 違いは、libssl-dev libncurses5-dev fop xsltproc libxml2-utils openjdk-8-jdk unixodbc-dev libwxgtk3.0-dev unzipを追加しています
    • libssl-dev libncurses5-dev fop xsltproc libxml2-utils openjdk-8-jdk unixodbc-dev libwxgtk3.0-devErlangのインストールで必要になります
    • unzipElixirのインストールで必要になります
    • 以下Elixirのインストール等も"shell"で書こうとしたのですが、asdfが事前にsudo su - vagrantとかしても/root/.asdfにcloneされるのであきらめました
  • Vagrantfileがおいてあるフォルダーにコマンドプロンプトでcdしてたどりついたら

Windows

> vagrant up
  • してください
  • 私の場合、20分くらいでしたでしょうか
  • 無事vagrant upが終わったら

Windows

> vagrant ssh
  • してください
  • 以降Ubuntuでの操作になります

Ubuntu

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.6
$ echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
$ echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
$ source ~/.bashrc
$ asdf plugin-add erlang
$ asdf plugin-add elixir
$ asdf install erlang 22.1.4
$ asdf install elixir 1.9.4-otp-22
$ asdf global erlang 22.1.4
$ asdf global elixir 1.9.4-otp-22
$ mix local.hex --force
$ mix local.rebar
$ mix archive.install hex nerves_bootstrap --force
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa 
  • asdf install erlang 22.1.4が一番時間がかかります
    • ドキュメントまわりで警告でましたが私は無視しました
    • 公開当初は上記のような適当なこと書いていましたが、先人の方々の記事を参考にして警告がなくなるようにしました
  • 私の場合、16分くらいでしたでしょうか
  • もし進んでいるのかどうか不安になりましたら、もう一個コマンドプロンプトを立ち上げて、vagrant sshして

Ubuntu

$ tail -f /home/vagrant/.asdf/plugins/erlang/kerl-home/builds/asdf_22.1.4/otp_build_22.1.4.log

サンプルプロジェクト

  • 引き続きUbuntuでの作業です

Ubuntu

$ git clone https://github.com/nerves-project/nerves_examples.git
$ cd nerves_examples/hello_leds/
$ export MIX_TARGET=rpi2
$ mix deps.get
$ mix firmware
$ exit
  • MIX_TARGETはTargetsをみながらお手元のハードウェアを指定してください
  • mix deps.getmix firmwareは少し時間かかります
  • 一旦、UbuntuからぬけてmicroSDを認識させます

Windows

> vagrant halt
  • Ubuntuを止めます
  • firmwareを焼くmicroSDカードをUSBアダプタ経由でWindowsに挿します
  • 私はこういうやつを使いました

IMG_20200104_224605.jpg

vm-vb.png

  • ↑こういうやつをダブルクリックして
  • [設定] |> [USB]とすすんで

usb-setting.png

  • こんな感じに設定します
  • ふたたびUbuntuを起動しましょう

Windows

> vagrant up
> vagrant ssh

Ubuntu

$ lsusb
Bus 001 Device 002: ID 1307:0310 Transcend Information, Inc. SD/MicroSD CardReader [hama]
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  • こんな感じでmicroSDっぽいやつを認識していれば大丈夫です
$ cd nerves_examples/hello_leds/
$ export MIX_TARGET=rpi2
$ mix firmware.burn

firmware_burn.png

  • 私は、microSDカードのサイズで1を選びました
  • 一番緊張する瞬間であります
  • こんがり焼きあがりましたら、ハードウェアにmicroSDカードをさしこんで電源ONです!

IMG_20200104_234408.jpg

VID_20200104_214146.gif

Tips

パソコンの電源を切るとき

# Ubuntu
$ exit
logout
Connection to 127.0.0.1 closed.

# Windows
> vagrant halt

また開発するぞ!

# Windows
> vagrant up
> vagrant ssh

# Ubuntu
$ mix nerves.new hello_nerves

このあとは!

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?