Michal Nowak
2017-05-24 75c55337697026d3bc6c5a1291f34b99cf3b1b94
Fix `--memory` attribute on Linux & other stuff

Changes:
* Fixed memory assignment otherwise, Vagrant would be assigning
VirtualBox memory in giga bytes, not mega bytes:
```
==> default: Running 'pre-boot' VM customizations...
A customization command failed:
["modifyvm", :id, "--memory", 2]
```
* Use long form of `rsync` option `-z`.
* Fix vCPU assignment on Windows.
* Added requirements for Windows (`ssh`, `rsync`) to documentation.
* Typos.

Tested on openSUSE Leap 42.2 and Windows 10 Pro with latest Vagrant and
VirtualBox.
2 files modified
47 ■■■■■ changed files
Vagrantfile 31 ●●●● patch | view | raw | blame | history
doc/vagrant.md 16 ●●●● patch | view | raw | blame | history
Vagrantfile
@@ -12,6 +12,7 @@
#
# Copyright 2016 Adam Stevko. All rights reserved.
# Copyright 2017 Michal Nowak
#
Vagrant.configure("2") do |config|
@@ -25,10 +26,10 @@
  config.vm.box_check_update = true
  # Unless OpenIndiana is better supported in vagrant, we have to use this
  # workaround. The problem is with vagrant creating folder as root:root,
  # but rsync connects as vagrant and fails to write.
  # workaround. The problem with vagrant is that it creates folder as root:root,
  # but rsync connects as vagrant and thus fails to write.
  config.vm.synced_folder ".", "/vagrant", type: "rsync",
    rsync__args: ["--verbose", "--archive", "-z", "--copy-links"],
    rsync__args: ["--verbose", "--archive", "--compress", "--copy-links"],
    rsync__rsync_path: "pfexec rsync", owner: "vagrant", group: "vagrant"
  # Autoconfigure resources for development VM. The snippet is taken from
@@ -38,22 +39,24 @@
  config.vm.provider "virtualbox" do |v|
    host = RbConfig::CONFIG['host_os']
    # Give VM 1/4 system memory and CPU core count
    # Get memory size and CPU cores amount
    if host =~ /darwin/
      # sysctl returns Bytes and we need to convert to MB
      mem = `sysctl -n hw.memsize`.to_i / 1024
      cpus = `sysctl -n hw.ncpu`.to_i / 4
      # sysctl returns Bytes
      mem = `sysctl -n hw.memsize`.to_i
      cpus = `sysctl -n hw.ncpu`.to_i
    elsif host =~ /linux/
      # meminfo shows KB and we need to convert to MB
      mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024
      cpus = `grep -c Processor /proc/cpuinfo`.to_i / 4
      # meminfo shows size in kB; convert to Bytes
      mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.to_i * 1024
      cpus = `getconf _NPROCESSORS_ONLN`.to_i
    elsif host =~ /mswin|mingw|cygwin/
      # Windows code via https://github.com/rdsubhas/vagrant-faster
      mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024
      cpus = 2
      mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i
      cpus = `echo %NUMBER_OF_PROCESSORS%`.to_i
    end
    mem = mem / 1024 / 4
    # Give VM 1/4 system memory as well as CPU core count
    mem /= 1024 ** 2 * 4
    cpus /= 4
    v.customize ["modifyvm", :id, "--memory", mem]
    v.customize ["modifyvm", :id, "--cpus", cpus]
@@ -66,6 +69,6 @@
    pfexec pkg install build-essential
    cd /vagrant && gmake setup
    echo "VM ready, happy contributing!"
    echo "VM is ready, happy contributing!"
  SHELL
end
doc/vagrant.md
@@ -20,7 +20,7 @@
* Download Vagrant from the official [download site](https://www.vagrantup.com/downloads.html). Select a version for your platform. We recommend to use the latest version.
* Download VirtualBox from the official [download site](https://www.virtualbox.org/wiki/Downloads). We recommend to use always the latest VirtualBox.
* Fork the [oi-userland repository](https://github.com/OpenIndiana/oi-userland.git) on Github.
* Fork the [oi-userland repository](https://github.com/OpenIndiana/oi-userland.git) on GitHub.
* Clone your oi-userland repository somewhere:
  ```
@@ -39,13 +39,21 @@
  git pull --rebase upstream oi/hipster
  ```
* On Windows make sure, that `rsync` and `ssh` commands are available, and that Hyper-V (if actually installed) is disabled:
  ```
  dism.exe /Online /Disable-Feature:Microsoft-Hyper-V-All
  ```
  And restart.
* Start the VM by running:
  ```
  vagrant up
  ```
  This might take a while as build utilities will be download and oi-userland configured.
  This might take a while as development utilities will be downloaded and oi-userland configured.
* Once the VM is online, enter it:
@@ -68,8 +76,8 @@
## Vagrant box updates
Vagrant box is configured to check for updates and if a new update is available,
Vagrant will display the notice.
Vagrant will display a notice.
## Getting help
If not sure, ask.
If not sure, ask on IRC, mailing list, etc.