LoginSignup
1
2

More than 1 year has passed since last update.

Proxmox VEのLXCバックアップをChrome OS上にマイグレーションしてみた

Last updated at Posted at 2022-12-02

はじめに

通常弊社では、Proxmox上のlxcコンテナの中で開発を行っている。
DBを外出しせずにコンテナ内に内包しているようなコンテナイメージをそのまま納品するようなオンプレ用途にはDockerよりもLXCの方が向いていると感じています。
そんな中で、Proxmoxに繋がらない環境でお客様にプレゼンしたり、外で開発するような事例が出てきたため、ProxmoxでバックアップしたイメージをChrome OSにマイグレーションしたい要望が上がってきました。
ProxmoxのLXCは、バックアップで標準とは違う形式でバックアップを吐き出すため、そのままChrome OSやmacOSなどに持っていっても起動すらできなかった。
フォーラムで記載されている方法でも無理であったがなんとかなったため、ここに書き記す。

執筆時のバージョン

Soft Ver
Proxmox VE 7.3
Chrome OS 107.0.5304.110

Proxmoxがx86_64版しか存在しないため、Arm版ChromebookやM1macなどは動かない、もしくは実用速度に満たない可能性が高いです。
Rosetta2の上でLXCが動くのかは確認していないです。
素直にIntel macをお使いください。

Proxmoxでのバックアップ作成

マニュアルなどを参考にProxmoxでコンテナのバックアップを作成してください。
ここはGUIで簡単に出来るため割愛します。
ポイントはモードはstop(停止)で圧縮はGZIPにすることです。

vzdump-lxc--timestamp.tar.gzというファイルが出来上がりますが、これをUSBメモリなどで引っこ抜くか、SFTP転送などで、Chrome OSまで持ってきてください。

Proxmox上での操作は以上で終了です。

Chrome OS上の操作

1. terminaに入る

Chrome ブラウザ上で ctrl + alt + t のショートカットによりターミナルを開きvsh termina でtermina VMに入ります。

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 VMに入ります。

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 ~ $ 

2. metadataのテンプレートを作る

結論を言うと、Proxmoxのバックアップファイルにはmetadata.yamlを始めとしたこのコンテナは何者かというデータがありません。
このため、これらのファイルを作ります。

2.1. Proxmoxで元になっていたLXCコンテナを作る

下記はcentos7の場合、どれが最適かわからない場合はlxc image list images:なりで探す。

lxc launch images:centos/7 centos

Arm版ChromebookやM1macなどはx86_64を明示的に選択する必要があるが、Rosetta2などを通しても上手く動かない場合は、下記のエラーでコケます。
チューニングすれば動くようになるのかな?

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

うまくいくと、コンテナが起動する

Creating centos
Starting centos 

2.2. コンテナを停止させバックアップを取る

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

2.3. バックアップから設定ファイル以外のデータを削除する

tarボールの中にあるrootfs/ディレクトリ以下が、いま現状のコンテナのファイルが入っているため、このフォルダを削除する。

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

2.4.Proxmoxのバックアップファイルを置いたディレクトリをLinuxと共有をかける

Chrome OSのFilesアプリでフォルダを右クリックすると表示されるメニューからLinuxと共有を選ぶと、termina では/mnt/shared/MyFiles以下にマウントされます。
例えば、ダウンロードフォルダをLinuxと共有をかけると/mnt/shared/MyFiles/Downloads/にマウントされます。

2.5. 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

2.6. うまく起動するとIPが振られるため確認する

lxc listで起動状態と振られている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         |
+---------+---------+-----------------------+------+-----------+-----------+
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2