Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial Port Access from Host #3

Closed
giezi opened this issue Apr 7, 2022 · 8 comments
Closed

Serial Port Access from Host #3

giezi opened this issue Apr 7, 2022 · 8 comments

Comments

@giezi
Copy link

giezi commented Apr 7, 2022

Thank you very much for the great application. I have seen that it has support for serial adapters in the code for Linux Guests. I have now released this code for macOS as well. In macOS I see /dev/cu.virtio device which is great. How can I access the serial adapter of the VM from the host OS (/dev/tty?)? Thanks a lot!

@s-u
Copy link
Owner

s-u commented Apr 7, 2022

@giezi The way this is setup currently in only forwards stdin/out on Linux

VZVirtioConsoleDeviceSerialPortConfiguration *serial = [[VZVirtioConsoleDeviceSerialPortConfiguration alloc] init];
VZFileHandleSerialPortAttachment *sata = [[VZFileHandleSerialPortAttachment alloc]
initWithFileHandleForReading: [NSFileHandle fileHandleWithStandardInput]
fileHandleForWriting: [NSFileHandle fileHandleWithStandardOutput]];
serial.attachment = sata;
self.serialPorts = @[ serial ];
, the serial link is not setup on macOS. However there is no real reason why it shouldn't be - it's just that on Linux it is really crucial as there is no other UI while on macOS it' snot strictly necessary. I could move the initialization code to apply to both platforms - would that be what you're looking for?

The other alternative would be to provide a separate tty, but I'd have to look into that. Let me know what you think.

@giezi
Copy link
Author

giezi commented Apr 7, 2022

Hi @s-u

Thank you for your fast answer. Sure, I understand, but we would like to place an "agent" in the macOS guest VM which is connecting to /dev/cu.virtio serial device. We have already modified the code so that OSX VMs also get a serial adapter :)

But how can we access it from the host-system? Where does macosvm map the serial adapter from the VM?

Best regards and thans again
Reto

@s-u
Copy link
Owner

s-u commented Apr 7, 2022

The code I referenced above registers the serial adapter connects it to the host-side file handles - as you can see the one above links it to stdin/out of the macosvm process. That setup code could connect it to something else - maybe a pipe to another process or FIFOs or tty similar. That's why I'm asking what would work for you as the setup has to do the corresponding work in the macosvm process. If it's not jsut a simple I/O FD then I would have to add code that forwards it to whatever you need.

@giezi
Copy link
Author

giezi commented Apr 7, 2022

Hi @s-u

Alright, thank you for your explanation! It would be ideal if it could be redirected to a normal TTY so that you could connect on the host OS using "screen /dev/tty.macosvm-vmname" for example, would this be possible?

Many thanks, Reto

@s-u
Copy link
Owner

s-u commented Apr 7, 2022

Yes, that can be done, I'll look into it.

@s-u
Copy link
Owner

s-u commented Apr 7, 2022

@giezi I have made a few changes:

  • the serial mapping to stdin/out is now on by default on macOS as well
  • I have added --no-serial option to disable it if needed (just to match the old behavior)
  • I have added --pty option which creates a pty for the serial mapping. There is an issue, though: the Apple virtualization framework will refuse to instantiate the VM if the serial I/O is not connected. This means that you have to connect to the pty before the VM can be started. This is a problem, so a temporary hack is that macosvm will wait for stdin after allocating the pty but before starting the VM. This is really fro testing now, so you can give it a shot, but we'll have to come up with a better solution. To make things worse it appears that the virtio pty cannot be re-connected, so once you terminate the session is refuses any new sessions. I suspect this is all a limitation of the virtualization framework, but if someone has any good ideas, let me know.

@giezi
Copy link
Author

giezi commented Apr 8, 2022

@s-u Amazing - it works perfectly :) Thank you SO MUCH!!!
Regarding the restrictions: Maybe https://github.com/kendfinger/canned-mac/search?q=serial has a solution?

@s-u
Copy link
Owner

s-u commented Dec 27, 2022

This is now in the release, so I'll close this, even though the setup of having to wait is still suboptimal. I have not seen a better solution just yet, but if anyone has a good idea, please feel free to open an issue. I'm not using this feature myself (since I just ssh instead which is more flexible) so feedback from users using this feature is welcome as well.

@s-u s-u closed this as completed Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants