As an Embedded Software Engineer serial port access is very critical requirement for me irrespective off which OS I am using and how I am using it (I mean with or without virtualization).
I have Windows XP as primary Operating System, however, I need to work on Linux for lot of hobby projects. I hate to manage two computers for two reasons first is it makes workplace really messy with extra wires and Second is I always need some space to keep items like Power Supplies, Oscilloscopes, Programmers, Debuggers etc. which are unavoidable.
So I installed Kubuntu as Guest OS on my Windows Host and I wanted to access the host serial port for debugging purposes. Virtual Box does provide this feature and its quite easy to configure as well. The problem is, it can be done in more then one way and that’s where user might get confused that’s why I am writing this post. Before jumping into action we will just find little more information about serial ports
How Serial Ports are Named:
In windows like operating systems serial ports are named like COM1, COM2 and so on while in Linux they are named like /dev/ttyS0, /dev/ttyS1 and so on. As my example involves both operating systems it might create some confusion, as a rule of thumb what will call COM1 in windows will be /dev/ttyS0, COM2 will be /dev/ttyS1 and so on. Even though the names are different they refer to the same Interrupt and IO ports and that’s how we map these names.
|Name Under Windows||Name Under Linux||IO Address||Interrupt Request (IRQ)|
Setup & Requirement:
My computer has four serial port COM1, COM2, COM3 & COM4 . My requirement is very simple I want to access COM3 in my Kubuntu guest installed under Virtual Box Virtual Machine. (We could have taken COM1 itself but that will be little bit confusing so we will stick to COM3 first, once we know how to do it we can access any port in similar manner).
The next step is to configure virtual box to connect virtual serial port in guest OS to physical serial port on host. This is pretty easy if you know what to IGNORE on the serial port configuration dialog of Virtual Box. Lets get started with the configuration now, Open the serial port configuration dialog box for the virtual machine of interest, by default Port0 Tab will be visible. For our purpose IGNORE IRQ, IO PORT and Create Pipe fields.
- On Port0 Tab select Enable Serial Port check box (you will not be able to change any other setting till you check this one).
- Port Number : This field refers to port number under guest OS, we want to map it to COM1 (/dev/ttyS0) so select COM1 (remember it has nothing to do with physical ports)
- Port Mode: We want to connect virtual device to physical device on host so set it to “Host Device”
- Port Path: For “Host Device” port mode this field refers to physical device port number on host, we want to connect to COM3 on host so enter COM3 here.
Check out the screen shot below for Virtual Box Configuration.
That’s it just set these 3 fields to correct values and you are done.
Now lets check if it really works or not, as I said my virtual machine runs Kubuntu so the serial port COM1 (Technically the port with IRQ= 4 and I/O Port = 0x3f8) will be mapped to /dev/ttyS0.
Verification Under Guest OS:
To verify the serial port operation under guest OS we need some Kind of Serial Port terminal for gust OS. As our guest OS is Kubuntu I have used Cutecom. Now the actual verification can be done in two ways.
- Short Pin 2 and 3 of the physical serial port, this will short the Rx and Tx pins of the serial port and whatever you send through terminal will echoed back to the terminal.
- Connect any RS-232 device to serial port and verify it with the device specific commands or application.
I will choose the first method because it will work for everyone, so short RX and Tx pins for your physical serial port and configure Cutecom to set the device to /dev/ttyS0, make other settings as per screen shot below.
See it in action below:
- In order to map COM1 to /dev/ttyS0 we need to set both Port Number and Port Path fields to COM1 in Virtual Box serial port settings.
- Even though I have tested it on Kubuntu it should work on any Linux destro.
- If your guest OS is Windows you can use the Hyper Terminal program and port name given in Port Number field of Virtual Box serial port settings.
- Please note that the selected physical port can not be accessed by the Host when the Virtual Machine using that port is running.
Links Related to This Post:
Thank you, for good information.
My Tips Computer Site :
Thanks MCom, I am glad to hear that it was useful for you.
I have Installed Virtual Box 3.1.6 on my system. The host is running on SuSe 11.2 and I have installed the SuSe 11.2 as guest OS on the VBox. I have a another system in which I installed Win XP. How to make serial port connection between the VBox and Win XP system.
Thanks in advance.
Thanx for the awesome info, it was very helpful.
I have a problem though. The the RTS aand DTR signals are permanently set.
I need to to use full hardware handshake so this is a real problem for me.
Can you help?
Great man! Thanks. I’m using Xubuntu on Virtualbox and I also need serial port. This helped me alot!.
Thanks wakaranai, I am happy that you find the port helpful.
Thanks a LOT for this!!! I have been baning my head against the wall (litteraly!) for a few hours. I thought that port path should be /dev/ttyS0…
Im running debian under windows xp and when I put COM1 on BOTH port number and path everything just works…
You are most welcome Jed, Thanks for dropping by.
Hi. On my config (xp host, xp guest, vbox 2.04) it doesn’t seem to work, but I’ve figured that adding manually the com port on the guest works ok.
On the vbox I set:
Port Number: COM1 (standard i/o and addr, it’s a physical rs232)
Port Path: COM1
On the guest I add the “communication port” manually (via control panel, add hardware wizard) and the xp guest sees it as the COM3.
Odd but works 🙂
Thanks for the Information pollo, that would be handy for the readers.
I don’t have setup with both XP host and XP Guest, will try that out soon.
in mine it say’s
NamedPipe#0 failed to bind to local socket /dev/ttyS0.
VBox status code: -448 (VERR_NET_ADDRESS_IN_USE).
some times it say’s
Ioctl failed for serial host device ‘/dev/ttyS3’ (VERR_DEV_IO_ERROR). The device will not work properly.
Unfortunately I don’t know the reason for the error you are getting? how about trying on Virtual Box Support Forum?
thank you so much ! but i want to ask how to do the inverse
i mean i have a VirtualBox installed in windows and i want to use with serial port for fedora in the virtual box ?
thanks for your time .
Excellent write up, thank you. I used this to enable a serial port with Ubuntu 8.04 as the host OS and WinXP as the guest OS. Here is my VM serial port configuration:
Port Number: COM1 (IRQ 4, I/O Port 0x3F8)
Port Mode: Host Device
Port Path: /dev/ttyS0
The only other thing I had to do was add my user account to the Ubuntu “tty” system group so that VirtualBox had permission to access the port. Before I did this, the VM would crash when I tried to start it because it could not access the hardware directly.
@ Roland : Thanks for the complement and your setup information.
@ Mourad: I guess Roland has got a solution for you.
I read your blog for quite a long time and should tell you that your articles always prove to be of a high value and quality for readers.
@ How to Get Six Pack Fast
Thanks for the appreciation, it’s my goal to cover all aspects of the problem in hand in my posts.
“The only other thing I had to do was add my user account to the Ubuntu “tty” system group so that VirtualBox had permission to access the port.”
Hi, how exactly can I do this? I’m looking but haven’t found anything.
Thanks a lot for this. I was wondering what the correct Path to the COM-Port on the XP-Host woulb be, but I couldn’t believe it would be that simple. By the way, it didn’t work with COM15 (a virtual COM-Port for a USB-Serial-Adapter). So I had to change COM15 to COM1. But now it works flawlessly under openSUSE, although there is no driver available for Linux.
@Peter: Yes it is very easy but there is lot to confuse you and that’s the reason I thought this will be good information to share. Thanks for the visit.
I’m trying to do exactly what Peter did. Thanks for all the info!
BTW “How to Get Six Pack Fast” is SPAM!
You are most welcome Chris, about “How to get six Pack Fast” i should have guessed from his name :). Thanks for your visit.
Any idea on doing the reverse of this? i.e. boot up to Ubuntu Linux and access WinXP via Virtual Box. I tried a few different configurations but didn’t get anywhere. Thanks in advance.
@Roland would like to know how you got the tty permissions.
Just sharing some info on what I did to get serial ports working in my Fedora Core 12 (fc12) host machine with Windows XP Guest:
Here is the short answer:
I used the following settings in Virtualbox (version 3.0.10_OSE) :
Port Number: COM1
I/O Port: 0x3F8
Port Mode: Host Device
Port/File Path: /dev/ttyS0
I also needed to add the user (my login) to the ‘dialout’ Group.
This info may be helpful for other users troubleshooting Virtualbox Serial Port problems (the long version).
Firstly you can check that Linux has loaded your serial port driver with the command:
# dmesg | grep ttyS0
You should see something like this returned:
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
00:02: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
Next you can check who has permissions to access /dev/ttyS0 with the command:
# ls -l /dev/ttyS0
You should see something like this returned:
crw-rw—-. 1 root dialout 4, 64 2009-12-02 23:25 /dev/ttyS
We can see that ‘root’ and the group ‘dialout’ have permissions to access /dev/tty0
You will want to give the Virtualbox user (the user you login as) permissions to access /dev/ttyS0 so add the user to the ‘dialout’group by:
a) Click, System –> Administration –> Users and Groups
b) Enter the root password
c) As an optional setep you disable ‘Hide System Users and Groups’ in the Preferences tab. Now you can see all system users and groups.
d) Double click the user and under the ‘Groups’ TAB tick ‘dialout’ (or what ever group your ls -l /dev/ttyS0′ returns as having permission to access it)
e) Log-out and log back into Fedora.
If you don’t have permission to access the dev/ttyS0 resource you will see the following error in Virtualbox:
Failed to start the virtual machine MACHINE_NAME_HERE
Cannot open host device /’dev/ttyS0′ for read/write access. Check the permissions of that device. (‘/bin/ls -l /dev/ttyS0’):……
As an additional note I could not use ‘COM1’ in the ‘Port/File Path:’ setting in virtualbox but /dev/ttyS0 works. The following error is produced with COM1 set:
Failed to start the virtual machine MACHINE_NAME_HERE
Failed to open the host device ‘COM1’ (VER_FILE_NOT_FOUND).
Unknown error creating VM (VERR_FILE_NOT_FOUND).
Hope this helps someone as it has helped me.
@ themattski: Thanks a lot for providing detailed information. I am sure it will help someone.
Thanks for dropping by.
And thank you for your guide above mate! It was most helpful in allowing me to arrive at a solution that worked in my set-up.
Following the above I also needed to add the serial port to Windows XP – my Guest OS:
Start –> Settings –> Control Panel –> Add Hardware
Next –> Yes I have already… –> (scroll to bottom) Add new hardware device –> Next –> Search and Install the Hardware.
You should now see the com port.
Damn thanks! I was really doing the wrong things, thanks for the info! Im need it for the same reasons as you 🙂
You are most welcome. Great to hear the comment from fellow programmer 🙂
Great article, thank you.
I was suffering with the native USB serial access which worked “occasionally”.
This article (and sorting permissions on /dev/ttyS0) finally helped me to get it working consistently.
Pingback: Serial Hardware connect - openSUSE Forums
Pingback: Serial Port Config B/W VBox and external system
Great help, thanks!
Just a short input. I am using a USB-serial converter which shows me a serial port (WindowsXP host Ubuntu GuestOS) so I connected the port exactly the same way you did. Without success.
I had to use /dev/ttyUSB0 as a Device in CuteCom. That may helps someone having the same problem.
Thanks for the information Dave, it will certainly help as I can see that many new laptop these days do not have in-built RS-232 ports.
In this case, did you change port number in serial settings of virtual box or it is still COM1?
Extremely Nice post! Very valuable and useful.
Here is my problem:
1. Trying to use WinFax on XP guest with OpenSuse host, and Version 3.2.4 Virtualbox.
2. But from guest XP, keep getting error msg, TAPI modem in use.
Is it actually possible to use WinFax Pro on Virtualbox with Opensuse host? Or any other fax program?
This Virtualbox user would be more than grateful!
Again, Tks so much.
Hi! Great response, and very easy to understand.
I have a question, though. What version of Virtual Box do I need to install in order to be able to access USB devices? I noticed that yours has the USB option; mine does not.
@josephine: Thanks for dropping by. Please note that open source edition of virtual box does not have USB support.
I’m running Ubuntu as Guest on Windows 7 Host. I can’t make “Port/File Path” as “/dev/ttyS2” (Port mode as “Host Device”). the following error appears:
failed to open host device \dev\ttyS2 VERR_PATH_NOT_FOUND
For a Windows 7 Host, try “COM3” for the “Port/File Path” instead of “/dev/ttyS2”
thankx alot for your help material
Hey thanks M8!!! Your instructions did the trick. A bit counter-intuitive and backwards, but you made it make sense!
Pingback: 2010 in review « Software, Tools, Tips, Tricks
Thanks for the detailed instructions. I have Windows 7 as host and Ubuntu 10.04 as guest. However I added the serial port to my virtual box after I had installed the Virtualbox guest additions on my guest system, so I couldn’t get the serial to work. Once I installed the guest additions again, it started working.
Guest additions don’t do anything with serial ports. I tried it anyway. Does not work.
I have WinXP as guest and Win7 as host – serial port doesn’t work. 😦
Pingback: redirecting serial port to VirtualBox by lan
Pingback: Delicious Bookmarks for February 26th from 15:41 to 22:01 « Lâmôlabs
Very nice port. Thank you A LOT.
Thank u for valuable info.
could you explain tha whole setting of virtualbox for all operating system?
thank u again
@ Aisha, Thanks for dropping by.
Yes, it is long pending plan… thanks for the reminder I will work on it soon.
Pingback: Is there a VM to map a legacy app’s serial resources onto modern hardware? Drija
Great job! This article help me a lot! Thank you!
The article is very nice. I can’t use the method for the com port that you explain with a XP virtual machine on a Windows 7 Host machine. Can you help me? I manage in the right way the serial com port in windows 7, but I can’t use it inside the XP virtual machine. I use exactly your method in the virtual box configuration.
Unfortunately, it does not work.
I send serial data on my other computer and the Linux guest does not receive it. The host does receive it though.
Pingback: Virtualbox Serial Port Step-by-Step
Thanks, worked !!!
Thanks. Worked perfectly on my Ubuntu guest using Windows 7 as host.
i’m using Ubuntu as my guest os and windows 8 as my host with addition of using usb to serial adapter for physical com port. the VM virtualbox is running but the terminal isn’t working.
Thanks very much for the info!
i go through with your above process but when i starting machine, its taking .iso image but after few second its shows
Map file : WRITE PROTECT
please help me out…?
Hi After installing Juniper Olive on Virtual box I cant see the interfaces that I need to use. I have chosen two interfaces on virtual box and one is microsoft loopback interface that directly connects to the host windows and the other is vittual box interface..But cant see none of the interfaces after the juniper successful installation. I am copying the ifconfig from the freebsd.
lsi: encaps: (null); framing: pseudo
dsc: encaps: (null); framing: pseudo
lo0: encaps: loopback; framing: local
inet mtu 4294967295 local=127.0.0.1
inet mtu 4294967295 local=126.96.36.199
inet6 mtu 4294967295 local=fe80::200:ff:fe00:0
gre: encaps: (null); framing:
ipip: encaps: (null); framing:
tap: encaps: other; framing: pseudo
pime: encaps: (null); framing:
pimd: encaps: (null); framing:
mtun: encaps: (null); framing:
demux0: encaps: (null); framing: pseudo
cbp0: encaps: ether; framing: ether
curr media: i802 0:5:86:71:80:11
pip0: encaps: ether; framing: ether
curr media: i802 0:5:86:71:83:e0
pp0: encaps: (null); framing:
irb: encaps: ether; framing: ether
curr media: i802 0:5:86:71:84:20
Pingback: Is there a VM to map a legacy app's serial resources onto modern hardware? - Just just easy answers
Pingback: WINDOWS - Virtualbox getting serial port to work | kossboss
Hi, someone tryied succesfully connect serial port with gest windows 7 and host windows 98?
i am using windows xp guest os on rhel5. i am unable to use the printer attached to host machine from the guest os. please helpme
thanks a ton for this helpful topic
Thanks a lot. The configuration of virtual machine was very helpful to me. I spent a lot of time in figuring out what was going wrong in my serial communication code. It ended up to be a problem with the virtualBox configuration
Hello! That is awesome! Does it work with MBN too?
Unquestionably believe that which you said. Your favourite justification appeared to be on the internet the easiest thing to
take into account of. I say to you, I certainly get annoyed whilst other folks consider issues that they just do not know
about. You controlled to hit the nail upon the highest and also outlined out the entire thing with no need side-effects , folks can take a signal.
Will probably be back to get more. Thank you
Setup & Requirement:
My computer has four serial port COM1, COM2, COM3 & COM4 . My requirement is very simple I want to access COM3 in my Kubuntu guest installed under Virtual Box Virtual Machine. (We could have taken COM1 itself but that will be little bit confusing so we will stick to COM3 first, once we know how to do it we can access any port in similar manner).”
Port Number : This field refers to port number under guest OS, we want to map it to COM1 (/dev/ttyS0) so select COM1 (remember it has nothing to do with physical ports)
Port Mode: We want to connect virtual device to physical device on host so set it to “Host Device”
Port Path: For “Host Device” port mode this field refers to physical device port number on host, we want to connect to COM3 on host so enter COM3 here.
You said you wanted to use COM3 on the GUEST and then you go and use COM1 on the GUEST and COM3 on the HOST.
What I mean is the COM1 port inside the guest and COM3 port inside the host refers to the same physical port.
Pingback: Quite A Box Of Tricks Serial Number | blazes
that’s good, thanks for sharing,.. I think this is great blog
The screens in VirtualBox have changed a little, for instance you can’t name the come port, but otherwise this was very helpful!
This is awesome. I like to use the greatest 6×9 speakers and subwoofers I can for my vehicle. You get really good seem top quality when you blend both of these types and place them in your auto. Even far better when you use a speaker enclosure.
Many thanks for the post!
Having read this I thought it was rather informative. I appreciate you taking the time
and effort to put this informative article together.
I once again find myself spending a lot of time both reading and leaving comments.
But so what, it was still worthwhile!
The software will help to access serial in virtual machine.http://www.eltima.com/com-port-in-virtual-machine/
The process couldn’t be more simple than this)
Hi, thank you for the details.
I tried this on my PC. I used Win8.1 and VBox with both Ubuntu and Debian.
I can see the port in Debian after I connected my device to my PC and the first thing is:
If I do not connect the device I can not even open Debian on my Vbox.
However, I can not communicate with my device in Debian and it showed that permission denied.
What can I do next.
Your article is the gift that keeps on giving. The little hint about COM1 on Virtual Box is just what I needed today. Thank you!
im not a linux user and i dont speak English very well. My problem is the opposite to this article, I have linux mint and i want to use serial port on a virtualized windows xp on virtualbox. Once i started win xp, the serial device is properly detected but when i try to connect it on hyperterminal, the system crashed. It’s like Linux dont give it permission to access the port, i dont know. Obviously it works perfect using virtualbox when both operative systems are windows. I really apreciatte any help, please remember im not a linux user, im a very sad windows user
So much time has passed, it’s good that nothing stands still. Now it can be done simply with the help of software …. for my works I use https://www.eltima.com/products/serial-over-ethernet/ , since It is supported by the Linux system and Windows.
Pingback: Alinco DR-735T: Programming On Linux Through Windows – Soliloquy Blog
Thank you, you save my life
Before using remember this command
$ sudo chmod 777 /dev/ttyS0