やってみた。

勉強/チャレンジなどやってみたことのログ

how to create xubuntu 16.04 LTS vagrant base box

Overview

this is how to create vagrant base box for xubuntu 16.04.

you'll get box like: xubuntu-16.04-desktop-amd64.box after this todos.

environment

preparation

todos

install xubuntu to virtualbox

after installation

log in with vagrant user

install openssh-server

$ sudo apt-get install openssh-server -y

if you want to ssh to this machine from host os, configure 'Settings' -> Network -> Advanced -> 'Port Forwarding'

  • Host IP: 127.0.0.1
  • Host Port: 2222
  • Guest IP: 10.0.2.15
  • Guest Port: 22

and from Host OS

$ ssh vagrant@127.0.0.1 -p 2222

set root password vagrant

$ sudo passwd
vagrant
vagrant

sudo with no password

$ sudo visudo

and rewrite line [A] with [B]

[A] %sudo ALL=(ALL:ALL) ALL
[B] %sudo ALL=(ALL) NOPASSWD: ALL

put vagrant public key

$ cd ~
$ mkdir .ssh
$ cd .ssh
$ wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
$ mv vagrant.pub authorized_keys
$ chmod 600 authorized_keys

configure sshd_config

$ sudo vi /etc/ssh/sshd_config

and rewrite line [A] with [B], add [C]

[A] #AuthorizedKeysFile %h/.ssh/authorized_keys
[B] AuthorizedKeysFile %h/.ssh/authorized_keys
[C] UseDNS no

if you want to get smaller box

# Zero free space to aid VM compression
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

refer to: Making smaller base boxes #343

shut down virtual machine

package box

in the Host OS

$ vagrant package --base xubuntu-16.04-desktop-amd64

check

$ vagrant box add xubuntu-16.04-desktop-amd64.box package.box
$ vagrant init xubuntu-16.04-desktop-amd64.box

if you want to launch GUI

$ vi Vagrantfile

and configure:

  # 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|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    # vb.memory = "1024"

    vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
  end

and, you'll need vagrant-vbguest. more information: vagrant-vbguest

$ vagrant plugin install vagrant-vbguest

finally start the machine

$ vagrant up --provider virtualbox