User:Ncopa/migrate-vserver-to-lxc: Difference between revisions

From Alpine Linux
(rename old vserver after last data sync happened)
 
(2 intermediate revisions by the same user not shown)
Line 41: Line 41:
auto eth0
auto eth0
iface eth0 inet static
iface eth0 inet static
         address 91.220.88.23
         address 1.2.3.4
         netmask 255.255.255.128
         netmask 255.255.255.248
         gateway 91.220.88.1
         gateway 1.2.3.1


auto eth1
auto eth1
iface eth1 inet static
iface eth1 inet static
         address 192.168.8.4
         address 192.168.0.4
         netmask 255.255.255.0
         netmask 255.255.255.0
</nowiki>}}
</nowiki>}}
Line 54: Line 54:
After data is copied we shut down the old vserver. This is on old Vserver host.
After data is copied we shut down the old vserver. This is on old Vserver host.
{{cmd|vserver build-edge stop}}
{{cmd|vserver build-edge stop}}
=== Mirror data again ===
We mirror the changes on the powered off vserver once again so we get the changes that happened after first data copy started. This is done from vserver host here.
{{cmd|rsync --partial --delete --numeric-ids -rva /vservers/build-edge/* bld1.alpinelinux.org:/var/lib/lxc/build-ege-x86/rootfs/}}


We rename the vserver so its not started/copied by mistake.
We rename the vserver so its not started/copied by mistake.
Line 60: Line 64:
We unmark the auto-start.
We unmark the auto-start.
{{cmd|rm /etc/vservers/build-edge/apps/init/mark}}
{{cmd|rm /etc/vservers/build-edge/apps/init/mark}}
=== Mirror data again ===
We mirror the changes on the powered off vserver once again so we get the changes that happened after first data copy started. This is done from vserver host here.
{{cmd|rsync --partial --delete --numeric-ids -rva /vservers/build-edge/* bld1.alpinelinux.org:/var/lib/lxc/build-ege-x86/rootfs/}}


=== Prepare lxcontainer for startup ===
=== Prepare lxcontainer for startup ===
Line 76: Line 76:


TODO: send GARP to tell switch of new ip.
TODO: send GARP to tell switch of new ip.
=== Start up container ===
Make it autostart.
{{cmd|ln -s lxc /etc/init.d/lxc.build-edge-x86}}
Now its time to start up container.
{{cmd|/etc/init.d/lxc.build-edge-x86 start}}
=== Verify that it works ===
Ping it. check that services are running and working.
Possible issues can come from switch not yet picking up that ip addr has moved to new mac addr. [http://www.cyberciti.biz/faq/linux-networking-sending-gratuitous-arps/ GARP] can be used to resolve that.

Latest revision as of 08:30, 18 October 2013

Some notes on how to migrate an Alpine Linux vserver to an lxcontainer.

Its fairly straightforward. Basically, the only thing that differs is:

  • /etc/inittab
  • /etc/network/interfaces

On vserver the host sets up the network, on LXC the container needs to do it itself.

Migration steps

Here follows some step by step. build-edge-x86 is used as example.

Create container

Create the new container on the LXC host

lxc-create -n build-edge-x86 -t alpine -- --release edge --arch x86

Backup inittab

Make a copy of the inittab to a location outside the container rootfs.

cp /var/lib/lxc/build-edge-x86/rootfs/etc/inittab /var/lib/lxc/build-edge-x86/

Copy data

Use rsync to mirror the vserver. We do this before we shut down the vserver guest to keep downtime as low as possible. In this example we rsync from the vserver host:

rsync --partial --delete --numeric-ids -rva /vservers/build-edge/* bld1.alpinelinux.org:/var/lib/lxc/build-ege-x86/rootfs/

Configure networking

While data is copying we can use the time to configure the network. Edit /var/lib/lxc/build-edge-x86/config and set up the network devices. In this example we do:

Contents of /var/lib/lxc/build-edge-x86/config

... lxc.network.type = veth lxc.network.link = br0 lxc.network.name = eth0 lxc.network.type = veth lxc.network.link = lxbr0 lxc.network.name = eth1 ...

We can also create a interfaces file that we will copy into the container after old vserver is shutdown.

Contents of /var/lib/lxc/build-edge-x86/interfaces

auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 1.2.3.4 netmask 255.255.255.248 gateway 1.2.3.1 auto eth1 iface eth1 inet static address 192.168.0.4 netmask 255.255.255.0

Shut down old vserver

After data is copied we shut down the old vserver. This is on old Vserver host.

vserver build-edge stop

Mirror data again

We mirror the changes on the powered off vserver once again so we get the changes that happened after first data copy started. This is done from vserver host here.

rsync --partial --delete --numeric-ids -rva /vservers/build-edge/* bld1.alpinelinux.org:/var/lib/lxc/build-ege-x86/rootfs/

We rename the vserver so its not started/copied by mistake.

mv /vservers/build-edge /vserver/build-edge.old

We unmark the auto-start.

rm /etc/vservers/build-edge/apps/init/mark

Prepare lxcontainer for startup

Before we start up the container we copy the inittab. This is on new LXC host.

cp /var/lib/lxc/build-edge-x86/inittab /var/lib/lxc/build-edge-x86/rootfs/etc/

...and we copy the interfaces file too.

cp /var/lib/lxc/build-edge-x86/interfaces /var/lib/lxc/build-edge-x86/rootfs/etc/networking/

We make sure networking is started at bootup.

ln -s /etc/init.d/networking /var/lib/lxc/build-edge-x86/rootfs/etc/runlevels/default/networking

TODO: send GARP to tell switch of new ip.