LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 11-07-2016, 07:53 PM   #1
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Rep: Reputation: Disabled
libvirt: execute command on host initiated by guest


Hi,

Is it possible, using libvirt, to trigger some command on host, from the guest?

Both machines run Linux, both are trusted.
But anyway, I don't mean guest executing whichever command it wants, but only predefined one.

Is it possible to do with, for example, QEMU Guest Agent?
I really would like all the configuration to sit within libvirt (e.g. in xml file or something like that).

What I plan to do, is to mount guest directory in the host using sshfs.
That would also require the possibility to run host's command when the machine is accidentally or forcibly shut down (to umount).

Alternatively, if you know better way to achieve that, I would like to hear it.
Still, I would like to know how to execute command on host from guest.
There are some more use cases for me.

Thanks in advance!

--
Best regards,
Andrzej Telszewski
 
Old 11-09-2016, 06:44 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,628

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
Quote:
Originally Posted by atelszewski View Post
Hi,

Is it possible, using libvirt, to trigger some command on host, from the guest?

Both machines run Linux, both are trusted.
But anyway, I don't mean guest executing whichever command it wants, but only predefined one.

Is it possible to do with, for example, QEMU Guest Agent?
I really would like all the configuration to sit within libvirt (e.g. in xml file or something like that).

What I plan to do, is to mount guest directory in the host using sshfs.
That would also require the possibility to run host's command when the machine is accidentally or forcibly shut down (to umount).

Alternatively, if you know better way to achieve that, I would like to hear it.
Still, I would like to know how to execute command on host from guest.
There are some more use cases for me.

Thanks in advance!

--
Best regards,
Andrzej Telszewski
Were it proven possible today, it would be more difficult tomorrow. This is exactly the kind of thing developers and admins strive to PREVENT. Such a feature would subvert the security advantage in running processes or servers in virtual containers in the first place. All control must come from the host to the container, NEVER the other way.

That said, there may be other ways to accomplish your real purpose. Providing a "share" space on another container that can be mounted both from the host AND from any other containers would allow for storage communication between an arbitrary number of nodes. Would something like that have value in your case?
 
Old 11-09-2016, 02:57 PM   #3
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by wpeckham View Post
Were it proven possible today, it would be more difficult tomorrow. This is exactly the kind of thing developers and admins strive to PREVENT. Such a feature would subvert the security advantage in running processes or servers in virtual containers in the first place. All control must come from the host to the container, NEVER the other way.
I don't know if I was explicit enough.
I didn't mean for container to send whichever commands it wants and the host executing it.
I was thinking more about something like events.
Guest sends some event and the host can act accordingly upon it.

I don't see it as security problem.
You could achieve the same (or more dangerous) behavior using SSH or serial port / unix socket.

What is more, the container is private and trusted.

Quote:
Originally Posted by wpeckham View Post
That said, there may be other ways to accomplish your real purpose. Providing a "share" space on another container that can be mounted both from the host AND from any other containers would allow for storage communication between an arbitrary number of nodes. Would something like that have value in your case?
What I would like to achieve, is to mount guest's rootfs in the host.
Guest is running under libvirt/QEMU, under regular user (session mode).

Thanks.

--
Best regards,
Andrzej Telszewski
 
Old 11-18-2016, 06:52 AM   #4
Slax-Dude
Member
 
Registered: Mar 2006
Location: Valadares, V.N.Gaia, Portugal
Distribution: Slackware
Posts: 528

Rep: Reputation: 272Reputation: 272Reputation: 272
Quote:
Originally Posted by atelszewski View Post
You could achieve the same (or more dangerous) behavior using SSH or serial port / unix socket.
Why not use SSH?
 
Old 11-18-2016, 07:23 AM   #5
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by Slax-Dude View Post
Why not use SSH?
Because it requires setup outside of libvirt.
Also, I would like to be signaled when VM exits unintentionally.

--
Best regards,
Andrzej Telszewski
 
Old 11-19-2016, 08:15 AM   #6
Slax-Dude
Member
 
Registered: Mar 2006
Location: Valadares, V.N.Gaia, Portugal
Distribution: Slackware
Posts: 528

Rep: Reputation: 272Reputation: 272Reputation: 272
You can use virsh to check if guest is running.
virt-top is also useful for monitoring guest processes
 
Old 11-19-2016, 09:09 AM   #7
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

I'm more curious if there already is solution implementing my requirements.
I could boil something myself, but that wasn't my intent.
It is not critical, if it was, I would do something that you suggested.

--
Best regards,
Andrzej Telszewski
 
Old 11-19-2016, 07:50 PM   #8
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
No, there is no solution, and if anything, it's usually the host monitoring the guest via an agent, and acting upon received data, not the other way around.

What exactly do you want to do?
 
