HowTo Install VyOS in Hyper-V with a VLAN Trunk


#1

I trolled the forums for some time, looking to see if anyone had put VyOS on Hyper-V. I saw several attempts and one deal-breaker: VyOS running Debian Wheezy (7.something) will install and recognize the non-legacy vNICs of Hyper-V 2012 R2, but during a reboot or reset network connectivity will be severed on all vNICs using VLANs. There are two ways to get around this flaw:

  1. Reapply the VLAN settings while the VyOS VM is up and running or…
  2. Completely shut down and boot the VyOS VM.

I decided to automate option #1 and here’s how I did it…

  1. Pull down the latest Wheezy-Transit build. I got mine from here. Put the VyOS Wheezy Live ISO on your Hyper-V server.
  2. Open Hyper-V Manager. Create a new VM.
    [list]
  3. Name: VyOS
  4. 1 vCPU
  5. 512 MB RAM
  6. 1x 8GB VHD
  7. 1x DVD Drive
  8. 2x vNIC - Non-Legacy
    [/list]
  9. Open the properties for this VM and…
    [list]
  10. “Mount” the Live CD ISO in the DVD Drive
  11. Assign the 1st vNIC to a Virtual Switch that connects to a physical NIC on the Hyper-V server
  12. Assign the 2nd vNIC to a Virtual Switch that is Internal-only
    [/list]
  13. Boot the VM
  14. Log in to the VM
    [list]
  15. vyos/vyos
    [/list]
  16. Run this command “install system”. NOTE: I tried the recommended path of “install image” but the Debian Live image failed to boot. It dumped me out to an “(initramfs)” prompt. I tried “install image” twice before going with “install system”.
  17. Follow the prompts to continue/finish the installation
  18. Run this command “poweroff”
  19. When powered off, unmount the ISO
  20. Power on the VyOS VM
  21. Type “cat /etc/debian_version”. Make sure you are at 7.0 at least.
  22. Execute the following commands in the VyOS console: configure edit interfaces ethernet eth0 set description 'External_Network' set address 192.168.1.10/24 set duplex auto set speed auto commit exit edit interfaces ethernet eth1 set description 'VLAN_Trunk' delete address set duplex auto set speed auto commit exit # Set up VLANs # VLAN 30 set interfaces ethernet eth1 vif 30 description 'VLAN 30' set interfaces ethernet eth1 vif 30 address '192.168.30.1/24' # Set System Parameters set system domain-name Domain.com set system host-name VyOS set system name-server 192.168.1.1 commit save exit reboot
  23. Open a PowerShell window with Administrative Rights on the Hyper-V host.
  24. Execute this command to list all NICs on your VyOS VM:
    Get-VMNetworkAdapter -VMName 'VyOS'
  25. Add a “WHERE” clause to filter the list to just the NIC that is connected to the Internal-only virtual switch. In my example, my Internal-only virtual switch is called “Tenant Logical Switch”.
    Get-VMNetworkAdapter -VMName 'VyOS' | WHERE {$_.SwitchName -ieq 'Tenant Logical Switch'}
  26. Pipe this returned object into ‘Get-VMNetworkAdapterVLAN’ to see which VLANs (if any) are currently assigned to this vNIC.
    Get-VMNetworkAdapter -VMName 'VyOS' | WHERE {$_.SwitchName -ieq 'Tenant Logical Switch'} | Get-VMNetworkAdapterVlan
  27. Pipe this returned object into ‘Set-VMNetworkAdapterVLAN’ to enable VLAN Trunking on this vNIC.
    Get-VMNetworkAdapter -VMName 'VyOS' | WHERE {$_.SwitchName -ieq 'Tenant Logical Switch'} | Set-VMNetworkAdapterVlan -Trunk -NativeVlanId 0 -AllowedVlanIdList 1-4094
  28. Create this PowerShell file on the Hyper-V host: <# This script is triggered by, and executed by the Task Scheduler. Log: Microsoft-Windows-Hyper-V-Worker/Admin Source: Hyper-V-Worker Event ID: 18512 & 18514 This is an entry that gets made in the Event Log when the VM is rebooted from the Hyper-V console from a running state: Log Name: Microsoft-Windows-Hyper-V-Worker-Admin Source: Microsoft-Windows-Hyper-V-Worker Date: 4/9/2014 12:31:13 AM Event ID: 18512 Task Category: None Level: Information Keywords: User: NT VIRTUAL MACHINE\6D4B300A-49C9-4B73-8734-C404427E73BB Computer: HyperVHost.Domain.com Description: 'VyOS' was reset. (Virtual machine ID 6D4B300A-49C9-4B73-8734-C404427E73BB) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-Hyper-V-Worker" Guid="{51DDFA29-D5C8-4803-BE4B-2ECB715570FE}" /> <EventID>18512</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x8000000000000000</Keywords> <TimeCreated SystemTime="2014-04-09T04:31:13.051890800Z" /> <EventRecordID>568</EventRecordID> <Correlation ActivityID="{D18A9FB4-405F-000E-F493-A7D25F40CF01}" /> <Execution ProcessID="6496" ThreadID="7520" /> <Channel>Microsoft-Windows-Hyper-V-Worker-Admin</Channel> <Computer>HyperVHost.Domain.com</Computer> <Security UserID="S-1-5-83-1-1833644042-1265846729-79967367-3144908354" /> </System> <UserData> <VmlEventLog xmlns:auto-ns2="http://schemas.microsoft.com/win/2004/08/events" xmlns="http://www.microsoft.com/Windows/Virtualization/Events"> <VmName>VyOS</VmName> <VmId>6D4B300A-49C9-4B73-8734-C404427E73BB</VmId> </VmlEventLog> </UserData> </Event> This is an entry that gets made when the VM is rebooted from within the OS from a running state: Log Name: Microsoft-Windows-Hyper-V-Worker-Admin Source: Microsoft-Windows-Hyper-V-Worker Date: 4/9/2014 12:24:23 AM Event ID: 18514 Task Category: None Level: Information Keywords: User: NT VIRTUAL MACHINE\6D4B300A-49C9-4B73-8734-C404427E73BB Computer: HyperVHost.Domain.com Description: 'VyOS' was reset by the guest operating system. (Virtual machine ID 6D4B300A-49C9-4B73-8734-C404427E73BB) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-Hyper-V-Worker" Guid="{51DDFA29-D5C8-4803-BE4B-2ECB715570FE}" /> <EventID>18514</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x8000000000000000</Keywords> <TimeCreated SystemTime="2014-04-09T04:24:23.853186000Z" /> <EventRecordID>561</EventRecordID> <Correlation ActivityID="{D18A9FB4-405F-000D-849C-8BD15F40CF01}" /> <Execution ProcessID="7372" ThreadID="4128" /> <Channel>Microsoft-Windows-Hyper-V-Worker-Admin</Channel> <Computer>HyperVHost.Domain.com</Computer> <Security UserID="S-1-5-83-1-1833644042-1265846729-79967367-3144908354" /> </System> <UserData> <VmlEventLog xmlns:auto-ns2="http://schemas.microsoft.com/win/2004/08/events" xmlns="http://www.microsoft.com/Windows/Virtualization/Events"> <VmName>VyOS</VmName> <VmId>6D4B300A-49C9-4B73-8734-C404427E73BB</VmId> </VmlEventLog> </UserData> </Event> This is an entry that gets made when the VM is booted fresh. There is no need to execute this code on this Event Log ID. Log Name: Microsoft-Windows-Hyper-V-Worker-Admin Source: Microsoft-Windows-Hyper-V-Worker Date: 4/9/2014 12:26:29 AM Event ID: 18500 Task Category: None Level: Information Keywords: User: NT VIRTUAL MACHINE\6D4B300A-49C9-4B73-8734-C404427E73BB Computer: HyperVHost.Domain.com Description: 'VyOS' started successfully. (Virtual machine ID 6D4B300A-49C9-4B73-8734-C404427E73BB) Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-Hyper-V-Worker" Guid="{51DDFA29-D5C8-4803-BE4B-2ECB715570FE}" /> <EventID>18500</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x8000000000000000</Keywords> <TimeCreated SystemTime="2014-04-09T04:26:29.919206200Z" /> <EventRecordID>565</EventRecordID> <Correlation ActivityID="{D18A9FB4-405F-000C-6DCF-B3D15F40CF01}" /> <Execution ProcessID="6496" ThreadID="4600" /> <Channel>Microsoft-Windows-Hyper-V-Worker-Admin</Channel> <Computer>HyperVHost.Domain.com</Computer> <Security UserID="S-1-5-83-1-1833644042-1265846729-79967367-3144908354" /> </System> <UserData> <VmlEventLog xmlns:auto-ns2="http://schemas.microsoft.com/win/2004/08/events" xmlns="http://www.microsoft.com/Windows/Virtualization/Events"> <VmName>VyOS</VmName> <VmId>6D4B300A-49C9-4B73-8734-C404427E73BB</VmId> </VmlEventLog> </UserData> </Event> #> $Rebooted_VMs = Get-VM | WHERE {$_.State -eq 'Running' -and $_.UpTime -lt ([TimeSpan]'00:00:10')}; ForEach ($VM in $Rebooted_VMs) { $vNICs = Get-VMNetworkAdapter -VMName $VM.Name; ForEach ($vNIC in $vNICs){ $VLAN_Properties = Get-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC; Switch ($VLAN_Properties.OperationMode) { ('Trunk') { Set-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC ` -Trunk ` -AllowedVlanIdList ($VLAN_Properties.AllowedVlanIdListString) ` -NativeVlanID ($VLAN_Properties.NativeVlanID) } ('Isolated') { Set-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC ` -Isolated ` -PrimaryVlanId ($VLAN_Properties.PrimaryVlanID) ` -SecondaryVlanID ($VLAN_Properties.SecondaryVlanID)} ('Promiscuous') { Set-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC ` -Isolated ` -PrimaryVlanId ($VLAN_Properties.PrimaryVlanID) ` -SecondaryVlanIDList ($VLAN_Properties.SecondaryVlanIDListString)} ('Access') { Set-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC ` -Access ` -VlanID $VLAN_Properties.AccessVlanID } ('Untagged') { Set-VMNetworkAdapterVLAN -VMNetworkAdapter $vNIC ` -Untagged } } } }
  29. Save the PowerShell code as ‘Scheduled_Task-Run_When_VM_Reboots.ps1’.
  30. Place the PowerShell script somewhere on the Hyper-V host’s local drives. On my server, I placed it in ‘E:\Hyper-V\Scripts’.
  31. Open Notepad on the Hyper-V server
  32. Copy this code and paste it into Notepad:<?xml version="1.0" encoding="UTF-16"?> <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2014-04-09T16:04:55.0777598</Date> <Author>The_Gecko</Author> <Description>A Hyper-V VM warm-cycled, not a full power cycle, but a reset or reboot. Execute these commands when that event happens.</Description> </RegistrationInfo> <Triggers> <EventTrigger> <Enabled>true</Enabled> <Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-Hyper-V-Worker-Admin"><Select Path="Microsoft-Windows-Hyper-V-Worker-Admin">*[System[Provider[@Name='Microsoft-Windows-Hyper-V-Worker'] and EventID=18512]]</Select></Query></QueryList></Subscription> </EventTrigger> <EventTrigger> <Enabled>true</Enabled> <Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-Hyper-V-Worker-Admin"><Select Path="Microsoft-Windows-Hyper-V-Worker-Admin">*[System[Provider[@Name='Microsoft-Windows-Hyper-V-Worker'] and EventID=18514]]</Select></Query></QueryList></Subscription> </EventTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>S-1-5-18</UserId> <RunLevel>HighestAvailable</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>Queue</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>true</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession> <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>PT1H</ExecutionTimeLimit> <Priority>7</Priority> </Settings> <Actions Context="Author"> <Exec> <Command>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe</Command> <Arguments>"E:\Hyper-V\Scripts\Scheduled_Task-Run_When_VM_Reboots.ps1"</Arguments> </Exec> </Actions> </Task>
  33. Down near the bottom of this code you will find a reference to “E:\Hyper-V\Scripts\Scheduled_Task-Run_When_VM_Reboots.ps1”. Edit this path to point to the location where you saved the PowerShell script created above.
  34. Save this file as “Commands Executed on a VM Warm-Cycle.xml”
  35. Start “Task Scheduler” on the Hyper-V host
  36. Go to Action --> Import Task
  37. Point it towards the XML file you just created.
  38. Done!

