[lxc-users] can't get kvm to work inside lxc

Marat Khalili mkh at rqc.ru
Wed Apr 5 07:51:10 UTC 2017


Just making it run is as simple as I wrote before, just 3 commands:

> # apt install wget qemu-kvm
>
> # wget 
> https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img
>
> # kvm -curses ubuntu-16.04-server-cloudimg-amd64-disk1.img
>
You should see it booting. I used a script to create fresh privileged 
LXC container, but there's nothing kvm-specific in that script, just 
some network configuration and user preferences. You said you use LXD, 
but I don't think there's big difference.

You'll have to solve more problems to actually make it useful:
* give it more space with qemu-img resize;
* access virtual system: define password or ssh key with cloud-localds;
* share network with VM: -netdev bridge,id=br0 -device 
virtio-net,netdev=br0,mac="$MAC_ADDRESS";
* configure static IP address: using cloud-localds rewrite file in 
/etc/network/interfaced.d and reboot the system;
* share local storage with VM: -virtfs and mount with 9p.
* control VM with scripts: -monitor unix:... and socat;
* monitor boot with scripts: -serial unix... and socat;
* start and stop VM with container: systemd;
* ...
(br0 above is a bridge inside the container; you'll need to create it 
and to forward /dev/net/tun for this to work.)

There's a lot of info about all this scattered throughout the internet, 
but no single page; I'll think about writing details up somewhere.

--

With Best Regards,
Marat Khalili

On 04/04/17 20:22, Spike wrote:
> Marat,
>
> any chance you could share a little more about the steps you took to 
> start kvm manually? that'd be most useful to get things started. If 
> you wrote up that experience somewhere a link would be most welcomed too.
>
> thank you,
>
> Spike
>
> On Mon, Apr 3, 2017 at 11:36 PM Marat Khalili <mkh at rqc.ru 
> <mailto:mkh at rqc.ru>> wrote:
>
>     Hello,
>
>     I was able to run kvm in a privileged lxc container without any
>     modifications of lxc stock config (well, with some related to network
>     bridge). I gave up on libvirt and start containers with
>     qemu-system-x86_64 and systemd. You may want to try downloading ubuntu
>     cloud image from
>     https://cloud-images.ubuntu.com/releases/16.04/release/
>     and starting it with kvm -curses to see if it works.
>
>     --
>
>     With Best Regards,
>     Marat Khalili
>
>     _______________________________________________
>     lxc-users mailing list
>     lxc-users at lists.linuxcontainers.org
>     <mailto:lxc-users at lists.linuxcontainers.org>
>     http://lists.linuxcontainers.org/listinfo/lxc-users
>
>
>
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20170405/1949f7db/attachment.html>


More information about the lxc-users mailing list