[Lxc-users] Converting an LXC container into a bootable OS?
Iliyan ilf Stoyanov
ilf at ilf.me
Wed Oct 12 02:10:21 UTC 2011
Hi Ivan,
On Tue, 2011-10-11 at 18:32 -0600, Ivan Fetch wrote:
> Hello,
>
> Along with some other troubleshooting we are doing (separate thread), we are investigating turning some LXC containers into virtual machines. Does anyone have experience, or perhaps some write-ups, on going in the other direction? E.G> start with a base Ubuntu 10.04 installation, copy the LXC contianer's filesystem into that installation, then adjust fstab, rebuilt initrd image, Etc?
It shouldn't be that hard doing that. All you need to take into account
is the 'hardware' inside your virtual machine. I always assume people
use KVM/Qemu so basically you should probably take into account the
appropriate vda/hda drivers, the virtio drivers for the network
interfaces, etc.
Once upon a time I used to install server by booting from NFS and
effectively copying the live NFS FS to the local harddrives, chrooting
there and doing kudzu and then mkinitrd by including specific kernel
modules for the hardware on the machine, raid, etc, so I can boot it,
but that was on RHEL4. I would have to say nowadays I do that, but the
tools are very different between distros. RHEL and Fedora use dracut for
generating the initrd and partially probing hardware. I'm not really
familiar with the fine details of ubuntu, but I think mkinitrd (or the
appropriate analog) still allows you to include modules by hand. Then
you should setup your fstab file and essentially start the machine.
As for the exact creation of the image (I assume you'll be using images)
qemu-img would help you create the appropriate format, and eventully
mount it as a loop device. If you don't change hardware platforms (i.e.
x86_64 on i386 host, or PowerPC on x86(_64) instruction set host) you
mount the img. Copy the LXC container FS to it, mount
--bind /{proc,sys,dev} to the root of the loop device, chroot there and
then mkinitrd with proper modules from the appropriate kernel version.
Then you setup the fstab, put a boot loader on the image and edit it's
config and attempt to boot from that qemu image. It is almost like
copying the FS on real server, just with different kernel modules.
This is just a quick and dirty howto that assumes you are using
KVM/Qemu, but I think it will not be that much different for other
hypervisors.
Hope I was some help. Unfortunately I don't have the time lately to sit
down and write a detailed howto, because actually it would make a good
algorithm and I can write a small script for converting LXC machines to
KVM, and vice versa as I'm almost certain I'll need such a thing at
some point.
cheers,
-- ilf
>
> Thanks,
>
> Ivan.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> .
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2d-oct
> _______________________________________________
> Lxc-users mailing list
> Lxc-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-users
More information about the lxc-users
mailing list