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

feat: vsock support for remote console access #197

Merged
merged 1 commit into from
Dec 3, 2024
Merged

Conversation

matttbe
Copy link
Collaborator

@matttbe matttbe commented Nov 29, 2024

Having a remote console access can be helpful for different reasons, e.g. an easy way to have multiple terminals, not using a serial which can be slow to print a lot of text, etc.

With this new support, a user can simply use vng like before, and add the new --vsock option:

vng --vsock (...)

Then in another terminal, it can connect to the existing VM:

vng --vsock-connect

Advanced users can set a different CID with --vsock-cid, useful when multiple VMs are started in parallel.

It is also possible to change the command that is executed when connected inside the VM. By default, bash -i is used, but it is possible to pass something else, e.g.

vng --vsock byobu

Or zsh, fish, tmux, etc. Or a script, for example to set env vars, change dir and set other dimensions, etc., e.g. starting the VM with:

$ vng --vsock "${PWD}/console.sh"

... and connecting to it from another terminal with:

$ read -r rows columns <<< "$(stty size)"
$ cat <<-EOF > console.sh
    #! /bin/bash
    stty rows ${rows} columns ${columns}
    cd "\${virtme_chdir}"
    HOME=${HOME}
    byobu
  EOF
$ chmod +x console.sh
$ vng --vsock-connect

Note: on my side, 'bash' is a bit weird: I cannot see the command I'm typing. I didn't try to find a solution for a too long time as I'm usually not using bash.

Regarding the kernel config, two new config are now required: VSOCKETS and VIRTIO_VSOCKETS. They seem light enough.

While at it, fixed a typo in the README file with the --network option.

Depends-on: #195

Link: #151

@matttbe
Copy link
Collaborator Author

matttbe commented Nov 29, 2024

Note: because I added the options after others from #195, this PR depends on that. But I can change if needed.

@matttbe matttbe force-pushed the vsock branch 2 times, most recently from 9724a41 to 7b3096d Compare November 29, 2024 19:09
matttbe added a commit to multipath-tcp/mptcp-upstream-virtme-docker that referenced this pull request Nov 29, 2024
Cleaner to do that like that.

Also added a new 'connect' parameter.

Use it via connect.sh

Note, it depends on a WIP version of virtme-ng [1]

Link: arighi/virtme-ng#197 [1]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Copy link
Owner

@arighi arighi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just left a comment about providing a helper script to initialize the console session, but overall it looks great, I love this!

Feel free to merge this as is, we can improve it later in tree.

README.md Show resolved Hide resolved
Having a remote console access can be helpful for different reasons,
e.g. an easy way to have multiple terminals, not using a serial which
can be slow to print a lot of text, etc.

With this new support, a user can simply use vng like before, and add
the new --vsock option:

  vng --vsock (...)

Then in another terminal, it can connect to the existing VM:

  vng --vsock-connect

Advanced users can set a different CID with --vsock-cid, useful when
multiple VMs are started in parallel.

It is also possible to change the command that is executed when
connected inside the VM. By default, 'bash -i' is used, but it is
possible to pass something else, e.g.

  vng --vsock byobu

Or zsh, fish, tmux, etc. Or a script, for example to set env vars, change dir
and set other dimensions, etc., e.g. starting the VM with:

  $ vng --vsock "${PWD}/console.sh"

... and connecting to it from another terminal with:

  $ read -r rows columns <<< "$(stty size)"
  $ cat <<-EOF > console.sh
	#! /bin/bash
	stty rows ${rows} columns ${columns}
	cd "\${virtme_chdir}"
	HOME=${HOME}
	byobu
    EOF
  $ chmod +x console.sh
  $ vng --vsock-connect

Note: on my side, 'bash' is a bit weird: I cannot see the command I'm
typing. I didn't try to find a solution for a too long time as I'm
usually not using bash.

Regarding the kernel config, two new config are now required: VSOCKETS
and VIRTIO_VSOCKETS. They seem light enough.

While at it, fixed a typo in the README file with the --network option.

Link: arighi#151
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
@matttbe matttbe merged commit 2543783 into arighi:main Dec 3, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants