Serial port settings of VirtualBox Virtual Machine in Ubuntu

Source: Internet
Author: User
There are two serial communication mechanisms for VirtualBox virtual machines: one is to connect the serial port of the virtual machine to the serial port of the host, and the other is to connect the serial port of the virtual machine to a named pipe on the host, the first method has not yet been put into practice. Currently, the method of naming the pipeline has been successfully put into practice. 1. after the serial port is enabled to create a virtual machine, the serial port panel appears in the settings. You can set the serial port. The default setting is unavailable. Generally, the port is/dev/ttyS0 corresponding to the Virtual Machine of COM1, in Port mode, select HostPipe

There are two serial communication mechanisms for VirtualBox virtual machines: one is to connect the serial port of the virtual machine to the serial port of the host, and the other is to connect the serial port of the virtual machine to a named pipe on the host, the first method has not yet been put into practice. Currently, the method of naming the pipeline has been successfully put into practice.

1. Enable serial port

After creating a virtual machine, the serial port panel will appear in the settings. You can set the serial port. The default setting is unavailable. Generally, the port is/dev/ttyS0 corresponding to the Virtual Machine of COM1, in Port mode, select Host Pipe to connect the serial port of the virtual machine to a named Pipe of the Host. When the channel is created, VirtualBox will create a named Pipe in the Host OS when the virtual machine is started, and connect it to the corresponding serial port of the virtual machine. When you select Host Pipe, the port path indicates the path of the named Pipe. On Windows, it is \\. in the form of \ pipe \ xxx, you can set any path in Linux, for example, set it to/tmp/vbox. Note: If the named pipe corresponding to the port path cannot be created, virtual machine startup will fail; the named pipe in the port path cannot be created again.

You can also use the command line to enable and create a connection from the virtual machine to the host named pipe, the following command connects the COM1 serial port of the Virtual Machine Ubuntu 8.10 Dev OS to the/tmp/vbox named pipe of the Host:

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/Config/IRQ" 4

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/Config/IOBase" 0x3f8

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/LUN #0/Driver" Char

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/LUN #0/AttachedDriver/Driver" NamedPipe

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/LUN #0/AttachedDriver/Config/Location" "/tmp/vbox"

VBoxManage setextradata "Ubuntu8.10DevOS" "VBoxInternal/Devices/serial/0/LUN #0/AttachedDriver/Config/IsServer" 1

2. serial communication between the VM and host HostOS

Start Ubuntu8.10DevOS, and a new vbox file will be created in the/tmp/directory of the host. You can use ls-l to see that it is a sock-type file for communication. Install minicom in HostOS, which can be used for serial port testing:

Sudo apt-get install minicom

Next we can configure minicom to point to/tmp/vbox and execute the command

Sudo gedit/etc/minicom/minirc. dfl and modify it

Pu port unix #/tmp/vbox

You can also modify it through serial port settings in minicom. Before testing, ensure that the baud rate set by the serial port in minicom is the same as that set by the serial port in the virtual machine. The serial port baud rate setting in the virtual machine can be referred to below. The baud rate setting of minicom can be changed directly after Ctrl + A and O in the program, or the configuration file can be modified.

Test process,

1) Start minicom in HostOS:

Sudo minicom

Run:

Echo is that OK? >/Dev/ttyS0

Displays the corresponding content in minicom of HostOS.

2) run:

Cat/dev/ttyS0

At this time, the input status will appear in The minicom on the host, and the entered information will also be displayed on the Virtual Machine terminal.

3. Serial Communication between virtual machines

Communication between two virtual machines can also be completed by using the host name pipeline. The principle can be simply described as follows: a virtual machine creates a named pipe in the host and connects its serial port. Another virtual machine also connects its serial port to the named pipe of the host, in this way, the serial ports of the two VMS can be connected. Both virtual machines use their respective COM1 ports. The host name pipe is the same pipe/tmp/vbox. During configuration, one channel is created (for example, Ubuntu8.10DevOS), and the other is not created. Start the virtual machine that creates the channel first, then start another virtual machine, open the terminal of the two virtual machines respectively, and set the input/output baud rate of the respective COM1 ports to 115200 through the following command

Stty ispeed 115200 ospeed 115200-F/dev/ttyS0

Test process:

Run

Cat/dev/ttyS0

Run

Echo OK>/dev/ttyS0

In this case, the Supervisor of Virtual Machine A will receive the OK message from B.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.