ubuntu(デスクトップ版)をVagrantで構築する
/ 5 min read
Table of Contents
はじめに
ubuntu(デスクトップ版)をVagrantで構築する方法です。
方法
Vagrant で ubuntu を構築する
$ vagrant box add bento/ubuntu-18.04$ vagrant init bento/ubuntu-18.04
GUI 用に 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| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "bento/ubuntu-18.04" config.disksize.size = '64GB'
# Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box\_check\_update = false
# Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # NOTE: This will enable public access to the opened port # config.vm.network "forwarded\_port", guest: 80, host: 8080 config.vm.network "forwarded\_port", guest: 8888, host: 8888 # jupyter用のポート設定
# Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine and only allow access # via 127.0.0.1 to disable public access # config.vm.network "forwarded\_port", guest: 80, host: 8080, host\_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network "private\_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public\_network"
# Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. config.vm.synced_folder "./shared", "/home/vagrant/shared"
# Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "4096" vb.cpus = 2 vb.customize [ "modifyvm", :id, "--vram", "256", "--clipboard", "bidirectional", "--draganddrop", "bidirectional", "--accelerate3d", "on", "--hwvirtex", "on", "--nestedpaging", "on", "--largepages", "on", "--ioapic", "on", "--chipset", "ich9", "--pae", "on", "--paravirtprovider", "kvm", ] end # # View the documentation for the provider you are using for more # information on available options.
# Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. # config.vm.provision "shell", inline: <<-SHELL # apt-get update # apt-get install -y apache2 # SHELLend
光学ドライブを追加する
VirtualBox で対象の仮想環境を選択して、設定 > ストレージ
IDE コントローラに空の光学ドライブを追加する。
タイムゾーンを東京にする
$ sudo timedatectl set-timezone Asia/Tokyo$ timedatectl # タイムゾーンを確認する
Ubuntu のデスクトップ環境(MATE)をインストール
$ sudo apt update$ sudo apt upgrade$ sudo apt install ubuntu-mate-desktop$ reboot
Guest Additions のインストール
$ sudo apt install linux-headers-$(uname -r) build-essential dkms
ここで Virtualbox のメニューバーからデバイス > Guest Additions CD イメージの挿入
画面に従ってインストール、再起動。
コマンドでやるなら、↓ の通り。
$ sudo mount /dev/cdrom /media/cdrom$ sudo sh /media/cdrom/VBoxLinuxAdditions.run$ reboot
(Creating a Base Box - VirtualBox Provider - Vagrant by HashiCorp)
日本語化する
ibus-mozc のインストール
$ sudo apt install ibus-mozc$ reboot
システムを日本語にする
Menu > Preference > Language Support
の「Use the same language choices for startup and the login screen.」から Japanese を選択してインストールする。
インストールが終わったら追加された「日本語」を一番上まで持ってくる。
-
設定 > iBus の設定 「入力メソッド」タブで、「日本語-Mozc」を追加、「英語-英語(US)」を削除する。
-
設定 > Mozc の設定 「一般」タブのキー設定を「ATOK」にして、編集へ。
以下の 2 項目(各 3 個ある)の入力キーを全て「Ctrl Space」に変更する # 英字キーボードの場合
モード | コマンド |
---|---|
直接入力 | IME を有効化 |
入力文字なし | キャンセル後 IME を無効化 |
ここまで終わったら再起動して完了。
おまけ
Virtual Box マネージャーで BOX を選択してから設定 > ディスプレイ > リモートディスプレイ
でサーバーを有効化のチェックを外す