alpine-iot演習環境の構築手順
alpine-iot環境の構築手順について解説します。Arduino互換機Digispark開発ボードを使ってBadUSBを作る演習で必要となります。
1. VirtualBox本体のインストール
Downloads – Oracle VM VirtualBoxから自分のOS環境にあった最新のVirtualBoxをダウンロードしてインストールしてください。
セットアップ途中のCustom Setup画面で「VirtualBox USB Support」が選択されていることを確認してください。
初めてインストールするときに「このデバイス ソフトウェアをインストールしますか?」(名前:Oracle Corporation ユニバーサル シリアル バス コントローラ)という確認画面が表示されたら「インストール」をクリックしてOracle社のUSBコントローラを必ずインストールするようにしてください。
このUSBコントローラのインストールが完了できていないと、ホスト側に接続されたUSBデバイスをゲストOSから認識できなくなります。
2. Extension Pack のインストール
VirtualBox本体のインストールが終わった後、上記と同じVirtualBoxのダウンロードページから「VirtualBox x.y.z Oracle VM VirtualBox Extension Pack」の下にあるリンク「All supported platforms」をクリックして、Extension Packをダウンロードしてファイルをダブルクリックしてインストールしてください。ダブルクリック後にインストール画面が表示されるまで少し時間がかかります。このとき、必ずVirtualBox本体のバージョンと一致するExtension Packをインストールしてください。
3. Vagrant本体のインストール
Download - Vagrant by HashiCorpから最新のVagrantをインストールしてください。
初回インストール時はファイルの展開にものすごい時間がかかりますが、気長に待っていれば終わります。 SSDではなくHDDの場合、インストールが完了するまで数分から十数分ぐらい待つ必要があります。 Vagrantのインストールが終わったらOSの再起動が必要となります。
# 4. alpine-iot.zip の解凍
勉強会会場にてUSBメモリで配布している alpine-iot.zip を解凍してください。
※日本語を含むフォルダ名がフルパスの途中にあるとVagrantのssh鍵生成に失敗する不具合が報告されているので、英語名のみのパス上で解凍してください。
5. コマンドプロンプトの起動
cmd.batをダブルクリックして、解凍フォルダ上でコマンドプロンプトを起動します。 (macOSの場合は、コマンドを開いて解凍ディレクトリに cd alpine-iot してください。)
4. alpine-iot 作業ディレクトリの作成
mkdir alpine-iot cd alpine-iot
※日本語を含むフォルダ名がフルパスの途中にあるとVagrantのssh鍵生成に失敗する不具合が報告されているので、英語名のみのパス上で解凍してください。
5. 演習で使う Vagrant box のインストール
コマンドプロンプトから以下のコマンドを実行してください。
vagrant init takesako/alpine-iot
テンプレートのVagrantfileファイルが自動で作成されます。
【実行結果】
C:\alpine-iot>vagrant init takesako/alpine-iot A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
6. VMの起動
Vagrantfileのあるディレクトリで以下のコマンドを実行してください。
vagrant up
Vagrantfileに書かれた該当のboxイメージからVMが自動で起動します。
【実行結果】
C:\alpine-iot>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'takesako/alpine-iot' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Successfully added box 'takesako/alpine-iot' (v3.9.4) for 'virtualbox'! ==> default: Importing base box 'takesako/alpine-iot'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'takesako/alpine-iot' version '3.9.4' is up to date... ==> default: Setting the name of the VM: alpine-iot_default_1566895136480_97807 ==> 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: 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: 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... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => C:/alpine-iot
7. VMの接続
以下のコマンドを実行してsshログインします。
vagrant ssh
コンソールに「Welcome to Alpine Linux!」が表示されたらログインに成功です。 ログインに成功したらexitと入力して、ゲストOSのLinuxからログアウトします。
exit
【実行結果】
C:\alpine-iot>vagrant ssh Welcome to Alpine Linux! alpine:~$ exit Connection to 127.0.0.1 closed.
ゲストOSとホストOS間でのファイル共有の確認(任意:この項目は作業しなくて良いです)
ゲストOS上の /vagrant フォルダは、ホストOSでVagrantfileが存在するフォルダとファイルが共有されています。 以下のコマンドを実行してゲストOSのLinuxからファイルを作成し、ホストOSからそのファイルを読み込めることを確認してください。
echo host > host.txt vagrant ssh cd /vagrant ls cat host.txt echo guest > guest.txt exit type guest.txt
【実行結果】
C:\alpine-iot>echo host > host.txt C:\alpine-iot>vagrant ssh Welcome to Alpine Linux! alpine:~$ cd /vagrant alpine:/vagrant$ ls Vagrantfile host.txt alpine:/vagrant$ cat host.txt host alpine:/vagrant$ echo guest > guest.txt alpine:/vagrant$ exit Connection to 127.0.0.1 closed. C:\alpine-iot>type guest.txt guest
8. VMの停止(ここまで実施する)
以下のコマンドを入力してゲストOSを安全にシャットダウンします。
vagrant halt
【実行結果】
C:\alpine-iot>vagrant halt ==> default: Attempting graceful shutdown of VM...
→これで演習環境の確認は終了です。お疲れ様でした。
9. VMイメージの削除(これは実行しないでください)
もしも、VMイメージを削除したいときは以下のコマンドを実行してください。
vagrant destroy vagrant box remove takesako/alpine-iot
→これは演習環境を完全に消去したいときだけ実行してください。