我在Chrome OS上尝试将Proxmox VE的LXC备份迁移

首先

我们通常在Proxmox上的LXC容器中进行开发。
对于仅在内部使用且容器镜像包含了数据库而无需外部部署的情况,我认为LXC比Docker更适用于本地部署。
然而,在无法连接Proxmox的环境下,我们遇到了需要向客户演示或在外部进行开发的情况,因此出现了希望将在Proxmox上备份的镜像迁移到Chrome OS的要求。
Proxmox的LXC备份输出的格式与标准不同,因此即使将其直接拷贝到Chrome OS或macOS等系统上,也无法启动。
虽然论坛上的方法也无法解决问题,但我们最终找到了一种方法,现在在此记录下来。

 

写作时的版本

SoftVerProxmox VE7.3Chrome OS107.0.5304.110

由于Proxmox只存在x86_64版,因此Arm版Chromebook和M1mac可能无法运行或速度不够快。
尚未确认LXC能否在Rosetta2上运行。
建议直接使用Intel mac。

在Proxmox中创建备份。

请参考手册等,在Proxmox中创建容器备份。
这里简单地使用图形化界面进行剪辑。
重点是选择停止模式,并使用GZIP进行压缩。

 

生成一个名为vzdump-lxc–timestamp.tar.gz的文件,请使用USB存储设备将其拷贝或通过SFTP传输等方式,将其带到Chrome OS上。

在Proxmox上的操作已经完成。

使用Chrome OS的操作

1. 进入termina

在Chrome浏览器中,通过按下ctrl + alt + t的快捷键来打开终端,并使用vsh termina命令进入termina虚拟机。

Welcome to crosh, the ChromeOS developer shell.

If you got here by mistake, don't panic!  Just close this tab and carry on.

Type 'help' for a list of commands.

If you want to customize the look/behavior, you can use the options page.
Load it by using the Ctrl-Shift-P keyboard shortcut.

crosh> vsh termina
(termina) chronos@localhost ~ $ 

如果出现错误,则由于Linux机尚未启动,只需输入vmc start termina命令,即可在Linux机启动后进入termina虚拟机。

Welcome to crosh, the ChromeOS developer shell.

If you got here by mistake, don't panic!  Just close this tab and carry on.

Type 'help' for a list of commands.

If you want to customize the look/behavior, you can use the options page.
Load it by using the Ctrl-Shift-P keyboard shortcut.

crosh> vsh termina
ERROR vsh: [vsh.cc(121)] Failed to get VM info for termina
[ERROR:src/main.rs:185] ERROR: command failed
crosh> vmc start termina
(termina) chronos@localhost ~ $ 

创建metadata模板

總結來說,Proxmox的備份文件中缺少了metadata.yaml等容器相關的數據。所以我們需要創建這些文件。

2.1. 使用Proxmox来创建基于的LXC容器。

如果你不确定在CentOS 7上哪个最适合,请使用lxc image list images:命令进行搜索。

lxc launch images:centos/7 centos

如果Arm版的Chromebook或M1mac无法通过Rosetta2等方式正常运行,并且需要明确选择x86_64,那么会遇到以下错误。或许进行调优能使它们正常工作吗?

Error: Failed instance creation: Failed creating instance record: Requested architecture isn't supported by this host

如果顺利的话,容器将会被启动。

Creating centos
Starting centos 

停止容器并进行备份。

lxc stop centos
lxc publish centos --alias centos
lxc image export centos $LXD_CONF/centos

2.3. 从备份中删除除了设置文件以外的数据。

Note: This is the paraphrased version in simplified Chinese.

删除rootfs/目录下的内容,因为该目录中包含了当前容器的文件。

zcat $LXD_CONF/centos.tar.gz | tar --delete rootfs | gzip > $LXD_CONF/metadata.tar.gz
rm $LXD_CONF/centos.tar.gz

将Proxmox备份文件所在的目录与Linux共享

在Chrome OS的Files应用程序中,右键单击文件夹,然后从显示的菜单中选择“共享到Linux”选项,这样在termina中就会挂载到/mnt/shared/MyFiles目录下。
例如,如果将下载文件夹与Linux共享,则会挂载到/mnt/shared/MyFiles/Downloads/目录下。

将metadata.tar.gz和Proxmox的备份文件合并,构建新的容器镜像,并启动。

lxc image import $LXD_CONF/metadata.tar.gz /mnt/shared/MyFiles/Downloads/vzdump-lxc-105-2020_11_11-17_31_29.tar.gz --alias centos-custom
lxc launch centos-custom

当启动成功后会分配IP地址,请进行确认。

在运行的LXC列表中可以查看到容器的启动状态和分配的IP地址。

(termina) chronos@localhost ~ $ lxc list
+---------+---------+-----------------------+------+-----------+-----------+
|  NAME   |  STATE  |         IPV4          | IPV6 |   TYPE    | SNAPSHOTS |
+---------+---------+-----------------------+------+-----------+-----------+
| centos7 | RUNNING | 100.115.92.194 (eth0) |      | CONTAINER | 0         |
+---------+---------+-----------------------+------+-----------+-----------+
| penguin | STOPPED |                       |      | CONTAINER | 0         |
+---------+---------+-----------------------+------+-----------+-----------+