Port mode options and communication techniques in VirtualBox
Multiple choices are available when selecting the port mode which affects the virtual port’s connection. Your choices are:
- Disconnected — The guest OS recognizes the device but treats it as if it is not connected to the port.
- Host Device — This option links the virtual serial port to the host computer’s physical serial port. Paths reflect the format of the host OS. For example, /dev/ttyS0 is used for Linux and COM1 for Windows systems.
- Host Pipe — This option creates a named pipe on Windows systems or employs a local domain socket on Mac, Linux, or Oracle Solaris. This is the preferred setup for creating pipe connections from software to the host OS.
- Raw File — This mode saves the output of the virtual serial port to a file where it can be used to gather diagnostic data from the guest operating system.
- TCP Socket — Using this mode establishes VirtualBox serial port passthrough and allows the serial data to be forwarded over TCP/IP networks. VMs can act as either a server or a client.
When multiple virtual serial ports are created, interrupt sharing should not be implemented if the ports use the same interrupt level to avoid communication conflict.
Users can establish communication between virtual machines with a null-modem connection. One of the VMs is configured as a pipe or socket that the second VM uses to connect to the first machine.
The TCP socket mode supports the creation of external connections to a guest machine’s serial port over TCP. VirtualBox supports both TCP server mode which is accessible with tools like telnet, and TCP client mode, suitable for virtual null-modem cables.
A knowledge of VirtualBox serial ports provides developers and system programmers with a valuable tool to extend the functionality of their VMs. The ports can be used for device sharing, kernel debugging, or establishing network bridges without requiring physical serial interfaces.
Native VirtualBox Serial Port Setup
VirtualBox provide guest machines with support for virtual serial ports. When the port is enabled, a standard UART-compatible device is furnished to the guest machine’s operating system so data can be sent and received. Based on the host OS, there may be different setup and configuration procedures.
Virtual machines can be configured with up to four virtual serial ports. Users have control over parameters such as Port Number and Mode.
How to Set Up Serial Ports in Oracle VM VirtualBox
Creating Oracle VM VirtualBox serial ports can be valuable in multiple scenarios. This capability can streamline kernel debugging and allow you to connect to serial devices from your virtual machine. Following is a simple guide to configuring and utilizing COM ports in VirtualBox.
Step 1: Access the settings
You can access the VirtualBox setting in two ways.
- In the VirtualBox GUI, navigate to the Serial Ports tab.
- Use the command line and enter the VBoxManage modifyvm command. Section 7.8 of the VirtualBox user manual provides detailed information about this command.
Step 2: Configure the serial ports
- Up to four serial ports can be configured in VirtualBox for each virtual machine.
A. Port Numbers must be assigned to each of the virtual ports. You need to assign port numbers with specific IO bases and IRQs. For example:
COM1: I/O base 0x3F8, IRQ 4
COM2: I/O base 0x2F8, IRQ 3
COM3: I/O base 0x3E8, IRQ 4
COM4: I/O base 0x2E8, IRQ 3
NOTE:
Custom I/O bases and IRQs can be specified if necessary to address particular usage scenarios.
B. Port Mode determines how the virtual serial port connects to the host machine or other VMs. The possible values are:
Disconnected — the port acts as if it is unplugged.
Host Device — links the virtual port to a physical serial port on the host computer.
- Host Pipe varies based on operating system.
Windows systems use a named pipe such as \\.\pipe\name.
Linux and macOS systems will use a local domain socket in /tmp.
- Raw File — selecting this option writes the serial data from the virtual ports to a file on the host machine.
- TCP Socket determines how the virtual port will be used.
TCP Server — enables remote clients to connect to the interface over the network.
TCP Client — configures the port to connect to another network-attached server.
Step 3: Implement the configuration
Each port can be configured according to your requirements through VBoxManage command or the VirtualBox GUI. Following are examples of setting up the port as a server or client.
- To set COM1 as a TCP Server, enter this command:
VBoxManage modifyvm «VM name» —uart1 0x3F8 4 —uartmode1 tcpserver 2023
- To connect COM2 on a client to COM1 on a Windows host, use this command:
VBoxManage modifyvm «VM name» —uart2 0x2F8 3 —uartmode2 hostdevice «\\.\COM1»
Step 4: Verify the setup
Launch your virtual machine to verify the ports are configured correctly and that they are recognized by the operating system.
Last updated May 15, 2024
VirtualBox COM Port Passthrough: Definitive Guide
Nowadays there isn’t as much use for COM ports as it once was. And yet, they still can find their practical application and do you a great deal of good.
For example, you’ve got to have at least one serial port or you won’t be able to interact with the vast majority of the kernel debugging tools. In actual practice, it doesn’t have to be a physical COM-port. With the right software tool, you might as well do kernel debugging through a virtual serial port on a virtual machine.
This tutorial will show you how to redirect a serial port from the host to a guest VM in VirtualBox and how to create virtual serial ports in VirtualBox.
Access serial ports in VirtualBox
A very easy method of implementing VirtualBox serial port passthrough is with the software tool FlexiHub.
FlexiHub offers users a simple path to enable serial ports in VirtualBox or any other virtualization platform by redirecting serial port devices to guest virtual machines over the network.
FlexiHub works by creating virtual connections and redirecting serial port data over a network to the VirtualBox virtual machines. There are no complex parameters to configure. With FlexiHub, you can add a VirtualBox serial port with just one click.
How to share COM ports to VirtualBox
-
2.
Install FlexiHub on the VirtualBox host with a physical serial port that will be redirected. After that, install FlexiHub on the VirtualBox virtual machine that will connect to the host’s serial port.
-
3.
Launch the app both on the host and guest VM and log into your account.
-
4.
The serial devices that are available for connection will be displayed in the FlexiHub’s interface.
-
5.
On the guest machine, click ‘Connect’ in the app’s interface to access a serial port in VirtualBox.
From this point on, serial devices connected to the VirtualBox serial ports will be redirected to the virtual environment without any extra configuration.
For the video instructions on how to share serial ports to VirtualBox, you can check out this brief guide:
How to Set Up Serial Ports in Oracle VM VirtualBox
Setting up serial ports in Oracle VM VirtualBox can be a handy feature, especially for specific tasks like kernel debugging or when you need to connect devices that traditionally used serial connections. Here’s a straightforward guide to help you configure and use virtual serial ports in VirtualBox.
-
1.
Step 1: Accessing the Settings
Via VirtualBox GUI: Go to the settings of your virtual machine. Look for the «Serial Ports» tab.
Via Command Line: Use the `VBoxManage modifyvm` command. Detailed usage can be found in the VirtualBox manual under Section 7.8, “VBoxManage modifyvm”.
-
2.
Step 2: Configuring Your Serial Ports
You can configure up to four serial ports for each virtual machine.
1. Port Number: Assign a port number (COM1, COM2, COM3, COM4) with specific I/O bases and IRQs:
- COM1: I/O base 0x3F8, IRQ 4
- COM2: I/O base 0x2F8, IRQ 3
- COM3: I/O base 0x3E8, IRQ 4
- COM4: I/O base 0x2E8, IRQ 3
- You can also specify custom I/O bases and IRQs if needed.
2. Port Mode: Decide how the virtual serial port will connect to the host or other VMs:
- Disconnected: Acts like it’s unplugged.
- Host Device: Links the VM’s port to a physical serial port on your host machine.
- Host Pipe:
— For Windows: Uses a named pipe (e.g., `\\.\pipe\name`).
— For macOS/Linux: Uses a local domain socket (usually in `/tmp`). - Raw File: Outputs the serial data to a file on your host.
- TCP Socket:
— TCP Server: Allows remote connections to this port over the network.
— TCP Client: Connects to another server over the network.
-
3.
Step 3: Implementing the Configuration
- Set up each port according to your requirements using either the GUI or the VBoxManage commands. For example:
- To set COM1 as a TCP Server, use:
VBoxManage modifyvm "VM name" --uart1 0x3F8 4 --uartmode1 tcpserver 2023
- To connect COM2 to a host device on a Windows host:
VBoxManage modifyvm "VM name" --uart2 0x2F8 3 --uartmode2 hostdevice "\\.\COM1"
-
4.
Step 4: Verifying the Setup
- Start your virtual machine and check the device manager or equivalent to verify that the serial ports are recognized and configured correctly.
Additional Tips
✦ Remember that serial ports configured to use the same IRQ must not be used simultaneously due to sharing issues.
✦ For advanced setups like kernel debugging or simulating a null-modem connection between VMs, refer to specific configurations relevant to your use case.
This guide should help you effectively utilize virtual serial ports in VirtualBox, enhancing your VM’s connectivity for development, debugging, or legacy device interactions.
Because the description in the help and manual is very poor and others have had similar problems, I decided to write this guide after lots of trials.
Original it was posted in the Windows Hosts section for XP guest, but has now added Windows 7 settings.
How to add a physical serial port.
In Guest Settings for Serial Ports set as follow
Port1: Checked
Port Number: COM1
Port Mode: Host Device
Windows Host:
Port/File Path: COM1:
Note the colon in COM1: (not semicolon). I have experienced the guest could become unstable without it.
For a host port number higher than 9, the naming \\.\comX where X is the port number, is required. This can also be used for a one digit port number.
Linux Host:
Port/File Path: /dev/ttyS1
For other COM port than 1 replace the digit with port number.
Also remember the IRQ and I/O Port settings.
If the guest needs to see another port than COM1, change the Port Number to the requested port.
If using a user defined IRQ for the guest, IO APIC may have to be enabled.
Save the settings and start the guest.
Open the Device Manager in the guest and go to the Ports (COM & LPT) section.
If you see a COM3 port with a yellow warning icon skip the following sections.
XP:
Open Add Hardware from the Control Panel.
After searching for hardware select ‘Yes, I have already connected the hardware’ and Next.
Go to the bottom and select ‘Add a new hardware device’
Select ‘Install the hardware that I manually select from a list’
Select ‘Ports (COM & LPT)’
Select ‘Communication Port’ from Standard port types.
Continue with Next until finished.
WIN7:
From the Action menu select Add legacy hardware.
Select Next, ‘Install the hardware that I manually select from a list’ and Next
Select ‘Ports (COM & LPT)’ and Next
Select ‘Communication Port’ from Standard port types.
Continue with Next and Finish.
In the Device Manager you should now see the COM3 port with a yellow warning icon.
Open Properties for the COM3 port.
Select Advanced from Port Settings.
Choose COM1 from the ‘COM Port Number’ (Ignore possible ‘In Use’)
In the Resources tab select ‘Set Configuration Manually’ if you see it.
In Windows 7 uncheck ‘Use automatic settings’
Select the configuration that corresponds to the VirtualBox settings as noted – likely configuration 0000.
Close the box and you should be asked to reboot.
After reboot the COM1 port should now be working.
How to add an USB serial port.
Important: Depending on version ‘VirtualBox Extension Pack’ must be installed to use an USB serial adapter.
You have the choice of installing the device USB driver on the host or cancel this installation, but the VirtualBox’s host routing must be installed when the device is accessed for the first time in the guest.
In guest Settings for USB set as follow
Enable USB Controller: Checked
Enable USB 2.0: Checked
Add the driver (e.g. FTDI USB <-> Serial)
Save the settings and start the guest.
From the menu or status bar of VirtualBox frame check the Serial Port in the USB section.
Install the USB driver in the guest — I have found it is a good idea to restart the guest after the host routing is done and before the driver installation. If still a problem with the USB initializing the following procedure usually will do the job link.
In the guest the port number can be changed in the Device Manager, as well as settings for buffers, timers, etc.
- Make sure your serial port is enabled in BIOS.
- Make sure your serial port is found in the host operating system. For that, type:
setserial -g /dev/ttyS0
If the output says “unknown”, your port is not accessible by the host OS. This happens for example when disconnecting power from the docking station on a ThinkPad T61 using Ubuntu 10.10, because the serial port is only available on the docking station and is assumed “disconnected” when switching to battery operation, even though the dock is still physically connected. Re-connecting power to the docking station does not help here, but restarting does. - Configure your VirtualBox virtual machine to have a serial port. For that, use the following settings in the configuration dialog for your VM:
- serial port: enable
- port number: COM1
- IRQ and port settings: ignore, use the defaults
- Port Mode: Host Device
- Port Path: /dev/ttyS0
- Start the Windows XP guest OS and add the COM port to Windows XP:
- Go to “Start -> Control Panel”
- Double click the “Hardware” item (“Add New Hardware Wizard”)
- Click “Next”
- Choose “Yes, I have already connected the device”
- Click “Next”
- Choose the last list item “Add new hardware device”
- Click “Next”
- Click “Search for and install the hardware automatically”
- Click “Next”, it will search and find the new COM port.
Note that when trying to start VirtualBox without the serial port being available to the host device, VirtualBox will refuse to start with a variety of error messages.