Time to test if it works:

  1. Create another VM
  2. Open the Hyper-V properties for the second VM
    [list]
  3. Make sure that second VM has a non-legacy vNIC
  4. Connect the second VM’s vNIC to the Internal-only Virtual Switch
  5. Enable virtual LAN Identification
  6. Set the VLAN to 30
    [/list]
  7. Log in to the second VM
  8. Assign the second VM’s vNIC an IP address of 192.168.30.2
  9. Ping the VyOS VM (192.168.30.1): “ping -t 192.168.30.1”
  10. Reboot the VyOS VM
  11. Watch the pings fail during the reboot cycle and begin to succeed again during the VyOS boot process

This process was developed on a Dell R710 server running Windows Server 2012 R2. Fortunately, what you see here will run on all flavors of Windows Server 2012 R2, including the free Hyper-V 2012 R2 Hypervisor.

If I have made any mistakes or was not clear about any particular step, please send me a PM with the problem (and with a correction if you can provide one) and I will correct this post. I strive for completeness and correctness.

Edited on 2014-04-11 10:20 AM EST - Fixed duplicate “eth0” commands. Added “exit” commands. Changed “system install” to “install system” and added notes about “install image” experiences.


#2

Did you really do it that way? Most of it doesn´t even work. Check syntax and the order of your steps. Good luck guys!

