Windows 10 Virtual Machine Building Script


At first

Describes a script for creating a Windows 10 virtual machine on a Mac.

The script you are using is published as vm-configure on github, so please download it from github or download it from here.

See the link below for the vm-configure folder configuration.

VirtualBox and Vagrant are required to run the script.If it is not installed, please refer to the link below.

See Preparing Box Files for Windows 10 at the link below for Windows 10 Box Files.


This is the main script for building Windows 10 virtual machines.

The location of the script file is in the current directory.

SCRIPT_DIR=$(dirname "$0")

The execution result of the script is set to be output to the file (vm-create.command.log) with .log after the execution script file name, and the execution start date and time are output to the log file.

exec &>>(tee "${0}.log")
date "+%Y/%m/%d %H:%M:%S"

Vagrant’s Box file (the template for virtual terminals for Vagrant) and the directory on which VirtualBox virtual machines are stored VM_BASE_DIR set to default.

# Directory to store vagrant box and virtual machine
VM_BASE_DIR=$(cd "${SCRIPT_DIR}/../" && pwd)

You can change the location of Vagrant’s Box file VAGRANT_HOME environment variables and settings.

The script is writing the .bash_profile to VAGRANT_HOME bash initialization file as an environment variable.

If you want to change the destination, please change the commented out part with # to the state below.

# --------------------------------------------------
# Change the save destination of vagrant box files to the VM_BASE_DIR folder.
# If you don't want to change the save folder, please comment out.
if [ -e "${HOME}/.bash_profile" ]; then
    sed -i _cb.bak -e "/^export VAGRANT_HOME=.*$/d" "${HOME}/.bash_profile"
    rm "${HOME}/.bash_profile_cb.bak"
echo 'export VAGRANT_HOME="'"${VM_BASE_DIR}"'/.vagrant.d"' >>"${HOME}/.bash_profile"
# --------------------------------------------------

Changing the virtual machine location of VirtualBox.

If you want to change the destination, please change the commented out part with # to the state below.

# --------------------------------------------------
# Change the save destination of vagrant box files to the VM_BASE_DIR folder.
# If you don't want to change the save folder, please comment out.
vboxmanage setproperty machinefolder "${VM_BASE_DIR}/VirtualBox VMs"
# --------------------------------------------------

The location of Vagrant’s Box file is determined VAGRANT_HOME environment variables.The environment variables stored in the bash initialization file are re-loaded and activated with echo 'export VAGRANT_HOME VM_BASE_DIR>'“>’>’.vagrant.d” >>”>>>></.bash_profile”.

if [ -e "${HOME}/.bash_profile" ]; then
    . "${HOME}/.bash_profile"

If the vagrant-reload plug-in that allows Vagrant to restart during provisioning is not installed, it is installed.

if [ ! "`vagrant plugin list | grep 'vagrant-reload'`" ]; then
    vagrant plugin install vagrant-reload

If your Windows 10 Box file is not registered with Vagrant, you are registered with Vagrant.

Box files can be downloaded from here.

if [ ! "`vagrant box list | grep 'Microsoft/EdgeOnWindows10'`" ]; then
    vagrant box add "./MSEdge -" --name "Microsoft/EdgeOnWindows10"
    rm "./MSEdge -"

We are initializing Vagrant to run in the current directory in vagrant init. vagrant up is loading the Vagrant file in the current directory and starting the virtual machine.

Vagrant init
Vagrant up


Vagrantfile is a file that describes the configuration required to build a virtual machine in Vagrant.

VAGRANTFILE_API_VERSION api version of the Vagrantfile to be used in the configuration.


You can include definitions of multiple virtual machines between Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| to end.

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

Defines the configuration of the virtual machine to build between config.vm.define :vm1 do |vm1| and end.

If you want to define multiple virtual machines, you can configure multiple virtual machines in a single Vagrantfile by repeating the definition with vm1 as vm2, etc.

  config.vm.define :vm1 do |vm1|

Specify the name of the Box of Vagrant to use.

You can create the Box file yourself as a template for the virtual machine, or you can use the Box file published to Vagrant Cloud, but this time you create it from the box file you downloaded from Microsoft.

The process of registering Box files to Vagrant is done with = "Microsoft/EdgeOnWindows10"

We are changing the default SSH to WinRM settings to communicate with Windows during provisioning.

vm1.vm.communicator = "winrm"

Host OS”./. /.. Specifies that the /guest-share/windows10″ directory should be synchronized to the guest OS’s “/users/IEUser/share” directory.

By synchronizing, you can share and use files on the host OS and guest OS.

    vm1.vm.synced_folder "./../../guest-share/windows10", "/users/IEUser/share", create: true

Specifying the IP address to be set for the virtual machine. "private_network", ip: ""

Setting the user ID and password to run WinRM.

    vm1.winrm.username = "IEUser"
    vm1.winrm.password = "Passw0rd!"

Provisioning Vagrant specifies that the script should be run when the virtual machine is initialized.

Here we run the Powershell script configure-1.ps1 to japaneseize Windows, restart the virtual machine with reload, and then run the powershell script configuration-2.ps1 that continues to be Japanese.

For more information about the Japanese script, see the link below.

    vm1.vm.provision :shell, inline: "powershell -File \"C:\\users\\IEUser\\share\\os\\configure-1.ps1\""
    vm1.vm.provision :reload
    vm1.vm.provision :shell, inline: "powershell -File \"C:\\users\\IEUser\\share\\os\\configure-2.ps1\""

Setting up the virtual machine you want to create in VirtualBox.

guiSet whether to display the virtual machine when the virtual machine starts
nameName of the virtual machine
cpusThe number of CPUs to assign to the virtual machine
memoryThe amount of memory to be allocated to the virtual machine
customizeCustomization settings.
You can set the parameters that can be set in VBoxManage of VirtualBox.
See here for the parameters that can be set.
modifyvmCommand to change the virtual machine
–clipboardSettings for sharing the clipboard between the host OS and the guest OS
–draganddropDrag-and-drop settings between the host OS and the guest OS
–vramSetting the size of the video memory
–graphicscontrolerGraphics controller for use with virtual machines
setextradataCommands for additional settings to a virtual machine
GUI/ScaleFactorScale the screen size of the virtual machine displayed in the host OS
    vm1.vm.provider "virtualbox" do |vb|
      vb.gui = true = "windows10"
      vb.cpus = 2
      vb.memory = "4096"
      vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
      vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
      vb.customize ["modifyvm", :id, "--vram", "128"]
      vb.customize ['modifyvm', :id, '--graphicscontroller', 'vboxsvga']
      vb.customize ['setextradata', :id, 'GUI/ScaleFactor', '2.00']