[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running qemu guest in background

From: Ottavio Caruso
Subject: Re: Running qemu guest in background
Date: Sat, 16 May 2020 18:15:36 +0100

On Sat, 16 May 2020 at 15:22, Mahmood Naderan <address@hidden> wrote:
> >qemu-system-xxxxxx  -nographic &
> >
> >However, there's a lot of other work you need to do if you then want
> >to communicate with console, serial port, monitor, etc.
> No that doesn't work.
> As soon as I press enter, I see
> [1]+ Stopped  qemu-system-x86_84 .....
> And I see the terminal prompt. As I grep for qemu process, I see that with 
> the state "TL"
> However, anydesk won't connect.

I've tried this from a script and it works. Pay attention to the command line:

$ cat boot-freebsd-virtio
qemu-system-x86_64 \
-drive if=virtio,file=/home/oc/VM/img/freebsd.image,index=0,media=disk \
-drive if=virtio,file=/home/oc/VM/img/freebsd.image.old,index=1,media=disk \
-M q35,accel=kvm -m 250M -cpu host -smp $(nproc) \
-nic user,hostfwd=tcp::6664-:22,model=virtio-net-pci \
-display none -daemonize -pidfile pidfile.txt

$ ./boot-freebsd-virtio
$ jobs

[wait 20 seconds until sshd has started in the guest]

$ ssh -p 6664
Password for oc@FreeBSD:
Last login: Sat May 16 18:00:25 2020 from

[shutdown the guest]
oc@FreeBSD:~ %             doas shutdown -p now
*** FINAL System shutdown message from oc@FreeBSD ***

System going down IMMEDIATELY

System shutdown time has arrived
Connection to closed by remote host.
Connection to closed.

[wait a few seconds]

$ ps aux|grep qemu
oc       12416  0.0  0.0  14896   956 pts/1    S+   18:04   0:00 grep
--color=auto qemu

[nothing in there]

In case the guest hangs and qemu is still running, you can get the pid
from pidfile.txt:
$ cat pidfile.txt

$ kill 12383

So, there is a way to run qemu in the background without using
additional software. The line above works from a script but not from
the command line in interactive mode.

Be careful not to kill a VM if the root filesystem is  still mounted.
You might want to redirect -serial and -monitor to a Unix socket. I
have never tried it myself, though.

Ottavio Caruso

reply via email to

[Prev in Thread] Current Thread [Next in Thread]