是否可以将 LXC 容器从 Ubuntu 迁移到 libvirt-lxc (SLES)

是否可以将 LXC 容器从 Ubuntu 迁移到 libvirt-lxc (SLES)

我目前正在研究一种场景,其中在 Ubuntu 上创建的 LXC 容器应该迁移到 SLES 上的容器。

有办法吗?有没有什么工具可以推荐?

答案1

虽然没有完全自动化的端到端功能,但“virsh”提供了一个“domxml-from-native”命令,可以帮助您构建 XML 配置文档

$ cat container.cfg 
lxc.utsname = complex
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.hwaddr = 4a:49:43:49:79:bf
lxc.network.ipv4 = 10.2.3.5/24
lxc.network.type = macvlan
lxc.network.flags = up
lxc.network.link = eth0
lxc.network.hwaddr = 4a:49:43:49:79:bd
lxc.network.ipv4 = 10.2.3.4/24
lxc.network.ipv4 = 192.168.10.125/24
lxc.network.type = phys
lxc.network.flags = up
lxc.network.link = dummy0
lxc.network.hwaddr = 4a:49:43:49:79:ff
lxc.network.ipv4 = 10.2.3.6/24
lxc.cgroup.cpuset.cpus = 0,1
lxc.cgroup.cpu.shares = 1234
lxc.cgroup.devices.deny = a
lxc.cgroup.devices.allow = c 1:3 rw
lxc.cgroup.devices.allow = b 8:0 rw
lxc.rootfs = /mnt/rootfs.complex
lxc.cap.drop = sys_module mknod setuid net_raw
lxc.cap.drop = mac_override

$ virsh -c lxc:/// domxml-from-native lxc-tools container.cfg 
<domain type='lxc'>
  <name>complex</name>
  <uuid>1e600565-6421-4826-a511-20fdd4a5236c</uuid>
  <memory unit='KiB'>65536</memory>
  <currentMemory unit='KiB'>65536</currentMemory>
  <vcpu placement='static' cpuset='0-1'>1</vcpu>
  <cputune>
    <shares>1234</shares>
  </cputune>
  <os>
    <type>exe</type>
    <init>/sbin/init</init>
  </os>
  <features>
    <capabilities policy='allow'>
      <mknod state='off'/>
      <net_raw state='off'/>
      <setuid state='off'/>
      <sys_module state='off'/>
    </capabilities>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/libvirt_lxc</emulator>
    <filesystem type='mount' accessmode='passthrough'>
      <source dir='/mnt/rootfs.complex'/>
      <target dir='/'/>
    </filesystem>
    <interface type='bridge'>
      <mac address='4a:49:43:49:79:bf'/>
      <source bridge='br0'/>
      <ip address='10.2.3.5' family='ipv4' prefix='24'/>
      <link state='up'/>
    </interface>
    <interface type='direct'>
      <mac address='4a:49:43:49:79:bd'/>
      <source dev='eth0' mode='private'/>
      <ip address='10.2.3.4' family='ipv4' prefix='24'/>
      <ip address='192.168.10.125' family='ipv4' prefix='24'/>
      <link state='up'/>
    </interface>
    <hostdev mode='capabilities' type='net'>
      <source>
        <interface>dummy0</interface>
      </source>
      <ip address='10.2.3.6' family='ipv4' prefix='24'/>
    </hostdev>
  </devices>
</domain>

这种转换并非万无一失,也无法处理所有可能的配置选项,但它应该能让你朝着写作的方向前进。一旦你有了合适的 XML 配置,就可以使用virsh -c lxc:/// define它将其保存在 libvirt 中

相关内容