Configuring network settings when Ethernet adapters are not always present

Discussions related to using VirtualBox on Windows hosts.
Post Reply
Chris Hasler
Posts: 3
Joined: 8. Jun 2021, 13:16

Configuring network settings when Ethernet adapters are not always present

Post by Chris Hasler »

We are setting up a VM image to replace the piles of engineering laptops with a few external hard drives. This means that the VM is running on multiple physical hosts, and changing between people maybe 10-15 times a year.

If we configure the Ethernet adapter for the docking station and you start the VM without it, the VM "crashes". The same applies if we use a USB Ethernet adapter, or if people have different adapters.

Is there any way to configure the settings so that the VM will be able to start even if the expected Ethernet adapters are not present?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Configuring network settings when Ethernet adapters are not always present

Post by mpack »

The VM crashes? I must say I rather doubt that. Do you actually mean that it gives you an error message? A crash is an unintended abort, there is nothing unintended about this error message.

Anyway, no I'm afraid that VirtualBox has no automated system for switching bridged mode configs when you change hosts. It has been requested before of course, but no news as yet.

Do you have to use bridged mode? Why not NAT? NAT uses the host internet whatever it is, so would not care about NIC name changes.

Otherwise you'd have to create some kind of script to reconfig the VM every time you change to a host.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Configuring network settings when Ethernet adapters are not always present

Post by scottgus1 »

As Mpack says, a combination of NAT (for internet) & Host-Only (for host-VM comms) serve as a good work-around for not using Bridged. See Virtualbox Networks: In Pictures

Vboxmanage commands and 'ipconfig /all' outputs can be used in a self-rolled script to query available ethernet adapters and attach one to a Bridged adapter. Or a manually-made ini file on each laptop with the appropriate network adapter for vboxmanage to Bridge to. Use the script to start the VM by reading the ini file, vboxmanage to Bridge the VM, then start the VM.

Another idea: rethink the paradigm. Instead of moving the VM around to different laptops, give each laptop a copy of the VM with the Bridged adapter tuned appropriately and use a synchronizing scheme to update the data etc that the appropriate VM will use.
Chris Hasler
Posts: 3
Joined: 8. Jun 2021, 13:16

Re: Configuring network settings when Ethernet adapters are not always present

Post by Chris Hasler »

This does make things harder. We can't really change the issue of moving VMs around, as they require some very expensive licences for software which are used occasionally. It basically costs too much to give everyone their own VM.


NAT will have issues as the engineering laptop needs to use its own IP address to talk to the equipment its working with, and the equipment will dump the connection if its running over NAT. Having the techs change the IP addresses on their laptops doesn't really work as local admin is restricted by company policy, and if they don't use the admin account it gets disabled. This is why its always been a pile of engineering laptops, and now VMs.

I guess the script is going to be the solution here.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Configuring network settings when Ethernet adapters are not always present

Post by scottgus1 »

Licensing definitely deep-sixes the idea to let everyone have a VM, yes.

The script sounds like the correct way to go for distributed VMs.

(One other alternative? run the VMs on a central office server and have the laptops remote in)
Chris Hasler
Posts: 3
Joined: 8. Jun 2021, 13:16

Re: Configuring network settings when Ethernet adapters are not always present

Post by Chris Hasler »

This one is getting fun.

I can manually set up a batch file which dumps settings into the VM, which is so far so good. This doesn't improve things from using the GUI to do the changes, but it does make adding the VM to a laptop easier, as I can set the don't turn the HDD off settings so the VM isn't broken every 20 minutes.

The bit I am stuck on is how to write the batch file to get the Ethernet adapter in a form that can be entered as a variable to the VM.

I also looked at doing the RAM dynamically, but batch files and math do not go together well.

Any ideas on how this is done or if there is an easier alternative to the batch files?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Configuring network settings when Ethernet adapters are not always present

Post by scottgus1 »

I would approach this using a manually-made INI file set up for each host laptop, stored in a folder Virtualbox can normally access, like the root folder the VM is stored in, or another Appdata folder that the account can access.

Here's how I would set up the iNI file:
1. Register any VM on the host, even a new empty scrap VM, all you have to do is Bridge it to the desired host Ethernet adapter.
2. Right-click the VM and choose Show in Explorer.
3. Open the VM's .vbox file and look for the Network XML:
<Network>
<Adapter slot="0" enabled="true" MACAddress="0800274BB03A" cable="true" type="82540EM">
<DisabledModes>
<InternalNetwork name="intnet"/>
<NATNetwork name="NatNetwork"/>
</DisabledModes>
<BridgedInterface name="The Chosen Ethernet Controller Name"/>
</Adapter>
</Network>
4. Copy only the text between quotes on the BridgedInterface line (marked in Red above).
5. Paste the text into a Notepad document, save in the desired path.
6. Delete the scrap VM if you made one.
Do this for each laptop you plan to swap VMs on.

Here could be a starting point for the batch file:
set /p ethadapter=<driveletter:\path\to\BridgedAdapterName.text
vboxmanage modifyvm "vm name" --bridgeadapter# "%ethadapter%"
# in --bridgeadapter# should be (adapter slot number in the XML +1). Adapter slots start counting at 0, but the vboxmanage command starts counting at 1.

Proper manipulation of double quotes may require some experimentation.

Once the VM is Bridged to the desired adapter, it should remain that way, so the batch file should not be needed after it is used the first time. You could train the users to run the batch file as a first step after copying and registering the VM but before starting the VM. Then they can start the VM using normal methods thereafter.

Re RAM, I'd just go with the minimum necessary for good VM operation, and not bother trying to adjust to each host. Or add another INI file for RAM settings.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Configuring network settings when Ethernet adapters are not always present

Post by mpack »

If I was you I would just return to Scott's suggestion:

Create the VM and then copy the entire VM to every PC (use folder copy, not export/import).

If you are concerned about licensing or need the disk space then feel free to delete the VDI from the VM folder. Everything other than disk contents is preserved, including the choice of host NIC.

To use a VM just copy the correct VDI into the VM folder on the target laptop. If the VDI has the same UUID as before (i.e. you haven't switched VDIs on it), then the VM should be happy to boot.
Post Reply