Old 11-19-2016, 08:02 PM   #9
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by dyasny View Post
What exactly do you want to do?
If I only knew ;-)

My initial need was to mount guest's rootfs onto the host.
I can live without that, it would sometimes make things easier to setup, but not by a huge amount.

Another use case could be guest signalling host about finished task.
E.g. if VM is used for building packages, it could signal when it's done.

The aim is to receive signal, instead of polling the guest.

I know most of this could be done by other means, I was just wondering if it could be done within libvirt itself.

--
Best regards,
Andrzej Telszewski
 
Old 11-20-2016, 07:56 AM   #10
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,628

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
With any Full virtualization it is easy to mount the guest from the host. What you ask is that the GUEST trigger the host to mount the guest, and that is not something that you could normally trigger from the guest. In fact, the separation pretty much precludes such activity, for the reasons I gave earlier.

Have you considered bypassing libvert and full virtualization entirely and using kernel based virtual? Using LXC or OpernVZ the root of the guest is either ALWAYS available from the host, or available whenever the guest is mounted or running. This makes triggering a mount totally unnecessary.
 
Old 11-20-2016, 04:56 PM   #11
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by wpeckham View Post
What you ask is that the GUEST trigger the host to mount the guest, and that is not something that you could normally trigger from the guest. In fact, the separation pretty much precludes such activity, for the reasons I gave earlier.
I won't agree.
The communication between host and guest is happening all the time in many different parts of the system.
They all have to be thoughtfully designed.

And as I mentioned before, I'm not asking for the host directly executing whatever commands the guest sends.
What I'm thinking of is defining some sort of signal/event. Then host could execute e.g. script, or simply ignore the event request.

Quote:
Originally Posted by wpeckham View Post
Have you considered bypassing libvert and full virtualization entirely and using kernel based virtual? Using LXC or OpernVZ the root of the guest is either ALWAYS available from the host, or available whenever the guest is mounted or running. This makes triggering a mount totally unnecessary.
Nope, LXC is on my wish list ;-)
I don't know if it's possible with technologies you mentioned, but what I really like about libvirt/QEMU is that I can run them under regular user account.
No root account involved.

--
Best regards,
Andrzej Telszewski
 
Old 11-23-2016, 10:21 AM   #12
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
The common practice is to use the virtio-serial (or regular serial port) in the guest, as a file on the host, if the guest wants to send a message to the host, it will send t to it's serial port, and the host needs to monitor the file for changes and act upon them. this is the mechanism most guest agents use to communicate with the host. It is safe, since the host initiates the virtual port polling and will only execute commands received from it if it is programmed to specifically.

Anything else will have to either go through a shared storage volume or over a network. You can, btw, use an isolated IP network that exists only between the host and a guest.
 
Old 11-23-2016, 10:30 AM   #13
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by dyasny View Post
The common practice is to use the virtio-serial (or regular serial port) in the guest, as a file on the host, if the guest wants to send a message to the host, it will send t to it's serial port, and the host needs to monitor the file for changes and act upon them. this is the mechanism most guest agents use to communicate with the host. It is safe, since the host initiates the virtual port polling and will only execute commands received from it if it is programmed to specifically.
That's exactly what I was thinking of.
I just hoped that maybe libvirt already had an internal implementation.

virtio-vsock would also be a good candidate.
But I think it is just showing up as of this writing.

--
Best regards,
Andrzej Telszewski
 
Old 11-23-2016, 11:15 AM   #14
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
if you want a ready implementation, you can take a look at ovirt-guest-agent's source code
 
Old 11-23-2016, 11:20 AM   #15
atelszewski
Member
 
Registered: Aug 2007
Distribution: Slackware
Posts: 948

Original Poster
Rep: Reputation: Disabled
Hi,

Quote:
Originally Posted by dyasny View Post
if you want a ready implementation, you can take a look at ovirt-guest-agent's source code
What I meant was that I was hoping that libvirt had it, meaning I don't have to do it on my own.

--
Best regards,
Andrzej Telszewski
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Host Can't Guest Libvirt/KVM via SSH DJOtaku Linux - Virtualization and Cloud 4 01-19-2016 01:44 PM
[SOLVED] KVM/libvirt - all traffic from eth0 to virtual guest ericson007 Linux - Virtualization and Cloud 3 04-02-2012 09:43 PM
Guest to Host message passing - guest's memory usage statistics & guest's IP address Prince_Pangeni Linux - Virtualization and Cloud 2 03-03-2012 03:06 AM
Host Fedora14, Windows 7 is running as Virtualbox guest- Mic is not working on Guest mwaheed Linux - Virtualization and Cloud 1 10-20-2011 12:51 PM
execute command in background in remote host manojg Linux - General 5 11-27-2010 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration