Pythonと!

プログラミングド素人の勉強日記です。

ubuntu(デスクトップ版)をVagrantで構築する

$ 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
  # SHELL
end

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を選択してから
設定 > ディスプレイ > リモートディスプレイで
サーバーを有効化のチェックを外す