T (2+2) M - and it works :wink:


#3

Few things.
please don’t quote the whole howto, the original article is there for everyone to read :slight_smile:

“most of it doesn’t work”

Could you please cut & paste the error messages you got when you recreated this ?
That would be very helpful


#4

There is no need to recreate this, to see the mistakes.
Instead of just request error logs, read and review the content of the howto wich is full of mistakes and make it really difficult for other ones to find the error. Is the quallity of content not a goal of this forum?

So take a look at…

Just wrong, should be “install system” or even better “install image”
Also after that, a reboot into the new system is also a very good idea instead of changing the config of the live env.

[quote] edit interfaces ethernet eth0
set description ‘External_Network’
set address 192.168.1.10/24
set duplex auto
set speed auto
commit

edit interfaces ethernet eth0
set description 'VLAN_Trunk'
delete address
set duplex auto
set speed auto
commit[/quote]

What is that? some typo? kind of funny?

Anyway, I don´t want to be rude - but come on, this is not really helpful or professional.

Greetings


#5

If I got something wrong, I apologize. I will fix it.

I request that you Jason03 change your tone from mocking to helpful. VyOS is a brand new fork from Vyatta with a small number of followers. If you are devoted to seeing it succeed, then you need to encourage growth in the number of supporters and followers. To accomplish this you and everyone associated with the project needs to be open, welcoming, kind, and supportive.

You have had two opportunities to show that you care; two opportunities to encourage growth; two opportunities to foster a collaborative environment -and failed-. I invite you to step away from the air of superiority that Internet anonymity allows you and come back to us as the helpful, friendly person you are in real life. If you cannot do this then please unregistered yourself from this forum and I wish you a long, successful, and happy life.


#6

This is very usefully for me :slight_smile:


#7

Hi I have setup a similar network but i have a problem between the test VM and the router. They do not ping each other! but a pc outside the network can ping the ip of the router.

this is my config:

[code]vyos@vyos:~$ conf

[edit]
vyos@vyos# show int
ethernet eth0 {
address 192.168.1.150/21
description servers
duplex auto
hw-id 00:15:5d:01:26:0b
smp_affinity auto
speed auto
}
ethernet eth1 {
description VLAN_Trunk
duplex auto
hw-id 00:15:5d:01:26:0c
smp_affinity auto
speed auto
vif 20 {
address 192.168.16.254/22
}
vif 21 {
address 192.168.24.254/22
}
}
loopback lo {
}
[/code]


#8

Hi! This might be helpful.