Skip to content

Commit 8922543

Browse files
committed
Add Hyper-V support
1 parent dfbff29 commit 8922543

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ Looking for SQL Server on Windows VM? Check https://github.com/msabramo/vagrant_
1010
## Features
1111

1212
* Ubuntu 16.04
13+
* Hyper-V or [VirtualBox](https://www.virtualbox.org/)
1314
* [SQL Server 2017 on Linux](https://docs.microsoft.com/en-us/sql/linux/) (official packages by Microsoft)
1415
* [SQL Server command-line tools on Linux](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools)
1516
* Pre-configured with
1617
* Vagrant default user: `vagrant` with password `vagrant`
1718
* Port forwarding from host `2433` to guest `1433` (default).
19+
* *Hyper-V*: No port forwarding configured - default port used.
1820
* Database user `sa` with password `Password123`.
1921
* Database `master`.
2022
* Set SQL Server edition to `Developer` with `MSSQL_PID="Developer`.
2123
* Other of configuration [Environment variable](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables) set to default.
2224

2325
## Requirements
2426

25-
* [VirtualBox](https://www.virtualbox.org/) installed.
27+
* Hyper-V enabled or VirtualBox installed.
2628
* [Vagrant](https://www.vagrantup.com/downloads.html) installed.
2729

2830
## Installation
@@ -35,18 +37,22 @@ Looking for SQL Server on Windows VM? Check https://github.com/msabramo/vagrant_
3537

3638
### Vagrant VM
3739

38-
* `vagrant up` to create and boot the guest virtual machine.
39-
First time run, this may take quite a while as the base box image is downloaded
40-
and provisioned, packages installed.
40+
* `vagrant up` - create and boot the guest virtual machine.
41+
42+
First time run, this may take quite a while as the base box image is downloaded and provisioned, packages installed.
43+
44+
On Hyper-V, if Vagrant prompts for the Hyper-V Switch, choose `Default Switch` or `External Switch`.
45+
46+
On Hyper-V, no port forwarding is enabled. Once the provisioning is done, IP address of the guest is printed. Use this IP to connect from host to the SQL Server using the default port.
47+
48+
* `vagrant ssh` - access the guest shell via SSH.
4149

42-
* `vagrant ssh` to get direct access to the guest shell via SSH.
4350
You'll be connected as the vagrant user.
4451
You can get root access with `sudo` command.
4552

46-
* `vagrant halt` to shutdown the guest machine.
53+
* `vagrant halt` - shutdown the guest machine.
4754

48-
* `vagrant destroy` to wipe out the guest machine completely.
49-
You can re-create it and start over with `vagrant up`.
55+
* `vagrant destroy` - wipe out the guest machine completely.
5056

5157
### SQL Server
5258

Vagrantfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
# -*- mode: ruby -*-
22
# vi: set ft=ruby :
33

4-
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
5-
64
# Vagrant virtual environments for SQL Server 2017 on Ubuntu Linux
5+
76
Vagrant.configure(2) do |config|
8-
# Do not use official Ubuntu box, it is broken in many ways
9-
# https://bugs.launchpad.net/cloud-images/+bug/1569237
10-
config.vm.box = "bento/ubuntu-16.04"
11-
config.vm.box_check_update = true
12-
config.vm.network :forwarded_port, host: 2433, guest: 1433
13-
config.vm.network "private_network", type: "dhcp"
14-
config.vm.provider "virtualbox" do |vb|
7+
config.vm.box_check_update = false
8+
9+
config.vm.provider "virtualbox" do |vb, override|
10+
vb.name = "vagrant-mssql"
1511
vb.memory = "4096"
1612
vb.cpus = 4
13+
# Do not use official Ubuntu box, broken in many ways https://bugs.launchpad.net/cloud-images/+bug/1569237
14+
override.vm.box = "bento/ubuntu-16.04"
15+
override.vm.network "private_network", type: "dhcp"
16+
override.vm.network :forwarded_port, host: 2433, guest: 1433 # SQLServer
17+
end
18+
19+
config.vm.provider "hyperv" do |hv, override|
20+
hv.vmname = "vagrant-mssql"
21+
hv.memory = "4096"
22+
hv.cpus = 4
23+
override.vm.box = "synax/ubuntu-16-04-server"
24+
override.vm.synced_folder ".", "/vagrant", disabled: true
25+
# Windows (Build 16237+) comes with "Default Switch" to allow VMs to NAT host internet (any!) connection
26+
# https://blogs.technet.microsoft.com/virtualization/2017/07/26/hyper-v-virtual-machine-gallery-and-networking-improvements/
27+
# Apparently, this is an undocumented workaround to specify Hyper-V network in Vagrantfile.
28+
# Otherwise, Vagrant will prompt listing Hyper-V Switch-es to select.
29+
#override.vm.network "private_network", bridge: "Default Switch"
30+
#override.vm.network "public_network", bridge: "External Switch"
1731
end
1832

1933
scripts = [ "bootstrap.sh" ]

bootstrap.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ export DEBIAN_FRONTEND="noninteractive"
1010
sudo sed -i "s/^127\.0\.0\.1.*/127.0.0.1 localhost $HOSTNAME/g" /etc/hosts
1111
# Install pre-requisites
1212
sudo apt-get -y -q update
13-
sudo apt-get -y -q install curl
13+
## Ubuntu 16.04 does not deliver add-apt-repository by default
14+
sudo apt-get -y -q install curl software-properties-common
1415
# Pre-installation
15-
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
16+
curl -s -S --retry 3 https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
1617
## Repository Microsoft SQL Server
17-
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)"
18+
sudo add-apt-repository "$(curl -s -S --retry 3 https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)"
1819
## Repository SQL Server command-line tools
19-
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list)"
20+
sudo add-apt-repository "$(curl -s -S --retry 3 https://packages.microsoft.com/config/ubuntu/16.04/prod.list)"
2021
sudo apt-get -y -q update
2122
sudo -E bash -c 'apt-get -y -q install mssql-server'
2223
sudo -E bash -c 'apt-get -y -q install mssql-tools'
@@ -40,5 +41,5 @@ echo "SQLServer: Running sqlcmd -Q SELECT @@version"
4041
export PATH="$PATH:/opt/mssql-tools/bin"
4142
sqlcmd -S localhost -U SA -P 'Password123' -Q "SELECT @@version;"
4243
echo "SQLServer: Guest IP address:"
43-
/sbin/ifconfig | grep 'inet addr:'
44+
ip addr show|grep -w inet
4445
echo "Bootstrap: DONE"

0 commit comments

Comments
 (0)