From 8d96529820b5a420d3801b69c04cf15a5d380cab Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 29 Jan 2016 15:44:23 -0800 Subject: [PATCH 1/6] mdnstool: don't start when running as a Hyper-V VM Windows doesn't grok mDNS by default. No need to start mdnstool Signed-off-by: Rolf Neugebauer --- alpine/packages/mdnstool/etc/init.d/mdnstool | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/alpine/packages/mdnstool/etc/init.d/mdnstool b/alpine/packages/mdnstool/etc/init.d/mdnstool index 239355a51..22c6dc359 100755 --- a/alpine/packages/mdnstool/etc/init.d/mdnstool +++ b/alpine/packages/mdnstool/etc/init.d/mdnstool @@ -10,7 +10,9 @@ depend() start() { - ebegin "Starting mDNS server" + [ -d /sys/bus/vmbus ] && exit 0 + + ebegin "Starting mDNS server" [ -n "${PIDFILE}" ] || PIDFILE=/var/run/mdnstool.pid @@ -27,7 +29,9 @@ start() stop() { - ebegin "Stopping mDNS server" + [ -d /sys/bus/vmbus ] && exit 0 + + ebegin "Stopping mDNS server" [ -n "${PIDFILE}" ] || PIDFILE=/var/run/mdnstool.pid From ad95c77f90662c83ba8b87d485edec719473e13a Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 2 Feb 2016 19:12:52 -0800 Subject: [PATCH 2/6] hvtools: fix script to configure the IP address from the host Signed-off-by: Rolf Neugebauer --- alpine/packages/hvtools/hv_set_ifconfig | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/alpine/packages/hvtools/hv_set_ifconfig b/alpine/packages/hvtools/hv_set_ifconfig index 09175fe52..3da655487 100755 --- a/alpine/packages/hvtools/hv_set_ifconfig +++ b/alpine/packages/hvtools/hv_set_ifconfig @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # This example script activates an interface based on the specified # configuration. @@ -70,21 +70,20 @@ ifdown $DEVICE # create a new interfaces file echo "auto lo" > $outf echo "iface lo inet loopback" >> $outf -echo "" >> outf +echo "" >> $outf echo "auto $DEVICE" >> $outf if [ "$BOOTPROTO" = "dhcp" ]; then echo "iface $DEVICE inet dhcp" >> $outf else echo "iface $DEVICE inet static" >> $outf - echo " address $IPADDR0" >> outf - echo " netmask $NETMASK0" >> outf - echo " gateway $GATEWAY" >> outf + echo " address $IPADDR0" >> $outf + echo " netmask $NETMASK0" >> $outf + echo " gateway $GATEWAY" >> $outf + echo " nameserver $DNS1 $DNS2 $DNS3" >> $outf fi -echo " nameserver $DNS0" >> outf - -echo " hwaddress ether $HWADDR" >> outf +echo " hwaddress ether $HWADDR" >> $outf # Up the interface ifup $DEVICE From 7f7abf722e48e10e3c270a8d9c6824d4e74fd918 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Thu, 4 Feb 2016 16:02:30 -0800 Subject: [PATCH 3/6] docker: also listen to local unix socket when running on Hyper-V Signed-off-by: Rolf Neugebauer --- alpine/packages/docker/etc/init.d/docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpine/packages/docker/etc/init.d/docker b/alpine/packages/docker/etc/init.d/docker index db5b2dd69..19231e9c5 100755 --- a/alpine/packages/docker/etc/init.d/docker +++ b/alpine/packages/docker/etc/init.d/docker @@ -14,7 +14,7 @@ then else # If there is no database and we run on Hyper-V start daemon # with networking for now. This will change in the future! - [ -d /sys/bus/vmbus ] && DOCKER_OPTS="${DOCKER_OPTS} -H tcp://0.0.0.0:2375" + [ -d /sys/bus/vmbus ] && DOCKER_OPTS="${DOCKER_OPTS} -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock" fi From 68af3a7c22d66b205f32addb9dd7efaa007a4852 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 5 Feb 2016 09:26:33 -0800 Subject: [PATCH 4/6] hvtools: Force down the interface is config changes Signed-off-by: Rolf Neugebauer --- alpine/packages/hvtools/hv_set_ifconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpine/packages/hvtools/hv_set_ifconfig b/alpine/packages/hvtools/hv_set_ifconfig index 3da655487..e9d0f69e6 100755 --- a/alpine/packages/hvtools/hv_set_ifconfig +++ b/alpine/packages/hvtools/hv_set_ifconfig @@ -65,7 +65,7 @@ outf=/etc/network/interfaces . $1 # Down the interface -ifdown $DEVICE +ifdown -f $DEVICE # create a new interfaces file echo "auto lo" > $outf From 4189cffeeef16ccbaf7ecbe8501d1dd414b29d07 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 5 Feb 2016 15:47:47 -0800 Subject: [PATCH 5/6] dnsfix: don't run it in a Hyper-V VM Signed-off-by: Rolf Neugebauer --- alpine/packages/dnsfix/etc/init.d/dnsfix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alpine/packages/dnsfix/etc/init.d/dnsfix b/alpine/packages/dnsfix/etc/init.d/dnsfix index 3dceeabb4..40276cbc1 100755 --- a/alpine/packages/dnsfix/etc/init.d/dnsfix +++ b/alpine/packages/dnsfix/etc/init.d/dnsfix @@ -10,7 +10,9 @@ depend() start() { - ebegin "Testing DNS resolution" + [ -d /sys/bus/vmbus ] && exit 0 + + ebegin "Testing DNS resolution" ifconfig eth0 2>1 >/dev/null && \ (dig localhost 2>&1 > /dev/null || printf "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > /etc/resolv.conf) From b037de72b16ec53eff7144d98c22a355d1a68077 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 5 Feb 2016 16:58:59 -0800 Subject: [PATCH 6/6] win: remove PS script and documentation. They live elsewhere now Signed-off-by: Rolf Neugebauer --- docs/windows-notes.md | 174 ---------------------------------- scripts/MobyLinux.ps1 | 214 ------------------------------------------ 2 files changed, 388 deletions(-) delete mode 100644 docs/windows-notes.md delete mode 100755 scripts/MobyLinux.ps1 diff --git a/docs/windows-notes.md b/docs/windows-notes.md deleted file mode 100644 index aacb485bb..000000000 --- a/docs/windows-notes.md +++ /dev/null @@ -1,174 +0,0 @@ -# Initial install - -I use Windows 10 Pro in a Vmware Fusion VM. Make sure it's a 64bit VM. - -In Vmware Fusion VM settings make sure the `Processor -> Advanced Options -> Enable hypervisor applications in virtual machine` is selected. This enables nested virtualisation. If you install on bare hardware make sure the virtualisation technology is enabled in the BIOS. - -When creating the user, make sure that te username does **not** contain -any spaces. This will save you a world of pain! On Windows 10, also select custom settings during the install and disable all the spying/calling home features introduced. Also, since I'm running Windows in a VM on an already password protected system, I disable password for my user, using `c:\Windows\System32\netplwiz.exe`. Just untick the password checkbox. - - -Install software: -- [Git](http://git-scm.com/): Make sure you select 'Use git from Windows command prompt'. It gives access to git from PS, but still installs git-bash. -- [Putty](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). For getting to the serial console of the MobyLinux VM. -- [Sysinternals](https://technet.microsoft.com/en-gb/sysinternals/bb842062). Generally useful. -- [Chocolatey](https://chocolatey.org/). It's kinda like homebrew for windows. - - -## Enable Hyper-V feature - -This [MSDN article](https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/quick_start/walkthrough_install) is useful. - -Install Hyper-V with powershell: -``` -Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All -``` -This did *not* work! So I had to use the GUI to install instead as per -the MSDN article. - - -# Boot MobyLinux - -## Create a MobyLinux ISO image - -For now, this has to be done on a Linux docker install. - -Clone the [Moby git repository](https://github.com:docker/moby.git), cd into it and then do: -``` -cd alpine -make mobylinux.iso -``` -Copy the iso image to your Windows host/VM. - - -## Create a switch - -We need to create a VM Switch to attach the MobyLinux Networking to. This is a one off operation. Check your main Ethernet interface with either `ipconfig` or `Get-NetAdapter` (in powershell). On my system it is called 'Ethernet0'. Could also be called "Wi-Fi" Then create a switch with the same name (in elevated powershell): - -``` -New-VMSwitch -Name "VirtualSwitch" -AllowManagementOS $True -NetAdapterName *Replace-with-adapter-name-from-Get-NetAdapter* -``` -TODO: Figure out how to configure a NAT switch - - -## Booting MobyLinux from ISO - -In the moby repository under the scripts directory, there is a Powershell script called `MobyLinux.ps1` which allows you to create, start, stop and destroy a MobyLinux VM. Copy it over to your Windows machine. - -This must be executed from an elevated Powershell (ie Run as Administrator). - -Some Windows installation may not allow execution of arbitrary Powershell scripts. Check with `Get-ExecutionPolicy`. It is likely set to 'Restricted', which prevents you from running scripts. Change the policy: -``` -Set-ExecutionPolicy -ExecutionPolicy Unrestricted -force -``` - -Now, you can create and start a new MobyLinux VM - -``` -.\MobyLinux.ps1 -IsoFile .\mobylinux.iso -create -start -``` - -You can stop the VM with: -``` -.\MobyLinux.ps1 -stop -``` -and it can be restarted with: -``` -.\MobyLinux.ps1 -start -``` -and all the files can be removed with: -``` -.\MobyLinux.ps1 -destroy -``` - -## Running Docker - -You need a Windows docker client matching the version running on -MobyLinux. I build mine from source in a Linux container using `make -cross`. - - -When starting the MobyLinux VM on Hyper-V, the docker daemon is -currently started to listen on TCP socket 2375 inside the VM. - -**The IP address of the VM may changes on every start** - -To determine the IP address, you ca either type: -``` -Get-VMNetworkAdapter MobyLinuxVM -``` -and then set `DOCKER_HOST` accordingly, or you can execute the PS -snippet printed out by MovyLinux.ps1: -``` -$vmIP=(Get-VMNetworkAdapter MobyLinuxVM).IPAddresses[0] -$env:DOCKER_HOST = "tcp://" + $vmIP + ":2375" -``` - -## Getting a serial console - -The MobyLinux VM is configured with a serial console which Hyper-V relays to a named pipe. You can attach putty to the named pipe to get the console: -``` -'C:\Program Files (x86)\PuTTY\putty.exe' -serial \\.\pipe\MobyLinuxVM-com1 -``` - -For easy access, I create a shortcut to putty.exe on my Desktop, -rename it to "MobyVM Console", open the shortcur properties and cut -and paste the above line into the "Target" field in the Shortcut tab. Note, the shortcut needs to be executed as Administrator to work. - - -# ToDos and Open issues -- Networking configuration - - switch between wifi/wired (see also below) - - NAT, see eg the Docker on Windows docs on MSDN -- Host FS sharing (SMB?) -- Host <-> docker in VM communication (with Proxy) - - maybe hijack serial console as transport... -- Start Hyper-V guest services in Moby -- Would like to use a Hyper-V generation 2 VM. That requires and ISO - with UEFI boot (see below). Though, Azure might currently only - support Generation 1 VMs -- Logging - -many more - -``` -If running Windows 10 Hyper-V on a laptop you may want to create a -virtual switch for both the ethernet and wireless network cards. With -this configuration you can change your virtual machines between theses -switches dependent on how the laptop is network connected. Virtual -machines will not automatically switch between wired and wireless. -``` - -# Notes, thoughts, links - -[Serial Console Service](https://github.com/alexpilotti/SerialConsoleService): This is a Windows Service (written in C#) running inside a Windows VM opening a command prompt if something attaches to the named pipe on the the host. Might be useful for Host<->VM communication. - -[Generation 2 VMs](https://blogs.technet.microsoft.com/jhoward/2013/10/24/hyper-v-generation-2-virtual-machines-part-1/): Contains very useful details about differences between generation 1 and generation 2 Hyper-V VMs. - -Thought: Another option for booting Moby on Hyper-V might be to boot a EFI file from Hyper-V and have that directly load the Linux kernel and initrd like we kinda do on xhyve. Would safe us the whole ISO image hassle. - -[Create a Windows VM to run Containers](https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/container_setup): Contains good script for config - -[Enable Windows server to run Containers](https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/inplace_setup): Another good script linked fro here for setting up Networking. - -[Shared Network setup](http://blog.areflyen.no/2012/10/10/setting-up-internet-access-for-hyper-v-with-nat-in-windows-8/): GUI, maybe convert to PS. - -## UEFI Boot -Hyper-V Generation 2 VMs require UEFI booting. I've tried many -different ways to create Hybrid UEFI/Legacy boot ISO images and none -of them worked...Might need to restart the effort at some point. - -Maybe just create a FAT32 formatted raw disk, copy EFI linux loader -(efilinux, from kernel source tree) to it along with the kernel image and initrd (no -syslinux etc). Roughly following -[this guide](https://wiki.ubuntu.com/USBStickUEFIHowto), but not -bother with the main partition. Convert this to a VHD(X) using the -vbox script (or maybe on windows with appropriate tools) and boot from -there. [Enterprise](https://sevenbits.github.io/Enterprise) might be -an alternative Linux UEFI loader. - -Another alternative would be to boot a Linux EFI loader from Hyper-V -and pass enough arguments for it to load kernel and initrd directly -from the host file system. - -Vmware Fusion UEFI boot. Add `firmware = "efi"` to the `.vmx` file. diff --git a/scripts/MobyLinux.ps1 b/scripts/MobyLinux.ps1 deleted file mode 100755 index 1dd61ec52..000000000 --- a/scripts/MobyLinux.ps1 +++ /dev/null @@ -1,214 +0,0 @@ -<# - .SYNOPSIS - Manages a MobyLinux VM to run Linux Docker on Hyper-V - - .DESCRIPTION - Creates/Destroys/Starts/Stops A MobyLinux VM to run Docker on Hyper-V - - .PARAMETER IsoFile - Path to the MobyLinux ISO image, must be set for Create/ReCreate - - .PARAMETER Create - Create a MobyLinux VM - - .PARAMETER Destroy - Destroy (remove) a MobyLinux VM - - .PARAMETER ReCreate - Destroy an existing MobyLinux VM and create a new one - - .PARAMETER Start - Start an existing MobyLinux VM - - .PARAMETER Stop - Stop a running MobyLinux VM - - .PARAMETER $VmName - If passed, use this name for the MobyLinux VM, otherwise 'MobyLinuxVM' - - .PARAMETER $SwitchName - If passed, use this VMSwitch for network connectivity. Otherwise, use the first existing switch with external connectivity. - - .EXAMPLE - .\MobyLinux.ps1 -IsoFile .\mobylinux.iso -Create - .\MobyLinux.ps1 -Start -#> - -# This may only work on Windows 10/Windows Server 2016 as we are using a NAT switch - -Param( - [string] - $VmName = "MobyLinuxVM", - - [string] - $IsoFile = ".\mobylinux.iso", - - [string] - $SwitchName, - - [switch] - $Create, - - [switch] - $Destroy, - - [switch] - $Start, - - [switch] - $Stop -) - -$global:VmSwitchName = $SwitchName - -# Other hardcoded global parameters -$global:VmMemory = 2147483648 # 2GB -$global:VhdSize = 21474836480 # 20GB -$global:VmProcessors = ([Math]::min((Get-VMHost).LogicalProcessorCount, 2)) - -# Default location for VHDs -$global:VhdRoot = "$((Get-VMHost).VirtualHardDiskPath)".TrimEnd("\") -# Where we put Moby -$global:VmVhdFile = "$global:VhdRoot\$VmName.vhd" -$global:VmIsoFile = "$global:VhdRoot\$VmName.iso" - -# XXX For some reason this works in ISE but not on an elevated Powershell prompt -#function -#Check-Feature -#{ -# [CmdletBinding()] -# param( -# [ValidateNotNullOrEmpty()] -# [string] -# $FeatureName -# ) -# -# # WindowsServer and Windows client use differnet commandlets....sigh -# if (Get-Command Get-WindowsFeature -ErrorAction SilentlyContinue) { -# if (!(Get-WindowsFeature $FeatureName).Installed) { -# throw "Please install $FeatureName" -# } -# } else { -# if ((Get-WindowsOptionalFeature -Online -FeatureName $FeatureName).State -eq "Disabled") { -# throw "Please install $FeatureName" -# } -# } -#} - -function -Check-Switch -{ - # If no switch name was passed in pick the first external switch - if ($global:VmSwitchName -eq "") { - $switches = (Get-VMSwitch |? SwitchType -eq "External") - - if ($switches.Count -gt 0) { - $global:VmSwitchName = $switches[0].Name - } - } - - if ($global:VmSwitchName -ne "") { - Write-Output "Using external switch: $global:VmSwitchName" - } else { - Write-Output "Please create a VMSwitch, e.g." - Write-Output "New-VMSwitch -Name VirtualSwitch -AllowManagementOS `$True -NetAdapterName Ethernet0" - Write-Output "Where Ethernet0 is the name of your main network adapter. See Get-Netadapter" - throw "No switch" - } -} - - -function -Create-MobyLinuxVM -{ - if ($(Get-VM $VmName -ea SilentlyContinue) -ne $null) { - throw "VM $VmName already exists" - } - - if (Test-Path $global:VmVhdFile) { - throw "VHD $global:VmVhdPath already exists" - } - - if (!(Test-Path $IsoFile)) { - throw "ISO file at $IsoFile does not exist" - } - - Write-Output "Creading new dynamic VHD: $global:VmVhdFile" - $vhd = New-VHD -Path $global:VmVhdFile -SizeBytes $global:VhdSize - - Write-Output "Creating VM $VmName..." - $vm = New-VM -Name $VmName -Generation 1 -VHDPath $vhd.Path - $vm | Set-VM -MemoryStartupBytes $global:VmMemory - $vm | Set-VMProcessor -Count $global:VmProcessors - - # We use SCSI in the Linux VM - Add-VMScsiController -VMName $VmName - - # Copy the ISO and add it to the VM - Copy-Item $IsoFile $global:VmIsoFile - Add-VMDvdDrive -VMName $VMName -Path $global:VmIsoFile - - # Attach to switch - $vm | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "$global:VmSwitchName" - - # Enable Serial Console - Set-VMComPort -VMName $VmName -number 1 -Path "\\.\pipe\$VmName-com1" -} - -function -Destroy-MobyLinuxVM -{ - Write-Output "Destroying $VmName" - if ($(Get-VM $VmName -ea SilentlyContinue) -ne $null) { - Remove-VM $VmName -Force - } - - if (Test-Path $global:VmVhdFile) { - Remove-Item $global:VmVhdFile - } - - if (Test-Path $global:VmIsoFile) { - Remove-Item $global:VmIsoFile - } -} - -function -Start-MobyLinuxVM -{ - Write-Output "Starting $VmName" - Start-VM -VMName $VmName - - Write-Output 'Connect to Docker by executing:' - Write-Output '$vmIP=(Get-VMNetworkAdapter MobyLinuxVM).IPAddresses[0]' - Write-Output '$env:DOCKER_HOST = "tcp://" + $vmIP + ":2375"' -} - -function -Stop-MobyLinuxVM -{ - Write-Output "Stopping $VmName" - # You can use -Force to basically pull the plug on the VM - # The below requires the Hyper-V tools to be installed in the VM - Stop-VM -VMName $VmName -} - -# Main entry point -# XXX Check if these feature names are the same on Windows Server -# XXX These work when run in ISE but not whe run on normal elevated Powershell -#Check-Feature Microsoft-Hyper-V -#Check-Feature Microsoft-Hyper-V-Hypervisor -#Check-Feature Microsoft-Hyper-V-Management-PowerShell - -if ($Stop) { - Stop-MobyLinuxVM -} -if ($Destroy) { - Destroy-MobyLinuxVM -} -if ($Create) { - Check-Switch - Create-MobyLinuxVM -} -if ($Start) { - Start-MobyLinuxVM -}